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 * @link http://pear.php.net/package/PEAR
13 * @since File available since Release 1.4.0a1
16 * Base class for all installation roles.
18 * This class allows extensibility of file roles. Packages with complex
19 * customization can now provide custom file roles along with the possibility of
20 * adding configuration values to match.
23 * @author Greg Beaver <cellog@php.net>
24 * @copyright 1997-2006 The PHP Group
25 * @license http://opensource.org/licenses/bsd-license.php New BSD License
26 * @version Release: 1.10.1
27 * @link http://pear.php.net/package/PEAR
28 * @since Class available since Release 1.4.0a1
30 class PEAR_Installer_Role_Common
41 function __construct(&$config)
43 $this->config = $config;
47 * Retrieve configuration information about a file role from its XML info
49 * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
52 function getInfo($role)
54 if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) {
55 return PEAR::raiseError('Unknown Role class: "' . $role . '"');
57 return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role];
61 * This is called for each file to set up the directories and files
62 * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
63 * @param array attributes from the <file> tag
64 * @param string file name
65 * @return array an array consisting of:
67 * 1 the original, pre-baseinstalldir installation directory
68 * 2 the final installation directory
69 * 3 the full path to the final location of the file
70 * 4 the location of the pre-installation file
72 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
74 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
75 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
76 if (PEAR::isError($roleInfo)) {
79 if (!$roleInfo['locationconfig']) {
82 if ($roleInfo['honorsbaseinstall']) {
83 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer,
85 if (!empty($atts['baseinstalldir'])) {
86 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
88 } elseif ($roleInfo['unusualbaseinstall']) {
89 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
90 $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
91 if (!empty($atts['baseinstalldir'])) {
92 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
95 $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
96 $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
98 if (dirname($file) != '.' && empty($atts['install-as'])) {
99 $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
101 if (empty($atts['install-as'])) {
102 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
104 $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
106 $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
108 // Clean up the DIRECTORY_SEPARATOR mess
109 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
111 list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
112 array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR,
113 DIRECTORY_SEPARATOR),
114 array($dest_dir, $dest_file, $orig_file));
115 return array($save_destdir, $dest_dir, $dest_file, $orig_file);
119 * Get the name of the configuration variable that specifies the location of this file
120 * @return string|false
122 function getLocationConfig()
124 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
125 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
126 if (PEAR::isError($roleInfo)) {
129 return $roleInfo['locationconfig'];
133 * Do any unusual setup here
134 * @param PEAR_Installer
135 * @param PEAR_PackageFile_v2
136 * @param array file attributes
137 * @param string file name
139 function setup(&$installer, $pkg, $atts, $file)
143 function isExecutable()
145 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
146 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
147 if (PEAR::isError($roleInfo)) {
150 return $roleInfo['executable'];
153 function isInstallable()
155 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
156 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
157 if (PEAR::isError($roleInfo)) {
160 return $roleInfo['installable'];
163 function isExtension()
165 $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' .
166 ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this)))));
167 if (PEAR::isError($roleInfo)) {
170 return $roleInfo['phpextension'];