[ Index ] |
|
Code source de GeekLog 1.4.1 |
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.13 2006/01/06 04:47:36 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 //$GLOBALS['_PEAR_INSTALLER_ROLES'] = array(); 29 /** 30 * @category pear 31 * @package PEAR 32 * @author Greg Beaver <cellog@php.net> 33 * @copyright 1997-2006 The PHP Group 34 * @license http://www.php.net/license/3_0.txt PHP License 3.0 35 * @version Release: 1.4.11 36 * @link http://pear.php.net/package/PEAR 37 * @since Class available since Release 1.4.0a1 38 */ 39 class PEAR_Installer_Role 40 { 41 /** 42 * Set up any additional configuration variables that file roles require 43 * 44 * Never call this directly, it is called by the PEAR_Config constructor 45 * @param PEAR_Config 46 * @access private 47 * @static 48 */ 49 function initializeConfig(&$config) 50 { 51 if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { 52 PEAR_Installer_Role::registerRoles(); 53 } 54 foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) { 55 if (!$info['config_vars']) { 56 continue; 57 } 58 $config->_addConfigVars($info['config_vars']); 59 } 60 } 61 62 /** 63 * @param PEAR_PackageFile_v2 64 * @param string role name 65 * @param PEAR_Config 66 * @return PEAR_Installer_Role_Common 67 * @static 68 */ 69 function &factory($pkg, $role, &$config) 70 { 71 if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { 72 PEAR_Installer_Role::registerRoles(); 73 } 74 if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) { 75 $a = false; 76 return $a; 77 } 78 $a = 'PEAR_Installer_Role_' . ucfirst($role); 79 if (!class_exists($a)) { 80 require_once str_replace('_', '/', $a) . '.php'; 81 } 82 $b = new $a($config); 83 return $b; 84 } 85 86 /** 87 * Get a list of file roles that are valid for the particular release type. 88 * 89 * For instance, src files serve no purpose in regular php releases. php files 90 * serve no purpose in extsrc or extbin releases 91 * @param string 92 * @param bool clear cache 93 * @return array 94 * @static 95 */ 96 function getValidRoles($release, $clear = false) 97 { 98 if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { 99 PEAR_Installer_Role::registerRoles(); 100 } 101 static $ret = array(); 102 if ($clear) { 103 $ret = array(); 104 } 105 if (isset($ret[$release])) { 106 return $ret[$release]; 107 } 108 $ret[$release] = array(); 109 foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { 110 if (in_array($release, $okreleases['releasetypes'])) { 111 $ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); 112 } 113 } 114 return $ret[$release]; 115 } 116 117 /** 118 * Get a list of roles that require their files to be installed 119 * 120 * Most roles must be installed, but src and package roles, for instance 121 * are pseudo-roles. src files are compiled into a new extension. Package 122 * roles are actually fully bundled releases of a package 123 * @param bool clear cache 124 * @return array 125 * @static 126 */ 127 function getInstallableRoles($clear = false) 128 { 129 if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { 130 PEAR_Installer_Role::registerRoles(); 131 } 132 static $ret; 133 if ($clear) { 134 unset($ret); 135 } 136 if (!isset($ret)) { 137 foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { 138 if ($okreleases['installable']) { 139 $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); 140 } 141 } 142 } 143 return $ret; 144 } 145 146 /** 147 * Return an array of roles that are affected by the baseinstalldir attribute 148 * 149 * Most roles ignore this attribute, and instead install directly into: 150 * PackageName/filepath 151 * so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php 152 * @param bool clear cache 153 * @return array 154 * @static 155 */ 156 function getBaseinstallRoles($clear = false) 157 { 158 if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) { 159 PEAR_Installer_Role::registerRoles(); 160 } 161 static $ret; 162 if ($clear) { 163 unset($ret); 164 } 165 if (!isset($ret)) { 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 foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) { 193 if ($okreleases['phpfile']) { 194 $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role)); 195 } 196 } 197 } 198 return $ret; 199 } 200 201 /** 202 * Scan through the Command directory looking for classes 203 * and see what commands they implement. 204 * @param string which directory to look for classes, defaults to 205 * the Installer/Roles subdirectory of 206 * the directory from where this file (__FILE__) is 207 * included. 208 * 209 * @return bool TRUE on success, a PEAR error on failure 210 * @access public 211 * @static 212 */ 213 function registerRoles($dir = null) 214 { 215 $parser = new PEAR_XMLParser; 216 if ($dir === null) { 217 $dir = dirname(__FILE__) . '/Role'; 218 } 219 $dp = @opendir($dir); 220 if (empty($dp)) { 221 return PEAR::raiseError("registerRoles: opendir($dir) failed"); 222 } 223 while ($entry = readdir($dp)) { 224 if ($entry{0} == '.' || substr($entry, -4) != '.xml') { 225 continue; 226 } 227 $class = "PEAR_Installer_Role_".substr($entry, 0, -4); 228 // List of roles 229 if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) { 230 $file = "$dir/$entry"; 231 $parser->parse(file_get_contents($file)); 232 $data = $parser->getData(); 233 if (!is_array($data['releasetypes'])) { 234 $data['releasetypes'] = array($data['releasetypes']); 235 } 236 $GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data; 237 } 238 } 239 @closedir($dp); 240 ksort($GLOBALS['_PEAR_INSTALLER_ROLES']); 241 PEAR_Installer_Role::getBaseinstallRoles(true); 242 PEAR_Installer_Role::getInstallableRoles(true); 243 PEAR_Installer_Role::getPhpRoles(true); 244 PEAR_Installer_Role::getValidRoles('****', true); 245 return true; 246 } 247 } 248 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |