3 * Base class for all installation roles.
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
17 * Base class for all installation roles.
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.
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
31 class PEAR_Installer_Role_Common
42 function PEAR_Installer_Role_Common(&$config)
44 $this->config = $config;
48 * Retrieve configuration information about a file role from its XML info
50 * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
53 function getInfo($role)
55 if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) {
56 return PEAR::raiseError('Unknown Role class: "' . $role . '"');
58 return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role];
62 * This is called for each file to set up the directories and files
63 * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
64 * @param array attributes from the <file> tag
65 * @param string file name
66 * @return array an array consisting of:
68 * 1 the original, pre-baseinstalldir installation directory
69 * 2 the final installation directory
70 * 3 the full path to the final location of the file
71 * 4 the location of the pre-installation file
73 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
75 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
76 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
77 if (PEAR::isError($roleInfo)) {
80 if (!$roleInfo['locationconfig']) {
83 if ($roleInfo['honorsbaseinstall']) {
84 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer,
86 if (!empty($atts['baseinstalldir'])) {
87 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
89 } elseif ($roleInfo['unusualbaseinstall']) {
90 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
91 $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
92 if (!empty($atts['baseinstalldir'])) {
93 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
96 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
97 $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
99 if (dirname($file) != '.' && empty($atts['install-as'])) {
100 $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
102 if (empty($atts['install-as'])) {
103 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
105 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
107 $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
109 // Clean up the DIRECTORY_SEPARATOR mess
110 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
112 list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
113 array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
114 DIRECTORY_SEPARATOR),
115 array($dest_dir, $dest_file, $orig_file));
116 return array($save_destdir, $dest_dir, $dest_file, $orig_file);
120 * Get the name of the configuration variable that specifies the location of this file
121 * @return string|false
123 function getLocationConfig()
125 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
126 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
127 if (PEAR::isError($roleInfo)) {
130 return $roleInfo['locationconfig'];
134 * Do any unusual setup here
135 * @param PEAR_Installer
136 * @param PEAR_PackageFile_v2
137 * @param array file attributes
138 * @param string file name
140 function setup(&$installer, $pkg, $atts, $file)
144 function isExecutable()
146 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
147 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
148 if (PEAR::isError($roleInfo)) {
151 return $roleInfo['executable'];
154 function isInstallable()
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)) {
161 return $roleInfo['installable'];
164 function isExtension()
166 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
167 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
168 if (PEAR::isError($roleInfo)) {
171 return $roleInfo['phpextension'];