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