PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/pear/PEAR/Installer/Role.php

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