Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Installer_Role
3
 * PEAR_Installer_Role
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
-
 
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
-
 
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.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @copyright  1997-2006 The PHP Group
10
 * @copyright  1997-2009 The Authors
17
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
11
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
18
 * @version    CVS: $Id: Role.php,v 1.16 2006/10/31 02:54:41 cellog Exp $
-
 
19
 * @link       http://pear.php.net/package/PEAR
12
 * @link       http://pear.php.net/package/PEAR
20
 * @since      File available since Release 1.4.0a1
13
 * @since      File available since Release 1.4.0a1
21
 */
14
 */
Line 22... Line 15...
22
 
15
 
Line 27... Line 20...
27
require_once 'PEAR/XMLParser.php';
20
require_once 'PEAR/XMLParser.php';
28
/**
21
/**
29
 * @category   pear
22
 * @category   pear
30
 * @package    PEAR
23
 * @package    PEAR
31
 * @author     Greg Beaver <cellog@php.net>
24
 * @author     Greg Beaver <cellog@php.net>
32
 * @copyright  1997-2006 The PHP Group
25
 * @copyright  1997-2009 The Authors
33
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
26
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
34
 * @version    Release: 1.5.1
27
 * @version    Release: 1.10.1
35
 * @link       http://pear.php.net/package/PEAR
28
 * @link       http://pear.php.net/package/PEAR
36
 * @since      Class available since Release 1.4.0a1
29
 * @since      Class available since Release 1.4.0a1
37
 */
30
 */
38
class PEAR_Installer_Role
31
class PEAR_Installer_Role
39
{
32
{
40
    /**
33
    /**
41
     * Set up any additional configuration variables that file roles require
34
     * Set up any additional configuration variables that file roles require
42
     *
35
     *
43
     * Never call this directly, it is called by the PEAR_Config constructor
36
     * Never call this directly, it is called by the PEAR_Config constructor
44
     * @param PEAR_Config
37
     * @param PEAR_Config
45
     * @access private
-
 
46
     * @static
-
 
47
     */
38
     */
48
    function initializeConfig(&$config)
39
    public static function initializeConfig(&$config)
49
    {
40
    {
50
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
41
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
51
            PEAR_Installer_Role::registerRoles();
42
            PEAR_Installer_Role::registerRoles();
52
        }
43
        }
-
 
44
 
53
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) {
45
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $class => $info) {
54
            if (!$info['config_vars']) {
46
            if (!$info['config_vars']) {
55
                continue;
47
                continue;
56
            }
48
            }
-
 
49
 
57
            $config->_addConfigVars($info['config_vars']);
50
            $config->_addConfigVars($class, $info['config_vars']);
58
        }
51
        }
59
    }
52
    }
Line 60... Line 53...
60
 
53
 
61
    /**
54
    /**
62
     * @param PEAR_PackageFile_v2
55
     * @param PEAR_PackageFile_v2
63
     * @param string role name
56
     * @param string role name
64
     * @param PEAR_Config
57
     * @param PEAR_Config
65
     * @return PEAR_Installer_Role_Common
-
 
66
     * @static
58
     * @return PEAR_Installer_Role_Common
67
     */
59
     */
68
    function &factory($pkg, $role, &$config)
60
    public static function &factory($pkg, $role, &$config)
69
    {
61
    {
70
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
62
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
71
            PEAR_Installer_Role::registerRoles();
63
            PEAR_Installer_Role::registerRoles();
-
 
64
        }
72
        }
65
 
73
        if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) {
66
        if (!in_array($role, PEAR_Installer_Role::getValidRoles($pkg->getPackageType()))) {
74
            $a = false;
67
            $a = false;
75
            return $a;
68
            return $a;
-
 
69
        }
76
        }
70
 
77
        $a = 'PEAR_Installer_Role_' . ucfirst($role);
71
        $a = 'PEAR_Installer_Role_' . ucfirst($role);
78
        if (!class_exists($a)) {
72
        if (!class_exists($a)) {
79
            require_once str_replace('_', '/', $a) . '.php';
73
            require_once str_replace('_', '/', $a) . '.php';
-
 
74
        }
80
        }
75
 
81
        $b = new $a($config);
76
        $b = new $a($config);
82
        return $b;
77
        return $b;
Line 83... Line 78...
83
    }
78
    }
Line 87... Line 82...
87
     *
82
     *
88
     * For instance, src files serve no purpose in regular php releases.
83
     * For instance, src files serve no purpose in regular php releases.
89
     * @param string
84
     * @param string
90
     * @param bool clear cache
85
     * @param bool clear cache
91
     * @return array
86
     * @return array
92
     * @static
-
 
93
     */
87
     */
94
    function getValidRoles($release, $clear = false)
88
    public static function getValidRoles($release, $clear = false)
95
    {
89
    {
96
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
90
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
97
            PEAR_Installer_Role::registerRoles();
91
            PEAR_Installer_Role::registerRoles();
98
        }
92
        }
-
 
93
 
99
        static $ret = array();
94
        static $ret = array();
100
        if ($clear) {
95
        if ($clear) {
101
            $ret = array();
96
            $ret = array();
102
        }
97
        }
-
 
98
 
103
        if (isset($ret[$release])) {
99
        if (isset($ret[$release])) {
104
            return $ret[$release];
100
            return $ret[$release];
105
        }
101
        }
-
 
102
 
106
        $ret[$release] = array();
103
        $ret[$release] = array();
107
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
104
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
108
            if (in_array($release, $okreleases['releasetypes'])) {
105
            if (in_array($release, $okreleases['releasetypes'])) {
109
                $ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
106
                $ret[$release][] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
110
            }
107
            }
111
        }
108
        }
-
 
109
 
112
        return $ret[$release];
110
        return $ret[$release];
113
    }
111
    }
Line 114... Line 112...
114
 
112
 
115
    /**
113
    /**
Line 118... Line 116...
118
     * Most roles must be installed, but src and package roles, for instance
116
     * Most roles must be installed, but src and package roles, for instance
119
     * are pseudo-roles.  src files are compiled into a new extension.  Package
117
     * are pseudo-roles.  src files are compiled into a new extension.  Package
120
     * roles are actually fully bundled releases of a package
118
     * roles are actually fully bundled releases of a package
121
     * @param bool clear cache
119
     * @param bool clear cache
122
     * @return array
120
     * @return array
123
     * @static
-
 
124
     */
121
     */
125
    function getInstallableRoles($clear = false)
122
    public static function getInstallableRoles($clear = false)
126
    {
123
    {
127
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
124
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
128
            PEAR_Installer_Role::registerRoles();
125
            PEAR_Installer_Role::registerRoles();
129
        }
126
        }
-
 
127
 
130
        static $ret;
128
        static $ret;
131
        if ($clear) {
129
        if ($clear) {
132
            unset($ret);
130
            unset($ret);
133
        }
131
        }
-
 
132
 
134
        if (!isset($ret)) {
133
        if (isset($ret)) {
-
 
134
            return $ret;
-
 
135
        }
-
 
136
 
135
            $ret = array();
137
        $ret = array();
136
            foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
138
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
137
                if ($okreleases['installable']) {
139
            if ($okreleases['installable']) {
138
                    $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
140
                $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
139
                }
-
 
140
            }
141
            }
141
        }
142
        }
-
 
143
 
142
        return $ret;
144
        return $ret;
143
    }
145
    }
Line 144... Line 146...
144
 
146
 
145
    /**
147
    /**
Line 148... Line 150...
148
     * Most roles ignore this attribute, and instead install directly into:
150
     * Most roles ignore this attribute, and instead install directly into:
149
     * PackageName/filepath
151
     * PackageName/filepath
150
     * so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php
152
     * so a tests file tests/file.phpt is installed into PackageName/tests/filepath.php
151
     * @param bool clear cache
153
     * @param bool clear cache
152
     * @return array
154
     * @return array
153
     * @static
-
 
154
     */
155
     */
155
    function getBaseinstallRoles($clear = false)
156
    public static function getBaseinstallRoles($clear = false)
156
    {
157
    {
157
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
158
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
158
            PEAR_Installer_Role::registerRoles();
159
            PEAR_Installer_Role::registerRoles();
159
        }
160
        }
-
 
161
 
160
        static $ret;
162
        static $ret;
161
        if ($clear) {
163
        if ($clear) {
162
            unset($ret);
164
            unset($ret);
163
        }
165
        }
-
 
166
 
164
        if (!isset($ret)) {
167
        if (isset($ret)) {
-
 
168
            return $ret;
-
 
169
        }
-
 
170
 
165
            $ret = array();
171
        $ret = array();
166
            foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
172
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
167
                if ($okreleases['honorsbaseinstall']) {
173
            if ($okreleases['honorsbaseinstall']) {
168
                    $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
174
                $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
169
                }
-
 
170
            }
175
            }
171
        }
176
        }
-
 
177
 
172
        return $ret;
178
        return $ret;
173
    }
179
    }
Line 174... Line 180...
174
 
180
 
175
    /**
181
    /**
176
     * Return an array of file roles that should be analyzed for PHP content at package time,
182
     * Return an array of file roles that should be analyzed for PHP content at package time,
177
     * like the "php" role.
183
     * like the "php" role.
178
     * @param bool clear cache
184
     * @param bool clear cache
179
     * @return array
-
 
180
     * @static
185
     * @return array
181
     */
186
     */
182
    function getPhpRoles($clear = false)
187
    public static function getPhpRoles($clear = false)
183
    {
188
    {
184
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
189
        if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'])) {
185
            PEAR_Installer_Role::registerRoles();
190
            PEAR_Installer_Role::registerRoles();
-
 
191
        }
186
        }
192
 
187
        static $ret;
193
        static $ret;
188
        if ($clear) {
194
        if ($clear) {
189
            unset($ret);
195
            unset($ret);
-
 
196
        }
190
        }
197
 
-
 
198
        if (isset($ret)) {
-
 
199
            return $ret;
-
 
200
        }
191
        if (!isset($ret)) {
201
 
192
            $ret = array();
202
        $ret = array();
193
            foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
203
        foreach ($GLOBALS['_PEAR_INSTALLER_ROLES'] as $role => $okreleases) {
194
                if ($okreleases['phpfile']) {
204
            if ($okreleases['phpfile']) {
195
                    $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
-
 
196
                }
205
                $ret[] = strtolower(str_replace('PEAR_Installer_Role_', '', $role));
197
            }
206
            }
-
 
207
        }
198
        }
208
 
199
        return $ret;
209
        return $ret;
Line 200... Line 210...
200
    }
210
    }
201
 
211
 
Line 206... Line 216...
206
     *               the Installer/Roles subdirectory of
216
     *               the Installer/Roles subdirectory of
207
     *               the directory from where this file (__FILE__) is
217
     *               the directory from where this file (__FILE__) is
208
     *               included.
218
     *               included.
209
     *
219
     *
210
     * @return bool TRUE on success, a PEAR error on failure
220
     * @return bool TRUE on success, a PEAR error on failure
211
     * @access public
-
 
212
     * @static
-
 
213
     */
221
     */
214
    function registerRoles($dir = null)
222
    public static function registerRoles($dir = null)
215
    {
223
    {
216
        $GLOBALS['_PEAR_INSTALLER_ROLES'] = array();
224
        $GLOBALS['_PEAR_INSTALLER_ROLES'] = array();
217
        $parser = new PEAR_XMLParser;
225
        $parser = new PEAR_XMLParser;
218
        if ($dir === null) {
226
        if ($dir === null) {
219
            $dir = dirname(__FILE__) . '/Role';
227
            $dir = dirname(__FILE__) . '/Role';
220
        }
228
        }
-
 
229
 
221
        if (!file_exists($dir) || !is_dir($dir)) {
230
        if (!file_exists($dir) || !is_dir($dir)) {
222
            return PEAR::raiseError("registerRoles: opendir($dir) failed");
231
            return PEAR::raiseError("registerRoles: opendir($dir) failed: does not exist/is not directory");
223
        }
232
        }
-
 
233
 
224
        $dp = @opendir($dir);
234
        $dp = @opendir($dir);
225
        if (empty($dp)) {
235
        if (empty($dp)) {
226
            return PEAR::raiseError("registerRoles: opendir($dir) failed");
236
            return PEAR::raiseError("registerRoles: opendir($dir) failed: $php_errmsg");
227
        }
237
        }
-
 
238
 
228
        while ($entry = readdir($dp)) {
239
        while ($entry = readdir($dp)) {
229
            if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
240
            if ($entry{0} == '.' || substr($entry, -4) != '.xml') {
230
                continue;
241
                continue;
231
            }
242
            }
-
 
243
 
232
            $class = "PEAR_Installer_Role_".substr($entry, 0, -4);
244
            $class = "PEAR_Installer_Role_".substr($entry, 0, -4);
233
            // List of roles
245
            // List of roles
234
            if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) {
246
            if (!isset($GLOBALS['_PEAR_INSTALLER_ROLES'][$class])) {
235
                $file = "$dir/$entry";
247
                $file = "$dir/$entry";
236
                $parser->parse(file_get_contents($file));
248
                $parser->parse(file_get_contents($file));
237
                $data = $parser->getData();
249
                $data = $parser->getData();
238
                if (!is_array($data['releasetypes'])) {
250
                if (!is_array($data['releasetypes'])) {
239
                    $data['releasetypes'] = array($data['releasetypes']);
251
                    $data['releasetypes'] = array($data['releasetypes']);
240
                }
252
                }
-
 
253
 
241
                $GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data;
254
                $GLOBALS['_PEAR_INSTALLER_ROLES'][$class] = $data;
242
            }
255
            }
243
        }
256
        }
-
 
257
 
244
        closedir($dp);
258
        closedir($dp);
245
        ksort($GLOBALS['_PEAR_INSTALLER_ROLES']);
259
        ksort($GLOBALS['_PEAR_INSTALLER_ROLES']);
246
        PEAR_Installer_Role::getBaseinstallRoles(true);
260
        PEAR_Installer_Role::getBaseinstallRoles(true);
247
        PEAR_Installer_Role::getInstallableRoles(true);
261
        PEAR_Installer_Role::getInstallableRoles(true);
248
        PEAR_Installer_Role::getPhpRoles(true);
262
        PEAR_Installer_Role::getPhpRoles(true);
249
        PEAR_Installer_Role::getValidRoles('****', true);
263
        PEAR_Installer_Role::getValidRoles('****', true);
250
        return true;
264
        return true;
251
    }
265
    }
252
}
266
}
253
?>
-
 
254
267