Common.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * Base class for all installation roles.
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * @category pear
  8. * @package PEAR
  9. * @author Greg Beaver <cellog@php.net>
  10. * @copyright 1997-2006 The PHP Group
  11. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  12. * @version CVS: $Id: Common.php 313023 2011-07-06 19:17:11Z dufuz $
  13. * @link http://pear.php.net/package/PEAR
  14. * @since File available since Release 1.4.0a1
  15. */
  16. /**
  17. * Base class for all installation roles.
  18. *
  19. * This class allows extensibility of file roles. Packages with complex
  20. * customization can now provide custom file roles along with the possibility of
  21. * adding configuration values to match.
  22. * @category pear
  23. * @package PEAR
  24. * @author Greg Beaver <cellog@php.net>
  25. * @copyright 1997-2006 The PHP Group
  26. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  27. * @version Release: 1.9.4
  28. * @link http://pear.php.net/package/PEAR
  29. * @since Class available since Release 1.4.0a1
  30. */
  31. class PEAR_Installer_Role_Common
  32. {
  33. /**
  34. * @var PEAR_Config
  35. * @access protected
  36. */
  37. var $config;
  38. /**
  39. * @param PEAR_Config
  40. */
  41. function PEAR_Installer_Role_Common(&$config)
  42. {
  43. $this->config = $config;
  44. }
  45. /**
  46. * Retrieve configuration information about a file role from its XML info
  47. *
  48. * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
  49. * @return array
  50. */
  51. function getInfo($role)
  52. {
  53. if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) {
  54. return PEAR::raiseError('Unknown Role class: "' . $role . '"');
  55. }
  56. return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role];
  57. }
  58. /**
  59. * This is called for each file to set up the directories and files
  60. * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
  61. * @param array attributes from the <file> tag
  62. * @param string file name
  63. * @return array an array consisting of:
  64. *
  65. * 1 the original, pre-baseinstalldir installation directory
  66. * 2 the final installation directory
  67. * 3 the full path to the final location of the file
  68. * 4 the location of the pre-installation file
  69. */
  70. function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
  71. {
  72. $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
  73. ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  74. if (PEAR::isError($roleInfo)) {
  75. return $roleInfo;
  76. }
  77. if (!$roleInfo['locationconfig']) {
  78. return false;
  79. }
  80. if ($roleInfo['honorsbaseinstall']) {
  81. $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer,
  82. $pkg->getChannel());
  83. if (!empty($atts['baseinstalldir'])) {
  84. $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
  85. }
  86. } elseif ($roleInfo['unusualbaseinstall']) {
  87. $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
  88. $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
  89. if (!empty($atts['baseinstalldir'])) {
  90. $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
  91. }
  92. } else {
  93. $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
  94. $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
  95. }
  96. if (dirname($file) != '.' && empty($atts['install-as'])) {
  97. $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
  98. }
  99. if (empty($atts['install-as'])) {
  100. $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
  101. } else {
  102. $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
  103. }
  104. $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
  105. // Clean up the DIRECTORY_SEPARATOR mess
  106. $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
  107. list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
  108. array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
  109. DIRECTORY_SEPARATOR),
  110. array($dest_dir, $dest_file, $orig_file));
  111. return array($save_destdir, $dest_dir, $dest_file, $orig_file);
  112. }
  113. /**
  114. * Get the name of the configuration variable that specifies the location of this file
  115. * @return string|false
  116. */
  117. function getLocationConfig()
  118. {
  119. $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
  120. ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  121. if (PEAR::isError($roleInfo)) {
  122. return $roleInfo;
  123. }
  124. return $roleInfo['locationconfig'];
  125. }
  126. /**
  127. * Do any unusual setup here
  128. * @param PEAR_Installer
  129. * @param PEAR_PackageFile_v2
  130. * @param array file attributes
  131. * @param string file name
  132. */
  133. function setup(&$installer, $pkg, $atts, $file)
  134. {
  135. }
  136. function isExecutable()
  137. {
  138. $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
  139. ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  140. if (PEAR::isError($roleInfo)) {
  141. return $roleInfo;
  142. }
  143. return $roleInfo['executable'];
  144. }
  145. function isInstallable()
  146. {
  147. $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
  148. ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  149. if (PEAR::isError($roleInfo)) {
  150. return $roleInfo;
  151. }
  152. return $roleInfo['installable'];
  153. }
  154. function isExtension()
  155. {
  156. $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
  157. ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
  158. if (PEAR::isError($roleInfo)) {
  159. return $roleInfo;
  160. }
  161. return $roleInfo['phpextension'];
  162. }
  163. }
  164. ?>