Initial repo created
[timetracker.git] / WEB-INF / lib / pear / PEAR / Installer / Role / Common.php
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     /**
40      * @param PEAR_Config
41      */
42     function PEAR_Installer_Role_Common(&$config)
43     {
44         $this->config = $config;
45     }
46
47     /**
48      * Retrieve configuration information about a file role from its XML info
49      *
50      * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
51      * @return array
52      */
53     function getInfo($role)
54     {
55         if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) {
56             return PEAR::raiseError('Unknown Role class: "' . $role . '"');
57         }
58         return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role];
59     }
60
61     /**
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:
67      *
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
72      */
73     function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
74     {
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)) {
78             return $roleInfo;
79         }
80         if (!$roleInfo['locationconfig']) {
81             return false;
82         }
83         if ($roleInfo['honorsbaseinstall']) {
84             $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer,
85                 $pkg->getChannel());
86             if (!empty($atts['baseinstalldir'])) {
87                 $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
88             }
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'];
94             }
95         } else {
96             $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'],
97                     $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage();
98         }
99         if (dirname($file) != '.' && empty($atts['install-as'])) {
100             $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
101         }
102         if (empty($atts['install-as'])) {
103             $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
104         } else {
105             $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
106         }
107         $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
108
109         // Clean up the DIRECTORY_SEPARATOR mess
110         $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
111         
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);
117     }
118
119     /**
120      * Get the name of the configuration variable that specifies the location of this file
121      * @return string|false
122      */
123     function getLocationConfig()
124     {
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)) {
128             return $roleInfo;
129         }
130         return $roleInfo['locationconfig'];
131     }
132
133     /**
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
139      */
140     function setup(&$installer, $pkg, $atts, $file)
141     {
142     }
143
144     function isExecutable()
145     {
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)) {
149             return $roleInfo;
150         }
151         return $roleInfo['executable'];
152     }
153
154     function isInstallable()
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['installable'];
162     }
163
164     function isExtension()
165     {
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)) {
169             return $roleInfo;
170         }
171         return $roleInfo['phpextension'];
172     }
173 }
174 ?>