Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 94 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * PEAR_Installer_Role
|
3 | * PEAR_Installer_Role
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
8 | * that is available through the world-wide-web at the following URI:
|
8 | * that is available through the world-wide-web at the following URI:
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
10 | * the PHP License and are unable to obtain it through the web, please
|
10 | * the PHP License and are unable to obtain it through the web, please
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Greg Beaver <cellog@php.net>
|
15 | * @author Greg Beaver <cellog@php.net>
|
16 | * @copyright 1997-2008 The PHP Group
|
16 | * @copyright 1997-2008 The PHP Group
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @version CVS: $Id: Role.php,v 1.20 2008/01/03 20:26:36 cellog Exp $
|
18 | * @version CVS: $Id: Role.php,v 1.20 2008/01/03 20:26:36 cellog Exp $
|
19 | * @link http://pear.php.net/package/PEAR
|
19 | * @link http://pear.php.net/package/PEAR
|
20 | * @since File available since Release 1.4.0a1
|
20 | * @since File available since Release 1.4.0a1
|
21 | */
|
21 | */
|
22 | 22 | ||
23 | /**
|
23 | /**
|
24 | * base class for installer roles
|
24 | * base class for installer roles
|
25 | */
|
25 | */
|
26 | require_once 'PEAR/Installer/Role/Common.php'; |
26 | require_once 'PEAR/Installer/Role/Common.php'; |
27 | require_once 'PEAR/XMLParser.php'; |
27 | require_once 'PEAR/XMLParser.php'; |
28 | /**
|
28 | /**
|
29 | * @category pear
|
29 | * @category pear
|
30 | * @package PEAR
|
30 | * @package PEAR
|
31 | * @author Greg Beaver <cellog@php.net>
|
31 | * @author Greg Beaver <cellog@php.net>
|
32 | * @copyright 1997-2008 The PHP Group
|
32 | * @copyright 1997-2008 The PHP Group
|
33 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
33 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
34 | * @version Release: 1.7.2
|
34 | * @version Release: 1.7.2
|
35 | * @link http://pear.php.net/package/PEAR
|
35 | * @link http://pear.php.net/package/PEAR
|
36 | * @since Class available since Release 1.4.0a1
|
36 | * @since Class available since Release 1.4.0a1
|
37 | */
|
37 | */
|
38 | class PEAR_Installer_Role
|
38 | class PEAR_Installer_Role
|
39 | {
|
39 | {
|
40 | /**
|
40 | /**
|
41 | * Set up any additional configuration variables that file roles require
|
41 | * Set up any additional configuration variables that file roles require
|
42 | *
|
42 | *
|
43 | * Never call this directly, it is called by the PEAR_Config constructor
|
43 | * Never call this directly, it is called by the PEAR_Config constructor
|
44 | * @param PEAR_Config
|
44 | * @param PEAR_Config
|
45 | * @access private
|
45 | * @access private
|
46 | * @static
|
46 | * @static
|
47 | */
|
47 | */
|
48 | function initializeConfig(&$config) |
48 | function initializeConfig(&$config) |
49 | {
|
49 | {
|
50 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
50 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
51 | PEAR_Installer_Role::registerRoles(); |
51 | PEAR_Installer_Role::registerRoles(); |
52 | }
|
52 | }
|
53 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) { |
53 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) { |
54 | if (!$info['config_vars']) { |
54 | if (!$info['config_vars']) { |
55 | continue; |
55 | continue; |
56 | }
|
56 | }
|
57 | $config->_addConfigVars($class, $info['config_vars']); |
57 | $config->_addConfigVars($class, $info['config_vars']); |
58 | }
|
58 | }
|
59 | }
|
59 | }
|
60 | 60 | ||
61 | /**
|
61 | /**
|
62 | * @param PEAR_PackageFile_v2
|
62 | * @param PEAR_PackageFile_v2
|
63 | * @param string role name
|
63 | * @param string role name
|
64 | * @param PEAR_Config
|
64 | * @param PEAR_Config
|
65 | * @return PEAR_Installer_Role_Common
|
65 | * @return PEAR_Installer_Role_Common
|
66 | * @static
|
66 | * @static
|
67 | */
|
67 | */
|
68 | function &factory($pkg, $role, &$config) |
68 | function &factory($pkg, $role, &$config) |
69 | {
|
69 | {
|
70 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
70 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
71 | PEAR_Installer_Role::registerRoles(); |
71 | PEAR_Installer_Role::registerRoles(); |
72 | }
|
72 | }
|
73 | if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) { |
73 | if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) { |
74 | $a = false; |
74 | $a = false; |
75 | return $a; |
75 | return $a; |
76 | }
|
76 | }
|
77 | $a = 'PEAR_Installer_Role_' . ucfirst($role); |
77 | $a = 'PEAR_Installer_Role_' . ucfirst($role); |
78 | if (!class_exists($a)) { |
78 | if (!class_exists($a)) { |
79 | require_once str_replace('_', '/', $a) . '.php'; |
79 | require_once str_replace('_', '/', $a) . '.php'; |
80 | }
|
80 | }
|
81 | $b = new $a($config); |
81 | $b = new $a($config); |
82 | return $b; |
82 | return $b; |
83 | }
|
83 | }
|
84 | 84 | ||
85 | /**
|
85 | /**
|
86 | * Get a list of file roles that are valid for the particular release type.
|
86 | * Get a list of file roles that are valid for the particular release type.
|
87 | *
|
87 | *
|
88 | * For instance, src files serve no purpose in regular php releases.
|
88 | * For instance, src files serve no purpose in regular php releases.
|
89 | * @param string
|
89 | * @param string
|
90 | * @param bool clear cache
|
90 | * @param bool clear cache
|
91 | * @return array
|
91 | * @return array
|
92 | * @static
|
92 | * @static
|
93 | */
|
93 | */
|
94 | function getValidRoles($release, $clear = false) |
94 | function getValidRoles($release, $clear = false) |
95 | {
|
95 | {
|
96 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
96 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
97 | PEAR_Installer_Role::registerRoles(); |
97 | PEAR_Installer_Role::registerRoles(); |
98 | }
|
98 | }
|
99 | static $ret = array(); |
99 | static $ret = array(); |
100 | if ($clear) { |
100 | if ($clear) { |
101 | $ret = array(); |
101 | $ret = array(); |
102 | }
|
102 | }
|
103 | if (isset($ret[$release])) { |
103 | if (isset($ret[$release])) { |
104 | return $ret[$release]; |
104 | return $ret[$release]; |
105 | }
|
105 | }
|
106 | $ret[$release] = array(); |
106 | $ret[$release] = array(); |
107 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
107 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
108 | if (in_array($release, $okreleases['releasetypes'])) { |
108 | if (in_array($release, $okreleases['releasetypes'])) { |
109 | $ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
109 | $ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
110 | }
|
110 | }
|
111 | }
|
111 | }
|
112 | return $ret[$release]; |
112 | return $ret[$release]; |
113 | }
|
113 | }
|
114 | 114 | ||
115 | /**
|
115 | /**
|
116 | * Get a list of roles that require their files to be installed
|
116 | * Get a list of roles that require their files to be installed
|
117 | *
|
117 | *
|
118 | * Most roles must be installed, but src and package roles, for instance
|
118 | * Most roles must be installed, but src and package roles, for instance
|
119 | * are pseudo-roles. src files are compiled into a new extension. Package
|
119 | * are pseudo-roles. src files are compiled into a new extension. Package
|
120 | * roles are actually fully bundled releases of a package
|
120 | * roles are actually fully bundled releases of a package
|
121 | * @param bool clear cache
|
121 | * @param bool clear cache
|
122 | * @return array
|
122 | * @return array
|
123 | * @static
|
123 | * @static
|
124 | */
|
124 | */
|
125 | function getInstallableRoles($clear = false) |
125 | function getInstallableRoles($clear = false) |
126 | {
|
126 | {
|
127 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
127 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
128 | PEAR_Installer_Role::registerRoles(); |
128 | PEAR_Installer_Role::registerRoles(); |
129 | }
|
129 | }
|
130 | static $ret; |
130 | static $ret; |
131 | if ($clear) { |
131 | if ($clear) { |
132 | unset($ret); |
132 | unset($ret); |
133 | }
|
133 | }
|
134 | if (!isset($ret)) { |
134 | if (!isset($ret)) { |
135 | $ret = array(); |
135 | $ret = array(); |
136 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
136 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
137 | if ($okreleases['installable']) { |
137 | if ($okreleases['installable']) { |
138 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
138 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
139 | }
|
139 | }
|
140 | }
|
140 | }
|
141 | }
|
141 | }
|
142 | return $ret; |
142 | return $ret; |
143 | }
|
143 | }
|
144 | 144 | ||
145 | /**
|
145 | /**
|
146 | * Return an array of roles that are affected by the baseinstalldir attribute
|
146 | * Return an array of roles that are affected by the baseinstalldir attribute
|
147 | *
|
147 | *
|
148 | * Most roles ignore this attribute, and instead install directly into:
|
148 | * Most roles ignore this attribute, and instead install directly into:
|
149 | * PackageName/filepath
|
149 | * PackageName/filepath
|
150 | * so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php
|
150 | * so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php
|
151 | * @param bool clear cache
|
151 | * @param bool clear cache
|
152 | * @return array
|
152 | * @return array
|
153 | * @static
|
153 | * @static
|
154 | */
|
154 | */
|
155 | function getBaseinstallRoles($clear = false) |
155 | function getBaseinstallRoles($clear = false) |
156 | {
|
156 | {
|
157 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
157 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
158 | PEAR_Installer_Role::registerRoles(); |
158 | PEAR_Installer_Role::registerRoles(); |
159 | }
|
159 | }
|
160 | static $ret; |
160 | static $ret; |
161 | if ($clear) { |
161 | if ($clear) { |
162 | unset($ret); |
162 | unset($ret); |
163 | }
|
163 | }
|
164 | if (!isset($ret)) { |
164 | if (!isset($ret)) { |
165 | $ret = array(); |
165 | $ret = array(); |
166 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
166 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
167 | if ($okreleases['honorsbaseinstall']) { |
167 | if ($okreleases['honorsbaseinstall']) { |
168 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
168 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
169 | }
|
169 | }
|
170 | }
|
170 | }
|
171 | }
|
171 | }
|
172 | return $ret; |
172 | return $ret; |
173 | }
|
173 | }
|
174 | 174 | ||
175 | /**
|
175 | /**
|
176 | * Return an array of file roles that should be analyzed for PHP content at package time,
|
176 | * Return an array of file roles that should be analyzed for PHP content at package time,
|
177 | * like the "php" role.
|
177 | * like the "php" role.
|
178 | * @param bool clear cache
|
178 | * @param bool clear cache
|
179 | * @return array
|
179 | * @return array
|
180 | * @static
|
180 | * @static
|
181 | */
|
181 | */
|
182 | function getPhpRoles($clear = false) |
182 | function getPhpRoles($clear = false) |
183 | {
|
183 | {
|
184 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
184 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { |
185 | PEAR_Installer_Role::registerRoles(); |
185 | PEAR_Installer_Role::registerRoles(); |
186 | }
|
186 | }
|
187 | static $ret; |
187 | static $ret; |
188 | if ($clear) { |
188 | if ($clear) { |
189 | unset($ret); |
189 | unset($ret); |
190 | }
|
190 | }
|
191 | if (!isset($ret)) { |
191 | if (!isset($ret)) { |
192 | $ret = array(); |
192 | $ret = array(); |
193 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
193 | foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { |
194 | if ($okreleases['phpfile']) { |
194 | if ($okreleases['phpfile']) { |
195 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
195 | $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); |
196 | }
|
196 | }
|
197 | }
|
197 | }
|
198 | }
|
198 | }
|
199 | return $ret; |
199 | return $ret; |
200 | }
|
200 | }
|
201 | 201 | ||
202 | /**
|
202 | /**
|
203 | * Scan through the Command directory looking for classes
|
203 | * Scan through the Command directory looking for classes
|
204 | * and see what commands they implement.
|
204 | * and see what commands they implement.
|
205 | * @param string which directory to look for classes, defaults to
|
205 | * @param string which directory to look for classes, defaults to
|
206 | * the Installer/Roles subdirectory of
|
206 | * the Installer/Roles subdirectory of
|
207 | * the directory from where this file (__FILE__) is
|
207 | * the directory from where this file (__FILE__) is
|
208 | * included.
|
208 | * included.
|
209 | *
|
209 | *
|
210 | * @return bool TRUE on success, a PEAR error on failure
|
210 | * @return bool TRUE on success, a PEAR error on failure
|
211 | * @access public
|
211 | * @access public
|
212 | * @static
|
212 | * @static
|
213 | */
|
213 | */
|
214 | function registerRoles($dir = null) |
214 | function registerRoles($dir = null) |
215 | {
|
215 | {
|
216 | $GLOBALS['_PEAR_INSTALLER_ROLES'] = array(); |
216 | $GLOBALS['_PEAR_INSTALLER_ROLES'] = array(); |
217 | $parser = new PEAR_XMLParser; |
217 | $parser = new PEAR_XMLParser; |
218 | if ($dir === null) { |
218 | if ($dir === null) { |
219 | $dir = dirname(__FILE__) . '/Role'; |
219 | $dir = dirname(__FILE__) . '/Role'; |
220 | }
|
220 | }
|
221 | if (!file_exists($dir) || !is_dir($dir)) { |
221 | if (!file_exists($dir) || !is_dir($dir)) { |
222 | return PEAR::raiseError("registerRoles: opendir($dir) failed: does not exist/is not directory"); |
222 | return PEAR::raiseError("registerRoles: opendir($dir) failed: does not exist/is not directory"); |
223 | }
|
223 | }
|
224 | $dp = @opendir($dir); |
224 | $dp = @opendir($dir); |
225 | if (empty($dp)) { |
225 | if (empty($dp)) { |
226 | return PEAR::raiseError("registerRoles: opendir($dir) failed: $php_errmsg"); |
226 | return PEAR::raiseError("registerRoles: opendir($dir) failed: $php_errmsg"); |
227 | }
|
227 | }
|
228 | while ($entry = readdir($dp)) { |
228 | while ($entry = readdir($dp)) { |
229 | if ($entry{0} == '.' || substr($entry, -4) != '.xml') { |
229 | if ($entry{0} == '.' || substr($entry, -4) != '.xml') { |
230 | continue; |
230 | continue; |
231 | }
|
231 | }
|
232 | $class = "PEAR_Installer_Role_".substr($entry, 0, -4); |
232 | $class = "PEAR_Installer_Role_".substr($entry, 0, -4); |
233 | // List of roles
|
233 | // List of roles
|
234 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) { |
234 | if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) { |
235 | $file = "$dir/$entry"; |
235 | $file = "$dir/$entry"; |
236 | $parser->parse(file_get_contents($file)); |
236 | $parser->parse(file_get_contents($file)); |
237 | $data = $parser->getData(); |
237 | $data = $parser->getData(); |
238 | if (!is_array($data['releasetypes'])) { |
238 | if (!is_array($data['releasetypes'])) { |
239 | $data['releasetypes'] = array($data['releasetypes']); |
239 | $data['releasetypes'] = array($data['releasetypes']); |
240 | }
|
240 | }
|
241 | $GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data; |
241 | $GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data; |
242 | }
|
242 | }
|
243 | }
|
243 | }
|
244 | closedir($dp); |
244 | closedir($dp); |
245 | ksort($GLOBALS['_PEAR_INSTALLER_ROLES']); |
245 | ksort($GLOBALS['_PEAR_INSTALLER_ROLES']); |
246 | PEAR_Installer_Role::getBaseinstallRoles(true); |
246 | PEAR_Installer_Role::getBaseinstallRoles(true); |
247 | PEAR_Installer_Role::getInstallableRoles(true); |
247 | PEAR_Installer_Role::getInstallableRoles(true); |
248 | PEAR_Installer_Role::getPhpRoles(true); |
248 | PEAR_Installer_Role::getPhpRoles(true); |
249 | PEAR_Installer_Role::getValidRoles('****', true); |
249 | PEAR_Installer_Role::getValidRoles('****', true); |
250 | return true; |
250 | return true; |
251 | }
|
251 | }
|
252 | }
|
252 | }
|
253 | ?>
|
253 | ?>
|
254 | 254 |