Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 87 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * Base class for all installation roles.
|
3 | * Base class for all installation roles.
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
8 | * that is available through the world-wide-web at the following URI:
|
8 | * that is available through the world-wide-web at the following URI:
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
10 | * the PHP License and are unable to obtain it through the web, please
|
10 | * the PHP License and are unable to obtain it through the web, please
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Greg Beaver <cellog@php.net>
|
15 | * @author Greg Beaver <cellog@php.net>
|
16 | * @copyright 1997-2006 The PHP Group
|
16 | * @copyright 1997-2006 The PHP Group
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @version CVS: $Id: Common.php,v 1.12 2006/10/19 23:55:32 cellog Exp $
|
18 | * @version CVS: $Id: Common.php,v 1.12 2006/10/19 23:55:32 cellog Exp $
|
19 | * @link http://pear.php.net/package/PEAR
|
19 | * @link http://pear.php.net/package/PEAR
|
20 | * @since File available since Release 1.4.0a1
|
20 | * @since File available since Release 1.4.0a1
|
21 | */
|
21 | */
|
22 | /**
|
22 | /**
|
23 | * Base class for all installation roles.
|
23 | * Base class for all installation roles.
|
24 | *
|
24 | *
|
25 | * This class allows extensibility of file roles. Packages with complex
|
25 | * This class allows extensibility of file roles. Packages with complex
|
26 | * customization can now provide custom file roles along with the possibility of
|
26 | * customization can now provide custom file roles along with the possibility of
|
27 | * adding configuration values to match.
|
27 | * adding configuration values to match.
|
28 | * @category pear
|
28 | * @category pear
|
29 | * @package PEAR
|
29 | * @package PEAR
|
30 | * @author Greg Beaver <cellog@php.net>
|
30 | * @author Greg Beaver <cellog@php.net>
|
31 | * @copyright 1997-2006 The PHP Group
|
31 | * @copyright 1997-2006 The PHP Group
|
32 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
32 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
33 | * @version Release: 1.7.2
|
33 | * @version Release: 1.7.2
|
34 | * @link http://pear.php.net/package/PEAR
|
34 | * @link http://pear.php.net/package/PEAR
|
35 | * @since Class available since Release 1.4.0a1
|
35 | * @since Class available since Release 1.4.0a1
|
36 | */
|
36 | */
|
37 | class PEAR_Installer_Role_Common
|
37 | class PEAR_Installer_Role_Common
|
38 | {
|
38 | {
|
39 | /**
|
39 | /**
|
40 | * @var PEAR_Config
|
40 | * @var PEAR_Config
|
41 | * @access protected
|
41 | * @access protected
|
42 | */
|
42 | */
|
43 | var $config; |
43 | var $config; |
44 | 44 | ||
45 | /**
|
45 | /**
|
46 | * @param PEAR_Config
|
46 | * @param PEAR_Config
|
47 | */
|
47 | */
|
48 | function PEAR_Installer_Role_Common(&$config) |
48 | function PEAR_Installer_Role_Common(&$config) |
49 | {
|
49 | {
|
50 | $this->config = $config; |
50 | $this->config = $config; |
51 | }
|
51 | }
|
52 | 52 | ||
53 | /**
|
53 | /**
|
54 | * Retrieve configuration information about a file role from its XML info
|
54 | * Retrieve configuration information about a file role from its XML info
|
55 | *
|
55 | *
|
56 | * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
|
56 | * @param string $role Role Classname, as in "PEAR_Installer_Role_Data"
|
57 | * @return array
|
57 | * @return array
|
58 | */
|
58 | */
|
59 | function getInfo($role) |
59 | function getInfo($role) |
60 | {
|
60 | {
|
61 | if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) { |
61 | if (empty($GLOBALS['_PEAR_INSTALLER_ROLES'][$role])) { |
62 | return PEAR::raiseError('Unknown Role class: "' . $role . '"'); |
62 | return PEAR::raiseError('Unknown Role class: "' . $role . '"'); |
63 | }
|
63 | }
|
64 | return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role]; |
64 | return $GLOBALS['_PEAR_INSTALLER_ROLES'][$role]; |
65 | }
|
65 | }
|
66 | 66 | ||
67 | /**
|
67 | /**
|
68 | * This is called for each file to set up the directories and files
|
68 | * This is called for each file to set up the directories and files
|
69 | * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
|
69 | * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
|
70 | * @param array attributes from the <file> tag
|
70 | * @param array attributes from the <file> tag
|
71 | * @param string file name
|
71 | * @param string file name
|
72 | * @return array an array consisting of:
|
72 | * @return array an array consisting of:
|
73 | *
|
73 | *
|
74 | * 1 the original, pre-baseinstalldir installation directory
|
74 | * 1 the original, pre-baseinstalldir installation directory
|
75 | * 2 the final installation directory
|
75 | * 2 the final installation directory
|
76 | * 3 the full path to the final location of the file
|
76 | * 3 the full path to the final location of the file
|
77 | * 4 the location of the pre-installation file
|
77 | * 4 the location of the pre-installation file
|
78 | */
|
78 | */
|
79 | function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) |
79 | function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) |
80 | {
|
80 | {
|
81 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
81 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
82 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
82 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
83 | if (PEAR::isError($roleInfo)) { |
83 | if (PEAR::isError($roleInfo)) { |
84 | return $roleInfo; |
84 | return $roleInfo; |
85 | }
|
85 | }
|
86 | if (!$roleInfo['locationconfig']) { |
86 | if (!$roleInfo['locationconfig']) { |
87 | return false; |
87 | return false; |
88 | }
|
88 | }
|
89 | if ($roleInfo['honorsbaseinstall']) { |
89 | if ($roleInfo['honorsbaseinstall']) { |
90 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer, |
90 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], $layer, |
91 | $pkg->getChannel()); |
91 | $pkg->getChannel()); |
92 | if (!empty($atts['baseinstalldir'])) { |
92 | if (!empty($atts['baseinstalldir'])) { |
93 | $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; |
93 | $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; |
94 | }
|
94 | }
|
95 | } elseif ($roleInfo['unusualbaseinstall']) { |
95 | } elseif ($roleInfo['unusualbaseinstall']) { |
96 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], |
96 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], |
97 | $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage(); |
97 | $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage(); |
98 | if (!empty($atts['baseinstalldir'])) { |
98 | if (!empty($atts['baseinstalldir'])) { |
99 | $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; |
99 | $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir']; |
100 | }
|
100 | }
|
101 | } else { |
101 | } else { |
102 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], |
102 | $dest_dir = $save_destdir = $this->config->get($roleInfo['locationconfig'], |
103 | $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage(); |
103 | $layer, $pkg->getChannel()) . DIRECTORY_SEPARATOR . $pkg->getPackage(); |
104 | }
|
104 | }
|
105 | if (dirname($file) != '.' && empty($atts['install-as'])) { |
105 | if (dirname($file) != '.' && empty($atts['install-as'])) { |
106 | $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); |
106 | $dest_dir .= DIRECTORY_SEPARATOR . dirname($file); |
107 | }
|
107 | }
|
108 | if (empty($atts['install-as'])) { |
108 | if (empty($atts['install-as'])) { |
109 | $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); |
109 | $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file); |
110 | } else { |
110 | } else { |
111 | $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; |
111 | $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as']; |
112 | }
|
112 | }
|
113 | $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; |
113 | $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file; |
114 | 114 | ||
115 | // Clean up the DIRECTORY_SEPARATOR mess
|
115 | // Clean up the DIRECTORY_SEPARATOR mess
|
116 | $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; |
116 | $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; |
117 | 117 | ||
118 | list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"), |
118 | list($dest_dir, $dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"), |
119 | array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, |
119 | array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, |
120 | DIRECTORY_SEPARATOR), |
120 | DIRECTORY_SEPARATOR), |
121 | array($dest_dir, $dest_file, $orig_file)); |
121 | array($dest_dir, $dest_file, $orig_file)); |
122 | return array($save_destdir, $dest_dir, $dest_file, $orig_file); |
122 | return array($save_destdir, $dest_dir, $dest_file, $orig_file); |
123 | }
|
123 | }
|
124 | 124 | ||
125 | /**
|
125 | /**
|
126 | * Get the name of the configuration variable that specifies the location of this file
|
126 | * Get the name of the configuration variable that specifies the location of this file
|
127 | * @return string|false
|
127 | * @return string|false
|
128 | */
|
128 | */
|
129 | function getLocationConfig() |
129 | function getLocationConfig() |
130 | {
|
130 | {
|
131 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
131 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
132 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
132 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
133 | if (PEAR::isError($roleInfo)) { |
133 | if (PEAR::isError($roleInfo)) { |
134 | return $roleInfo; |
134 | return $roleInfo; |
135 | }
|
135 | }
|
136 | return $roleInfo['locationconfig']; |
136 | return $roleInfo['locationconfig']; |
137 | }
|
137 | }
|
138 | 138 | ||
139 | /**
|
139 | /**
|
140 | * Do any unusual setup here
|
140 | * Do any unusual setup here
|
141 | * @param PEAR_Installer
|
141 | * @param PEAR_Installer
|
142 | * @param PEAR_PackageFile_v2
|
142 | * @param PEAR_PackageFile_v2
|
143 | * @param array file attributes
|
143 | * @param array file attributes
|
144 | * @param string file name
|
144 | * @param string file name
|
145 | */
|
145 | */
|
146 | function setup(&$installer, $pkg, $atts, $file) |
146 | function setup(&$installer, $pkg, $atts, $file) |
147 | {
|
147 | {
|
148 | }
|
148 | }
|
149 | 149 | ||
150 | function isExecutable() |
150 | function isExecutable() |
151 | {
|
151 | {
|
152 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
152 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
153 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
153 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
154 | if (PEAR::isError($roleInfo)) { |
154 | if (PEAR::isError($roleInfo)) { |
155 | return $roleInfo; |
155 | return $roleInfo; |
156 | }
|
156 | }
|
157 | return $roleInfo['executable']; |
157 | return $roleInfo['executable']; |
158 | }
|
158 | }
|
159 | 159 | ||
160 | function isInstallable() |
160 | function isInstallable() |
161 | {
|
161 | {
|
162 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
162 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
163 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
163 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
164 | if (PEAR::isError($roleInfo)) { |
164 | if (PEAR::isError($roleInfo)) { |
165 | return $roleInfo; |
165 | return $roleInfo; |
166 | }
|
166 | }
|
167 | return $roleInfo['installable']; |
167 | return $roleInfo['installable']; |
168 | }
|
168 | }
|
169 | 169 | ||
170 | function isExtension() |
170 | function isExtension() |
171 | {
|
171 | {
|
172 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
172 | $roleInfo = PEAR_Installer_Role_Common::getInfo('PEAR_Installer_Role_' . |
173 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
173 | ucfirst(str_replace('pear_installer_role_', '', strtolower(get_class($this))))); |
174 | if (PEAR::isError($roleInfo)) { |
174 | if (PEAR::isError($roleInfo)) { |
175 | return $roleInfo; |
175 | return $roleInfo; |
176 | }
|
176 | }
|
177 | return $roleInfo['phpextension']; |
177 | return $roleInfo['phpextension']; |
178 | }
|
178 | }
|
179 | }
|
179 | }
|
180 | ?>
|
180 | ?>
|