Aggregate Code Coverage for all tests
1 : <?php 2 : /** 3 : * Base class for all installation roles. 4 : * 5 : * PHP version 5 6 : * 7 : * @category PEAR2 8 : * @package PEAR2_Pyrus 9 : * @author Greg Beaver <cellog@php.net> 10 : * @copyright 2008 The PEAR Group 11 : * @license http://www.opensource.org/licenses/bsd-license.php New BSD License 12 : * @version SVN: $Id$ 13 : * @link http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/ 14 : */ 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 : * 23 : * @category PEAR2 24 : * @package PEAR2_Pyrus 25 : * @author Greg Beaver <cellog@php.net> 26 : * @copyright 2008 The PEAR Group 27 : * @license http://www.opensource.org/licenses/bsd-license.php New BSD License 28 : * @link http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/ 29 : */ 30 : class PEAR2_Pyrus_Installer_Role_Common 31 1 : { 32 : /** 33 : * @var PEAR_Config 34 : * @access protected 35 : */ 36 : protected $config; 37 : 38 : /** 39 : * @param PEAR2_Pyrus_Config 40 : */ 41 : function __construct(PEAR2_Pyrus_Config $config) 42 : { 43 1 : $this->config = $config; 44 1 : } 45 : 46 : /** 47 : * Retrieve configuration information about a file role from its XML info 48 : * 49 : * @param string $role Role Classname, as in "PEAR2_Pyrus_Installer_Role_Data" 50 : * @return array 51 : */ 52 : static function getInfo($role) 53 : { 54 : return PEAR2_Pyrus_Installer_Role::getInfo($role); 55 : } 56 : 57 : /** 58 : * Retrieve the location a packaged file should be placed in a package 59 : * 60 : * @param PEAR2_Pyrus_Package $pkg 61 : * @param array $atts 62 : * @return string 63 : */ 64 : function getPackagingLocation(PEAR2_Pyrus_PackageFile_v2 $pkg, $atts) 65 : { 66 : $roleInfo = PEAR2_Pyrus_Installer_Role::getInfo('PEAR2_Pyrus_Installer_Role_' . 67 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 68 : $role = str_replace('pear2_pyrus_installer_role_', '', 69 : strtolower(get_class($this))); 70 : if ($role === 'php') { 71 : $role = 'src'; // we use "src" as the directory for role=php 72 : } 73 : 74 : $file = $atts['name']; 75 : // strip role from file path 76 : // so src/Path/To/File.php becomes Path/To/File.php, 77 : // data/package.xsd becomes package.xsd 78 : $newpath = $file; 79 : if (strpos($newpath, $role) === 0) { 80 : $newpath = substr($newpath, strlen($role) + 1); 81 : if ($newpath === false) { 82 : $newpath = $file; 83 : } 84 : } 85 : 86 : if ($newpath) { 87 : $file = $newpath; 88 : } 89 : 90 : if ($roleInfo['honorsbaseinstall']) { 91 : $dest_dir = $role; 92 : if (array_key_exists('baseinstalldir', $atts)) { 93 : if ($atts['baseinstalldir'] != '/') { 94 : $dest_dir .= '/' . $atts['baseinstalldir']; 95 : } 96 : 97 : if (strlen($atts['baseinstalldir'])) { 98 : $dest_dir .= '/'; 99 : } 100 : } else { 101 : $dest_dir .= '/'; 102 : } 103 : } elseif ($roleInfo['unusualbaseinstall']) { 104 : $dest_dir = $role . '/' . $pkg->channel . '/' . $pkg->name . '/'; 105 : if (array_key_exists('baseinstalldir', $atts)) { 106 : if (strlen($atts['baseinstalldir']) && $atts['baseinstalldir'] != '/') { 107 : $dest_dir .= $atts['baseinstalldir']; 108 : if (strlen($atts['baseinstalldir'])) { 109 : $dest_dir .= '/'; 110 : } 111 : } 112 : } else { 113 : if (dirname($file) != '.') { 114 : $dest_dir .= dirname($file) . '/'; 115 : } 116 : } 117 : } else { 118 : $dest_dir = $role . '/' . $pkg->channel . '/' . $pkg->name . '/'; 119 : } 120 : 121 : return $dest_dir . $file; 122 : } 123 : 124 : /** 125 : * This is called for each file to set up the directories and files 126 : * @param PEAR2_Pyrus_Package 127 : * @param array attributes from the <file> tag 128 : * @param string file name 129 : * @return array an array consisting of: 130 : * 131 : * 1 the original, pre-baseinstalldir installation directory 132 : * 2 the final installation directory 133 : * 3 the full path to the final location of the file 134 : * 4 the location of the pre-installation file 135 : */ 136 : function processInstallation(PEAR2_Pyrus_Package $pkg, $atts, $file, $tmp_path, $layer = null) 137 : { 138 : $roleInfo = PEAR2_Pyrus_Installer_Role::getInfo('PEAR2_Pyrus_Installer_Role_' . 139 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 140 : if (!$roleInfo['locationconfig']) { 141 : return false; 142 : } 143 : 144 : $where = $this->config->{$roleInfo['locationconfig']}; 145 : if ($roleInfo['honorsbaseinstall']) { 146 : $dest_dir = $save_destdir = $where; 147 : if (!empty($atts['baseinstalldir'])) { 148 : $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; 149 : } 150 : } elseif ($roleInfo['unusualbaseinstall']) { 151 : $dest_dir = $save_destdir = $where . 152 : DIRECTORY_SEPARATOR . $pkg->channel . DIRECTORY_SEPARATOR . $pkg->name; 153 : if (!empty($atts['baseinstalldir'])) { 154 : $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; 155 : } 156 : } else { 157 : $dest_dir = $save_destdir = $where . 158 : DIRECTORY_SEPARATOR . $pkg->channel . DIRECTORY_SEPARATOR . $pkg->name; 159 : } 160 : 161 : if (dirname($file) != '.' && empty($atts['install-as'])) { 162 : $newpath = dirname($file); 163 : if ($pkg->isNewPackage()) { 164 : // strip role from file path 165 : // so php/Path/To/File.php becomes Path/To/File.php, 166 : // data/package.xsd becomes package.xsd 167 : if (strpos($newpath, $r = strtolower(str_replace('PEAR2_Pyrus_Installer_Role_', '', 168 : get_class($this)))) === 0) { 169 : $newpath = substr($newpath, strlen($r) + 1); 170 : if ($newpath === false) { 171 : $newpath = ''; 172 : } 173 : } elseif ($r === 'php' && strpos($newpath, $r = 'src') === 0) { 174 : $newpath = substr($newpath, strlen($r) + 1); 175 : if ($newpath === false) { 176 : $newpath = ''; 177 : } 178 : } 179 : } 180 : $dest_dir .= DIRECTORY_SEPARATOR . $newpath; 181 : } 182 : 183 : $dest_file = $dest_dir . DIRECTORY_SEPARATOR; 184 : if (empty($atts['install-as'])) { 185 : $dest_file .= basename($file); 186 : } else { 187 : $dest_file .= $atts['install-as']; 188 : } 189 : 190 : $orig_file = $pkg->getFilePath($file); 191 : 192 : // Clean up the DIRECTORY_SEPARATOR mess 193 : $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; 194 : 195 : list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"), 196 : array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, 197 : DIRECTORY_SEPARATOR), 198 : array($dest_dir, $dest_file, $orig_file)); 199 : return array($save_destdir, $dest_dir, $dest_file, $orig_file); 200 : } 201 : 202 : /** 203 : * Get the name of the configuration variable that specifies the location of this file 204 : * @return string|false 205 : */ 206 : function getLocationConfig() 207 : { 208 1 : $roleInfo = PEAR2_Pyrus_Installer_Role::getInfo('PEAR2_Pyrus_Installer_Role_' . 209 1 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 210 1 : return $roleInfo['locationconfig']; 211 : } 212 : 213 : /** 214 : * Do any unusual setup here 215 : * @param PEAR_Installer 216 : * @param PEAR_PackageFile_v2 217 : * @param array file attributes 218 : * @param string file name 219 : */ 220 : function setup($installer, $pkg, $atts, $file) 221 : { 222 : } 223 : 224 : function isExecutable() 225 : { 226 : $roleInfo = PEAR2_Pyrus_Installer_Role::getInfo('PEAR2_Pyrus_Installer_Role_' . 227 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 228 : return $roleInfo['executable']; 229 : } 230 : 231 : function isInstallable() 232 : { 233 : $roleInfo = PEAR2_Pyrus_Installer_Role_Common::getInfo('PEAR2_Pyrus_Installer_Role_' . 234 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 235 : return $roleInfo['installable']; 236 : } 237 : 238 : function isExtension() 239 : { 240 : $roleInfo = PEAR2_Pyrus_Installer_Role::getInfo('PEAR2_Pyrus_Installer_Role_' . 241 : ucfirst(str_replace('pear2_pyrus_installer_role_', '', strtolower(get_class($this))))); 242 : return $roleInfo['phpextension']; 243 : } 244 1 : }