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_Dependency2, advanced dependency validation
3
 * PEAR_Dependency2, advanced dependency validation
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: Dependency2.php,v 1.54 2007/02/13 04:16:25 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 33... Line 26...
33
 * test_PEAR_Dependency2 class found in tests/PEAR_Dependency2/setup.php.inc,
26
 * test_PEAR_Dependency2 class found in tests/PEAR_Dependency2/setup.php.inc,
34
 * or unit tests will not actually validate the changes
27
 * or unit tests will not actually validate the changes
35
 * @category   pear
28
 * @category   pear
36
 * @package    PEAR
29
 * @package    PEAR
37
 * @author     Greg Beaver <cellog@php.net>
30
 * @author     Greg Beaver <cellog@php.net>
38
 * @copyright  1997-2006 The PHP Group
31
 * @copyright  1997-2009 The Authors
39
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
32
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
40
 * @version    Release: 1.5.1
33
 * @version    Release: 1.10.1
41
 * @link       http://pear.php.net/package/PEAR
34
 * @link       http://pear.php.net/package/PEAR
42
 * @since      Class available since Release 1.4.0a1
35
 * @since      Class available since Release 1.4.0a1
43
 */
36
 */
44
class PEAR_Dependency2
37
class PEAR_Dependency2
45
{
38
{
Line 47... Line 40...
47
     * One of the PEAR_VALIDATE_* states
40
     * One of the PEAR_VALIDATE_* states
48
     * @see PEAR_VALIDATE_NORMAL
41
     * @see PEAR_VALIDATE_NORMAL
49
     * @var integer
42
     * @var integer
50
     */
43
     */
51
    var $_state;
44
    var $_state;
-
 
45
 
52
    /**
46
    /**
53
     * Command-line options to install/upgrade/uninstall commands
47
     * Command-line options to install/upgrade/uninstall commands
54
     * @param array
48
     * @param array
55
     */
49
     */
56
    var $_options;
50
    var $_options;
-
 
51
 
57
    /**
52
    /**
58
     * @var OS_Guess
53
     * @var OS_Guess
59
     */
54
     */
60
    var $_os;
55
    var $_os;
-
 
56
 
61
    /**
57
    /**
62
     * @var PEAR_Registry
58
     * @var PEAR_Registry
63
     */
59
     */
64
    var $_registry;
60
    var $_registry;
-
 
61
 
65
    /**
62
    /**
66
     * @var PEAR_Config
63
     * @var PEAR_Config
67
     */
64
     */
68
    var $_config;
65
    var $_config;
-
 
66
 
69
    /**
67
    /**
70
     * @var PEAR_DependencyDB
68
     * @var PEAR_DependencyDB
71
     */
69
     */
72
    var $_dependencydb;
70
    var $_dependencydb;
-
 
71
 
73
    /**
72
    /**
74
     * Output of PEAR_Registry::parsedPackageName()
73
     * Output of PEAR_Registry::parsedPackageName()
75
     * @var array
74
     * @var array
76
     */
75
     */
77
    var $_currentPackage;
76
    var $_currentPackage;
-
 
77
 
78
    /**
78
    /**
79
     * @param PEAR_Config
79
     * @param PEAR_Config
80
     * @param array installation options
80
     * @param array installation options
81
     * @param array format of PEAR_Registry::parsedPackageName()
81
     * @param array format of PEAR_Registry::parsedPackageName()
82
     * @param int installation state (one of PEAR_VALIDATE_*)
82
     * @param int installation state (one of PEAR_VALIDATE_*)
83
     */
83
     */
84
    function PEAR_Dependency2(&$config, $installoptions, $package,
84
    function __construct(&$config, $installoptions, $package,
85
                              $state = PEAR_VALIDATE_INSTALLING)
85
                              $state = PEAR_VALIDATE_INSTALLING)
86
    {
86
    {
87
        $this->_config = &$config;
87
        $this->_config = &$config;
88
        if (!class_exists('PEAR_DependencyDB')) {
88
        if (!class_exists('PEAR_DependencyDB')) {
89
            require_once 'PEAR/DependencyDB.php';
89
            require_once 'PEAR/DependencyDB.php';
90
        }
90
        }
-
 
91
 
91
        if (isset($installoptions['packagingroot'])) {
92
        if (isset($installoptions['packagingroot'])) {
92
            // make sure depdb is in the right location
93
            // make sure depdb is in the right location
93
            $config->setInstallRoot($installoptions['packagingroot']);
94
            $config->setInstallRoot($installoptions['packagingroot']);
94
        }
95
        }
-
 
96
 
95
        $this->_registry = &$config->getRegistry();
97
        $this->_registry = &$config->getRegistry();
96
        $this->_dependencydb = &PEAR_DependencyDB::singleton($config);
98
        $this->_dependencydb = &PEAR_DependencyDB::singleton($config);
97
        if (isset($installoptions['packagingroot'])) {
99
        if (isset($installoptions['packagingroot'])) {
98
            $config->setInstallRoot(false);
100
            $config->setInstallRoot(false);
99
        }
101
        }
-
 
102
 
100
        $this->_options = $installoptions;
103
        $this->_options = $installoptions;
101
        $this->_state = $state;
104
        $this->_state = $state;
102
        if (!class_exists('OS_Guess')) {
105
        if (!class_exists('OS_Guess')) {
103
            require_once 'OS/Guess.php';
106
            require_once 'OS/Guess.php';
104
        }
107
        }
-
 
108
 
105
        $this->_os = new OS_Guess;
109
        $this->_os = new OS_Guess;
106
        $this->_currentPackage = $package;
110
        $this->_currentPackage = $package;
107
    }
111
    }
Line 108... Line 112...
108
 
112
 
109
    function _getExtraString($dep)
113
    function _getExtraString($dep)
110
    {
114
    {
111
        $extra = ' (';
115
        $extra = ' (';
112
        if (isset($dep['uri'])) {
116
        if (isset($dep['uri'])) {
113
            return '';
117
            return '';
-
 
118
        }
114
        }
119
 
115
        if (isset($dep['recommended'])) {
120
        if (isset($dep['recommended'])) {
116
            $extra .= 'recommended version ' . $dep['recommended'];
121
            $extra .= 'recommended version ' . $dep['recommended'];
117
        } else {
122
        } else {
118
            if (isset($dep['min'])) {
123
            if (isset($dep['min'])) {
119
                $extra .= 'version >= ' . $dep['min'];
124
                $extra .= 'version >= ' . $dep['min'];
-
 
125
            }
120
            }
126
 
121
            if (isset($dep['max'])) {
127
            if (isset($dep['max'])) {
122
                if ($extra != ' (') {
128
                if ($extra != ' (') {
123
                    $extra .= ', ';
129
                    $extra .= ', ';
124
                }
130
                }
125
                $extra .= 'version <= ' . $dep['max'];
131
                $extra .= 'version <= ' . $dep['max'];
-
 
132
            }
126
            }
133
 
127
            if (isset($dep['exclude'])) {
134
            if (isset($dep['exclude'])) {
128
                if (!is_array($dep['exclude'])) {
135
                if (!is_array($dep['exclude'])) {
129
                    $dep['exclude'] = array($dep['exclude']);
136
                    $dep['exclude'] = array($dep['exclude']);
-
 
137
                }
130
                }
138
 
131
                if ($extra != ' (') {
139
                if ($extra != ' (') {
132
                    $extra .= ', ';
140
                    $extra .= ', ';
-
 
141
                }
133
                }
142
 
134
                $extra .= 'excluded versions: ';
143
                $extra .= 'excluded versions: ';
135
                foreach ($dep['exclude'] as $i => $exclude) {
144
                foreach ($dep['exclude'] as $i => $exclude) {
136
                    if ($i) {
145
                    if ($i) {
137
                        $extra .= ', ';
146
                        $extra .= ', ';
138
                    }
147
                    }
139
                    $extra .= $exclude;
148
                    $extra .= $exclude;
140
                }
149
                }
141
            }
150
            }
-
 
151
        }
142
        }
152
 
143
        $extra .= ')';
153
        $extra .= ')';
144
        if ($extra == ' ()') {
154
        if ($extra == ' ()') {
145
            $extra = '';
155
            $extra = '';
-
 
156
        }
146
        }
157
 
147
        return $extra;
158
        return $extra;
Line 148... Line 159...
148
    }
159
    }
149
 
160
 
Line 169... Line 180...
169
     * There are two generic OS dependencies that will be the most common, unix and windows.
180
     * There are two generic OS dependencies that will be the most common, unix and windows.
170
     * Other options are linux, freebsd, darwin (OS X), sunos, irix, hpux, aix
181
     * Other options are linux, freebsd, darwin (OS X), sunos, irix, hpux, aix
171
     */
182
     */
172
    function validateOsDependency($dep)
183
    function validateOsDependency($dep)
173
    {
184
    {
174
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
-
 
175
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
185
        if ($this->_state != PEAR_VALIDATE_INSTALLING && $this->_state != PEAR_VALIDATE_DOWNLOADING) {
176
            return true;
186
            return true;
177
        }
187
        }
178
        if (isset($dep['conflicts'])) {
-
 
179
            $not = true;
-
 
180
        } else {
-
 
181
            $not = false;
-
 
182
        }
188
 
183
        if ($dep['name'] == '*') {
189
        if ($dep['name'] == '*') {
184
            return true;
190
            return true;
185
        }
191
        }
-
 
192
 
-
 
193
        $not = isset($dep['conflicts']) ? true : false;
186
        switch (strtolower($dep['name'])) {
194
        switch (strtolower($dep['name'])) {
187
            case 'windows' :
195
            case 'windows' :
188
                if ($not) {
196
                if ($not) {
189
                    if (strtolower(substr($this->getPHP_OS(), 0, 3)) == 'win') {
197
                    if (strtolower(substr($this->getPHP_OS(), 0, 3)) == 'win') {
190
                        if (!isset($this->_options['nodeps']) &&
198
                        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
191
                              !isset($this->_options['force'])) {
-
 
192
                            return $this->raiseError("Cannot install %s on Windows");
199
                            return $this->raiseError("Cannot install %s on Windows");
193
                        } else {
-
 
194
                            return $this->warning("warning: Cannot install %s on Windows");
-
 
195
                        }
200
                        }
-
 
201
 
-
 
202
                        return $this->warning("warning: Cannot install %s on Windows");
196
                    }
203
                    }
197
                } else {
204
                } else {
198
                    if (strtolower(substr($this->getPHP_OS(), 0, 3)) != 'win') {
205
                    if (strtolower(substr($this->getPHP_OS(), 0, 3)) != 'win') {
199
                        if (!isset($this->_options['nodeps']) &&
206
                        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
200
                              !isset($this->_options['force'])) {
-
 
201
                            return $this->raiseError("Can only install %s on Windows");
207
                            return $this->raiseError("Can only install %s on Windows");
202
                        } else {
-
 
203
                            return $this->warning("warning: Can only install %s on Windows");
-
 
204
                        }
208
                        }
-
 
209
 
-
 
210
                        return $this->warning("warning: Can only install %s on Windows");
205
                    }
211
                    }
206
                }
212
                }
207
            break;
213
            break;
208
            case 'unix' :
214
            case 'unix' :
209
                $unices = array('linux', 'freebsd', 'darwin', 'sunos', 'irix', 'hpux', 'aix');
215
                $unices = array('linux', 'freebsd', 'darwin', 'sunos', 'irix', 'hpux', 'aix');
210
                if ($not) {
216
                if ($not) {
211
                    if (in_array($this->getSysname(), $unices)) {
217
                    if (in_array($this->getSysname(), $unices)) {
212
                        if (!isset($this->_options['nodeps']) &&
218
                        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
213
                              !isset($this->_options['force'])) {
-
 
214
                            return $this->raiseError("Cannot install %s on any Unix system");
219
                            return $this->raiseError("Cannot install %s on any Unix system");
215
                        } else {
-
 
216
                            return $this->warning(
-
 
217
                                "warning: Cannot install %s on any Unix system");
-
 
218
                        }
220
                        }
-
 
221
 
-
 
222
                        return $this->warning( "warning: Cannot install %s on any Unix system");
219
                    }
223
                    }
220
                } else {
224
                } else {
221
                    if (!in_array($this->getSysname(), $unices)) {
225
                    if (!in_array($this->getSysname(), $unices)) {
222
                        if (!isset($this->_options['nodeps']) &&
226
                        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
223
                              !isset($this->_options['force'])) {
-
 
224
                            return $this->raiseError("Can only install %s on a Unix system");
227
                            return $this->raiseError("Can only install %s on a Unix system");
225
                        } else {
-
 
226
                            return $this->warning(
-
 
227
                                "warning: Can only install %s on a Unix system");
-
 
228
                        }
228
                        }
-
 
229
 
-
 
230
                        return $this->warning("warning: Can only install %s on a Unix system");
229
                    }
231
                    }
230
                }
232
                }
231
            break;
233
            break;
232
            default :
234
            default :
233
                if ($not) {
235
                if ($not) {
234
                    if (strtolower($dep['name']) == strtolower($this->getSysname())) {
236
                    if (strtolower($dep['name']) == strtolower($this->getSysname())) {
235
                        if (!isset($this->_options['nodeps']) &&
237
                        if (!isset($this->_options['nodeps']) &&
236
                              !isset($this->_options['force'])) {
238
                              !isset($this->_options['force'])) {
237
                            return $this->raiseError('Cannot install %s on ' . $dep['name'] .
239
                            return $this->raiseError('Cannot install %s on ' . $dep['name'] .
238
                                ' operating system');
240
                                ' operating system');
239
                        } else {
-
 
240
                            return $this->warning('warning: Cannot install %s on ' .
-
 
241
                                $dep['name'] . ' operating system');
-
 
242
                        }
241
                        }
-
 
242
 
-
 
243
                        return $this->warning('warning: Cannot install %s on ' .
-
 
244
                            $dep['name'] . ' operating system');
243
                    }
245
                    }
244
                } else {
246
                } else {
245
                    if (strtolower($dep['name']) != strtolower($this->getSysname())) {
247
                    if (strtolower($dep['name']) != strtolower($this->getSysname())) {
246
                        if (!isset($this->_options['nodeps']) &&
248
                        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
247
                              !isset($this->_options['force'])) {
-
 
248
                            return $this->raiseError('Cannot install %s on ' .
249
                            return $this->raiseError('Cannot install %s on ' .
249
                                $this->getSysname() .
250
                                $this->getSysname() .
250
                                ' operating system, can only install on ' . $dep['name']);
251
                                ' operating system, can only install on ' . $dep['name']);
251
                        } else {
-
 
252
                            return $this->warning('warning: Cannot install %s on ' .
-
 
253
                                $this->getSysname() .
-
 
254
                                ' operating system, can only install on ' . $dep['name']);
-
 
255
                        }
252
                        }
-
 
253
 
-
 
254
                        return $this->warning('warning: Cannot install %s on ' .
-
 
255
                            $this->getSysname() .
-
 
256
                            ' operating system, can only install on ' . $dep['name']);
256
                    }
257
                    }
257
                }
258
                }
258
        }
259
        }
259
        return true;
260
        return true;
260
    }
261
    }
Line 277... Line 278...
277
    function validateArchDependency($dep)
278
    function validateArchDependency($dep)
278
    {
279
    {
279
        if ($this->_state != PEAR_VALIDATE_INSTALLING) {
280
        if ($this->_state != PEAR_VALIDATE_INSTALLING) {
280
            return true;
281
            return true;
281
        }
282
        }
-
 
283
 
282
        if (isset($dep['conflicts'])) {
284
        $not = isset($dep['conflicts']) ? true : false;
283
            $not = true;
-
 
284
        } else {
-
 
285
            $not = false;
-
 
286
        }
-
 
287
        if (!$this->matchSignature($dep['pattern'])) {
285
        if (!$this->matchSignature($dep['pattern'])) {
288
            if (!$not) {
286
            if (!$not) {
289
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
287
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
290
                    return $this->raiseError('%s Architecture dependency failed, does not ' .
288
                    return $this->raiseError('%s Architecture dependency failed, does not ' .
291
                        'match "' . $dep['pattern'] . '"');
289
                        'match "' . $dep['pattern'] . '"');
292
                } else {
-
 
293
                    return $this->warning('warning: %s Architecture dependency failed, does ' .
-
 
294
                        'not match "' . $dep['pattern'] . '"');
-
 
295
                }
290
                }
-
 
291
 
-
 
292
                return $this->warning('warning: %s Architecture dependency failed, does ' .
-
 
293
                    'not match "' . $dep['pattern'] . '"');
296
            }
294
            }
-
 
295
 
297
            return true;
296
            return true;
298
        } else {
297
        }
-
 
298
 
299
            if ($not) {
299
        if ($not) {
300
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
300
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
301
                    return $this->raiseError('%s Architecture dependency failed, required "' .
301
                return $this->raiseError('%s Architecture dependency failed, required "' .
302
                        $dep['pattern'] . '"');
302
                    $dep['pattern'] . '"');
303
                } else {
-
 
304
                    return $this->warning('warning: %s Architecture dependency failed, ' .
-
 
305
                        'required "' . $dep['pattern'] . '"');
-
 
306
                }
-
 
307
            }
303
            }
-
 
304
 
-
 
305
            return $this->warning('warning: %s Architecture dependency failed, ' .
308
            return true;
306
                'required "' . $dep['pattern'] . '"');
309
        }
307
        }
-
 
308
 
-
 
309
        return true;
310
    }
310
    }
Line 311... Line 311...
311
 
311
 
312
    /**
312
    /**
313
     * This makes unit-testing a heck of a lot easier
313
     * This makes unit-testing a heck of a lot easier
Line 322... Line 322...
322
     */
322
     */
323
    function phpversion($name = null)
323
    function phpversion($name = null)
324
    {
324
    {
325
        if ($name !== null) {
325
        if ($name !== null) {
326
            return phpversion($name);
326
            return phpversion($name);
327
        } else {
-
 
328
            return phpversion();
-
 
329
        }
327
        }
-
 
328
 
-
 
329
        return phpversion();
330
    }
330
    }
Line 331... Line 331...
331
 
331
 
332
    function validateExtensionDependency($dep, $required = true)
332
    function validateExtensionDependency($dep, $required = true)
333
    {
333
    {
334
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
334
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
335
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
335
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
336
            return true;
336
            return true;
-
 
337
        }
337
        }
338
 
338
        $loaded = $this->extension_loaded($dep['name']);
339
        $loaded = $this->extension_loaded($dep['name']);
339
        $extra = $this->_getExtraString($dep);
340
        $extra  = $this->_getExtraString($dep);
340
        if (isset($dep['exclude'])) {
341
        if (isset($dep['exclude'])) {
341
            if (!is_array($dep['exclude'])) {
342
            if (!is_array($dep['exclude'])) {
342
                $dep['exclude'] = array($dep['exclude']);
343
                $dep['exclude'] = array($dep['exclude']);
343
            }
344
            }
-
 
345
        }
344
        }
346
 
345
        if (!isset($dep['min']) && !isset($dep['max']) &&
347
        if (!isset($dep['min']) && !isset($dep['max']) &&
-
 
348
            !isset($dep['recommended']) && !isset($dep['exclude'])
346
              !isset($dep['recommended']) && !isset($dep['exclude'])) {
349
        ) {
347
            if ($loaded) {
350
            if ($loaded) {
348
                if (isset($dep['conflicts'])) {
351
                if (isset($dep['conflicts'])) {
349
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
352
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
350
                        return $this->raiseError('%s conflicts with PHP extension "' .
353
                        return $this->raiseError('%s conflicts with PHP extension "' .
351
                            $dep['name'] . '"' . $extra);
-
 
352
                    } else {
-
 
353
                        return $this->warning('warning: %s conflicts with PHP extension "' .
-
 
354
                            $dep['name'] . '"' . $extra);
354
                            $dep['name'] . '"' . $extra);
-
 
355
                    }
-
 
356
 
-
 
357
                    return $this->warning('warning: %s conflicts with PHP extension "' .
355
                    }
358
                        $dep['name'] . '"' . $extra);
-
 
359
                }
356
                }
360
 
357
                return true;
361
                return true;
-
 
362
            }
358
            } else {
363
 
359
                if (isset($dep['conflicts'])) {
364
            if (isset($dep['conflicts'])) {
360
                    return true;
365
                return true;
-
 
366
            }
361
                }
367
 
362
                if ($required) {
368
            if ($required) {
363
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
369
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
364
                        return $this->raiseError('%s requires PHP extension "' .
-
 
365
                            $dep['name'] . '"' . $extra);
-
 
366
                    } else {
-
 
367
                        return $this->warning('warning: %s requires PHP extension "' .
-
 
368
                            $dep['name'] . '"' . $extra);
-
 
369
                    }
-
 
370
                } else {
-
 
371
                    return $this->warning('%s can optionally use PHP extension "' .
370
                    return $this->raiseError('%s requires PHP extension "' .
372
                        $dep['name'] . '"' . $extra);
371
                        $dep['name'] . '"' . $extra);
-
 
372
                }
-
 
373
 
-
 
374
                return $this->warning('warning: %s requires PHP extension "' .
373
                }
375
                    $dep['name'] . '"' . $extra);
-
 
376
            }
-
 
377
 
-
 
378
            return $this->warning('%s can optionally use PHP extension "' .
374
            }
379
                $dep['name'] . '"' . $extra);
-
 
380
        }
375
        }
381
 
376
        if (!$loaded) {
382
        if (!$loaded) {
377
            if (isset($dep['conflicts'])) {
383
            if (isset($dep['conflicts'])) {
378
                return true;
384
                return true;
-
 
385
            }
379
            }
386
 
380
            if (!$required) {
387
            if (!$required) {
381
                return $this->warning('%s can optionally use PHP extension "' .
388
                return $this->warning('%s can optionally use PHP extension "' .
382
                    $dep['name'] . '"' . $extra);
-
 
383
            } else {
-
 
384
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
385
                    return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
-
 
386
                        '"' . $extra);
-
 
387
                }
-
 
388
                    return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
-
 
389
                        '"' . $extra);
389
                    $dep['name'] . '"' . $extra);
-
 
390
            }
-
 
391
 
-
 
392
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
393
                return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
-
 
394
                    '"' . $extra);
-
 
395
            }
-
 
396
 
-
 
397
            return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
390
            }
398
                    '"' . $extra);
-
 
399
        }
391
        }
400
 
392
        $version = (string) $this->phpversion($dep['name']);
401
        $version = (string) $this->phpversion($dep['name']);
393
        if (empty($version)) {
402
        if (empty($version)) {
394
            $version = '0';
403
            $version = '0';
-
 
404
        }
395
        }
405
 
396
        $fail = false;
-
 
397
        if (isset($dep['min'])) {
406
        $fail = false;
398
            if (!version_compare($version, $dep['min'], '>=')) {
407
        if (isset($dep['min']) && !version_compare($version, $dep['min'], '>=')) {
399
                $fail = true;
-
 
400
            }
408
            $fail = true;
401
        }
-
 
-
 
409
        }
402
        if (isset($dep['max'])) {
410
 
403
            if (!version_compare($version, $dep['max'], '<=')) {
411
        if (isset($dep['max']) && !version_compare($version, $dep['max'], '<=')) {
404
                $fail = true;
-
 
405
            }
412
            $fail = true;
-
 
413
        }
406
        }
414
 
407
        if ($fail && !isset($dep['conflicts'])) {
415
        if ($fail && !isset($dep['conflicts'])) {
408
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
416
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
409
                return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
417
                return $this->raiseError('%s requires PHP extension "' . $dep['name'] .
410
                    '"' . $extra . ', installed version is ' . $version);
-
 
411
            } else {
-
 
412
                return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
-
 
413
                    '"' . $extra . ', installed version is ' . $version);
418
                    '"' . $extra . ', installed version is ' . $version);
-
 
419
            }
-
 
420
 
-
 
421
            return $this->warning('warning: %s requires PHP extension "' . $dep['name'] .
414
            }
422
                '"' . $extra . ', installed version is ' . $version);
415
        } elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail && isset($dep['conflicts'])) {
423
        } elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail && isset($dep['conflicts'])) {
416
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
424
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
417
                return $this->raiseError('%s conflicts with PHP extension "' .
425
                return $this->raiseError('%s conflicts with PHP extension "' .
418
                    $dep['name'] . '"' . $extra . ', installed version is ' . $version);
-
 
419
            } else {
-
 
420
                return $this->warning('warning: %s conflicts with PHP extension "' .
-
 
421
                    $dep['name'] . '"' . $extra . ', installed version is ' . $version);
426
                    $dep['name'] . '"' . $extra . ', installed version is ' . $version);
-
 
427
            }
-
 
428
 
-
 
429
            return $this->warning('warning: %s conflicts with PHP extension "' .
422
            }
430
                $dep['name'] . '"' . $extra . ', installed version is ' . $version);
-
 
431
        }
423
        }
432
 
424
        if (isset($dep['exclude'])) {
433
        if (isset($dep['exclude'])) {
425
            foreach ($dep['exclude'] as $exclude) {
434
            foreach ($dep['exclude'] as $exclude) {
426
                if (version_compare($version, $exclude, '==')) {
435
                if (version_compare($version, $exclude, '==')) {
427
                    if (isset($dep['conflicts'])) {
436
                    if (isset($dep['conflicts'])) {
428
                        continue;
437
                        continue;
-
 
438
                    }
429
                    }
439
 
430
                    if (!isset($this->_options['nodeps']) &&
-
 
431
                          !isset($this->_options['force'])) {
440
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
432
                        return $this->raiseError('%s is not compatible with PHP extension "' .
441
                        return $this->raiseError('%s is not compatible with PHP extension "' .
433
                            $dep['name'] . '" version ' .
442
                            $dep['name'] . '" version ' .
434
                            $exclude);
-
 
435
                    } else {
-
 
436
                        return $this->warning('warning: %s is not compatible with PHP extension "' .
-
 
437
                            $dep['name'] . '" version ' .
-
 
438
                            $exclude);
443
                            $exclude);
-
 
444
                    }
-
 
445
 
-
 
446
                    return $this->warning('warning: %s is not compatible with PHP extension "' .
-
 
447
                        $dep['name'] . '" version ' .
439
                    }
448
                        $exclude);
440
                } elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
449
                } elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
441
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
450
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
442
                        return $this->raiseError('%s conflicts with PHP extension "' .
451
                        return $this->raiseError('%s conflicts with PHP extension "' .
443
                            $dep['name'] . '"' . $extra . ', installed version is ' . $version);
-
 
444
                    } else {
-
 
445
                        return $this->warning('warning: %s conflicts with PHP extension "' .
-
 
446
                            $dep['name'] . '"' . $extra . ', installed version is ' . $version);
452
                            $dep['name'] . '"' . $extra . ', installed version is ' . $version);
-
 
453
                    }
-
 
454
 
-
 
455
                    return $this->warning('warning: %s conflicts with PHP extension "' .
447
                    }
456
                        $dep['name'] . '"' . $extra . ', installed version is ' . $version);
448
                }
457
                }
449
            }
458
            }
-
 
459
        }
450
        }
460
 
451
        if (isset($dep['recommended'])) {
461
        if (isset($dep['recommended'])) {
452
            if (version_compare($version, $dep['recommended'], '==')) {
462
            if (version_compare($version, $dep['recommended'], '==')) {
453
                return true;
-
 
454
            } else {
-
 
455
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
456
                    return $this->raiseError('%s dependency: PHP extension ' . $dep['name'] .
-
 
457
                        ' version "' . $version . '"' .
-
 
458
                        ' is not the recommended version "' . $dep['recommended'] .
-
 
459
                        '", but may be compatible, use --force to install');
-
 
460
                } else {
-
 
461
                    return $this->warning('warning: %s dependency: PHP extension ' .
-
 
462
                        $dep['name'] . ' version "' . $version . '"' .
-
 
463
                        ' is not the recommended version "' . $dep['recommended'].'"');
-
 
464
                }
463
                return true;
-
 
464
            }
-
 
465
 
-
 
466
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
467
                return $this->raiseError('%s dependency: PHP extension ' . $dep['name'] .
-
 
468
                    ' version "' . $version . '"' .
-
 
469
                    ' is not the recommended version "' . $dep['recommended'] .
-
 
470
                    '", but may be compatible, use --force to install');
-
 
471
            }
-
 
472
 
-
 
473
            return $this->warning('warning: %s dependency: PHP extension ' .
-
 
474
                $dep['name'] . ' version "' . $version . '"' .
465
            }
475
                ' is not the recommended version "' . $dep['recommended'].'"');
-
 
476
        }
466
        }
477
 
467
        return true;
478
        return true;
Line 468... Line 479...
468
    }
479
    }
469
 
480
 
470
    function validatePhpDependency($dep)
481
    function validatePhpDependency($dep)
471
    {
482
    {
472
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
483
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
473
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
484
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
-
 
485
            return true;
474
            return true;
486
        }
475
        }
487
 
476
        $version = $this->phpversion();
488
        $version = $this->phpversion();
477
        $extra = $this->_getExtraString($dep);
489
        $extra   = $this->_getExtraString($dep);
478
        if (isset($dep['exclude'])) {
490
        if (isset($dep['exclude'])) {
479
            if (!is_array($dep['exclude'])) {
491
            if (!is_array($dep['exclude'])) {
480
                $dep['exclude'] = array($dep['exclude']);
492
                $dep['exclude'] = array($dep['exclude']);
-
 
493
            }
481
            }
494
        }
482
        }
495
 
483
        if (isset($dep['min'])) {
496
        if (isset($dep['min'])) {
484
            if (!version_compare($version, $dep['min'], '>=')) {
497
            if (!version_compare($version, $dep['min'], '>=')) {
485
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
498
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
486
                    return $this->raiseError('%s requires PHP' .
-
 
487
                        $extra . ', installed version is ' . $version);
-
 
488
                } else {
-
 
489
                    return $this->warning('warning: %s requires PHP' .
499
                    return $this->raiseError('%s requires PHP' .
-
 
500
                        $extra . ', installed version is ' . $version);
-
 
501
                }
-
 
502
 
490
                        $extra . ', installed version is ' . $version);
503
                return $this->warning('warning: %s requires PHP' .
491
                }
504
                    $extra . ', installed version is ' . $version);
-
 
505
            }
492
            }
506
        }
493
        }
507
 
494
        if (isset($dep['max'])) {
508
        if (isset($dep['max'])) {
495
            if (!version_compare($version, $dep['max'], '<=')) {
509
            if (!version_compare($version, $dep['max'], '<=')) {
496
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
510
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
497
                    return $this->raiseError('%s requires PHP' .
-
 
498
                        $extra . ', installed version is ' . $version);
-
 
499
                } else {
-
 
500
                    return $this->warning('warning: %s requires PHP' .
511
                    return $this->raiseError('%s requires PHP' .
-
 
512
                        $extra . ', installed version is ' . $version);
-
 
513
                }
-
 
514
 
501
                        $extra . ', installed version is ' . $version);
515
                return $this->warning('warning: %s requires PHP' .
502
                }
516
                    $extra . ', installed version is ' . $version);
-
 
517
            }
503
            }
518
        }
504
        }
519
 
505
        if (isset($dep['exclude'])) {
520
        if (isset($dep['exclude'])) {
506
            foreach ($dep['exclude'] as $exclude) {
521
            foreach ($dep['exclude'] as $exclude) {
507
                if (version_compare($version, $exclude, '==')) {
-
 
508
                    if (!isset($this->_options['nodeps']) &&
522
                if (version_compare($version, $exclude, '==')) {
509
                          !isset($this->_options['force'])) {
523
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
510
                        return $this->raiseError('%s is not compatible with PHP version ' .
-
 
511
                            $exclude);
-
 
512
                    } else {
-
 
513
                        return $this->warning(
-
 
514
                            'warning: %s is not compatible with PHP version ' .
524
                        return $this->raiseError('%s is not compatible with PHP version ' .
-
 
525
                            $exclude);
-
 
526
                    }
-
 
527
 
-
 
528
                    return $this->warning(
515
                            $exclude);
529
                        'warning: %s is not compatible with PHP version ' .
516
                    }
530
                        $exclude);
517
                }
531
                }
-
 
532
            }
518
            }
533
        }
519
        }
534
 
Line 520... Line 535...
520
        return true;
535
        return true;
521
    }
536
    }
522
 
537
 
523
    /**
538
    /**
524
     * This makes unit-testing a heck of a lot easier
539
     * This makes unit-testing a heck of a lot easier
525
     */
540
     */
526
    function getPEARVersion()
541
    function getPEARVersion()
Line 527... Line 542...
527
    {
542
    {
528
        return '1.5.1';
543
        return '1.10.1';
529
    }
544
    }
Line 535... Line 550...
535
        if (isset($dep['exclude'])) {
550
        if (isset($dep['exclude'])) {
536
            if (!is_array($dep['exclude'])) {
551
            if (!is_array($dep['exclude'])) {
537
                $dep['exclude'] = array($dep['exclude']);
552
                $dep['exclude'] = array($dep['exclude']);
538
            }
553
            }
539
        }
554
        }
-
 
555
 
540
        if (version_compare($pearversion, $dep['min'], '<')) {
556
        if (version_compare($pearversion, $dep['min'], '<')) {
541
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
557
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
542
                return $this->raiseError('%s requires PEAR Installer' . $extra .
558
                return $this->raiseError('%s requires PEAR Installer' . $extra .
543
                    ', installed version is ' . $pearversion);
559
                    ', installed version is ' . $pearversion);
544
            } else {
-
 
545
                return $this->warning('warning: %s requires PEAR Installer' . $extra .
-
 
546
                    ', installed version is ' . $pearversion);
-
 
547
            }
560
            }
-
 
561
 
-
 
562
            return $this->warning('warning: %s requires PEAR Installer' . $extra .
-
 
563
                ', installed version is ' . $pearversion);
548
        }
564
        }
-
 
565
 
549
        if (isset($dep['max'])) {
566
        if (isset($dep['max'])) {
550
            if (version_compare($pearversion, $dep['max'], '>')) {
567
            if (version_compare($pearversion, $dep['max'], '>')) {
551
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
568
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
552
                    return $this->raiseError('%s requires PEAR Installer' . $extra .
569
                    return $this->raiseError('%s requires PEAR Installer' . $extra .
553
                        ', installed version is ' . $pearversion);
570
                        ', installed version is ' . $pearversion);
554
                } else {
-
 
555
                    return $this->warning('warning: %s requires PEAR Installer' . $extra .
-
 
556
                        ', installed version is ' . $pearversion);
-
 
557
                }
571
                }
-
 
572
 
-
 
573
                return $this->warning('warning: %s requires PEAR Installer' . $extra .
-
 
574
                    ', installed version is ' . $pearversion);
558
            }
575
            }
559
        }
576
        }
-
 
577
 
560
        if (isset($dep['exclude'])) {
578
        if (isset($dep['exclude'])) {
561
            if (!isset($dep['exclude'][0])) {
579
            if (!isset($dep['exclude'][0])) {
562
                $dep['exclude'] = array($dep['exclude']);
580
                $dep['exclude'] = array($dep['exclude']);
563
            }
581
            }
-
 
582
 
564
            foreach ($dep['exclude'] as $exclude) {
583
            foreach ($dep['exclude'] as $exclude) {
565
                if (version_compare($exclude, $pearversion, '==')) {
584
                if (version_compare($exclude, $pearversion, '==')) {
566
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
585
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
567
                        return $this->raiseError('%s is not compatible with PEAR Installer ' .
586
                        return $this->raiseError('%s is not compatible with PEAR Installer ' .
568
                            'version ' . $exclude);
587
                            'version ' . $exclude);
569
                    } else {
-
 
570
                        return $this->warning('warning: %s is not compatible with PEAR ' .
-
 
571
                            'Installer version ' . $exclude);
-
 
572
                    }
588
                    }
-
 
589
 
-
 
590
                    return $this->warning('warning: %s is not compatible with PEAR ' .
-
 
591
                        'Installer version ' . $exclude);
573
                }
592
                }
574
            }
593
            }
575
        }
594
        }
-
 
595
 
576
        return true;
596
        return true;
577
    }
597
    }
Line 578... Line 598...
578
 
598
 
579
    function validateSubpackageDependency($dep, $required, $params)
599
    function validateSubpackageDependency($dep, $required, $params)
Line 584... Line 604...
584
    /**
604
    /**
585
     * @param array dependency information (2.0 format)
605
     * @param array dependency information (2.0 format)
586
     * @param boolean whether this is a required dependency
606
     * @param boolean whether this is a required dependency
587
     * @param array a list of downloaded packages to be installed, if any
607
     * @param array a list of downloaded packages to be installed, if any
588
     * @param boolean if true, then deps on pear.php.net that fail will also check
608
     * @param boolean if true, then deps on pear.php.net that fail will also check
589
     *                against pecl.php.net packages to accomodate extensions that have
609
     *                against pecl.php.net packages to accommodate extensions that have
590
     *                moved to pecl.php.net from pear.php.net
610
     *                moved to pecl.php.net from pear.php.net
591
     */
611
     */
592
    function validatePackageDependency($dep, $required, $params, $depv1 = false)
612
    function validatePackageDependency($dep, $required, $params, $depv1 = false)
593
    {
613
    {
594
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
614
        if ($this->_state != PEAR_VALIDATE_INSTALLING &&
595
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
615
              $this->_state != PEAR_VALIDATE_DOWNLOADING) {
596
            return true;
616
            return true;
597
        }
617
        }
-
 
618
 
598
        if (isset($dep['providesextension'])) {
619
        if (isset($dep['providesextension'])) {
599
            if ($this->extension_loaded($dep['providesextension'])) {
620
            if ($this->extension_loaded($dep['providesextension'])) {
600
                $save = $dep;
621
                $save = $dep;
601
                $subdep = $dep;
622
                $subdep = $dep;
602
                $subdep['name'] = $subdep['providesextension'];
623
                $subdep['name'] = $subdep['providesextension'];
Line 606... Line 627...
606
                if (!PEAR::isError($ret)) {
627
                if (!PEAR::isError($ret)) {
607
                    return true;
628
                    return true;
608
                }
629
                }
609
            }
630
            }
610
        }
631
        }
-
 
632
 
611
        if ($this->_state == PEAR_VALIDATE_INSTALLING) {
633
        if ($this->_state == PEAR_VALIDATE_INSTALLING) {
612
            return $this->_validatePackageInstall($dep, $required, $depv1);
634
            return $this->_validatePackageInstall($dep, $required, $depv1);
613
        }
635
        }
-
 
636
 
614
        if ($this->_state == PEAR_VALIDATE_DOWNLOADING) {
637
        if ($this->_state == PEAR_VALIDATE_DOWNLOADING) {
615
            return $this->_validatePackageDownload($dep, $required, $params, $depv1);
638
            return $this->_validatePackageDownload($dep, $required, $params, $depv1);
616
        }
639
        }
617
    }
640
    }
Line 620... Line 643...
620
    {
643
    {
621
        $dep['package'] = $dep['name'];
644
        $dep['package'] = $dep['name'];
622
        if (isset($dep['uri'])) {
645
        if (isset($dep['uri'])) {
623
            $dep['channel'] = '__uri';
646
            $dep['channel'] = '__uri';
624
        }
647
        }
-
 
648
 
625
        $depname = $this->_registry->parsedPackageNameToString($dep, true);
649
        $depname = $this->_registry->parsedPackageNameToString($dep, true);
626
        $found = false;
650
        $found = false;
627
        foreach ($params as $param) {
651
        foreach ($params as $param) {
628
            if ($param->isEqual(
652
            if ($param->isEqual(
629
                  array('package' => $dep['name'],
653
                  array('package' => $dep['name'],
630
                        'channel' => $dep['channel']))) {
654
                        'channel' => $dep['channel']))) {
631
                $found = true;
655
                $found = true;
632
                break;
656
                break;
633
            }
657
            }
-
 
658
 
634
            if ($depv1 && $dep['channel'] == 'pear.php.net') {
659
            if ($depv1 && $dep['channel'] == 'pear.php.net') {
635
                if ($param->isEqual(
660
                if ($param->isEqual(
636
                  array('package' => $dep['name'],
661
                  array('package' => $dep['name'],
637
                        'channel' => 'pecl.php.net'))) {
662
                        'channel' => 'pecl.php.net'))) {
638
                    $found = true;
663
                    $found = true;
639
                    break;
664
                    break;
640
                }
665
                }
641
            }
666
            }
642
        }
667
        }
-
 
668
 
643
        if (!$found && isset($dep['providesextension'])) {
669
        if (!$found && isset($dep['providesextension'])) {
644
            foreach ($params as $param) {
670
            foreach ($params as $param) {
645
                if ($param->isExtension($dep['providesextension'])) {
671
                if ($param->isExtension($dep['providesextension'])) {
646
                    $found = true;
672
                    $found = true;
647
                    break;
673
                    break;
648
                }
674
                }
649
            }
675
            }
650
        }
676
        }
-
 
677
 
651
        if ($found) {
678
        if ($found) {
652
            $version = $param->getVersion();
679
            $version = $param->getVersion();
653
            $installed = false;
680
            $installed = false;
654
            $downloaded = true;
681
            $downloaded = true;
655
        } else {
682
        } else {
Line 670... Line 697...
670
                    $installed = false;
697
                    $installed = false;
671
                    $downloaded = false;
698
                    $downloaded = false;
672
                }
699
                }
673
            }
700
            }
674
        }
701
        }
-
 
702
 
675
        $extra = $this->_getExtraString($dep);
703
        $extra = $this->_getExtraString($dep);
676
        if (isset($dep['exclude'])) {
-
 
677
            if (!is_array($dep['exclude'])) {
704
        if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
678
                $dep['exclude'] = array($dep['exclude']);
705
            $dep['exclude'] = array($dep['exclude']);
679
            }
-
 
680
        }
706
        }
-
 
707
 
681
        if (!isset($dep['min']) && !isset($dep['max']) &&
708
        if (!isset($dep['min']) && !isset($dep['max']) &&
682
              !isset($dep['recommended']) && !isset($dep['exclude'])) {
709
              !isset($dep['recommended']) && !isset($dep['exclude'])
-
 
710
        ) {
683
            if ($installed || $downloaded) {
711
            if ($installed || $downloaded) {
684
                $installed = $installed ? 'installed' : 'downloaded';
712
                $installed = $installed ? 'installed' : 'downloaded';
685
                if (isset($dep['conflicts'])) {
713
                if (isset($dep['conflicts'])) {
-
 
714
                    $rest = '';
686
                    if ($version) {
715
                    if ($version) {
687
                        $rest = ", $installed version is " . $version;
716
                        $rest = ", $installed version is " . $version;
688
                    } else {
-
 
689
                        $rest = '';
-
 
690
                    }
717
                    }
-
 
718
 
691
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
719
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
692
                        return $this->raiseError('%s conflicts with package "' . $depname . '"' .
720
                        return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra . $rest);
693
                            $extra . $rest);
-
 
694
                    } else {
-
 
695
                        return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
-
 
696
                            $extra . $rest);
-
 
697
                    }
721
                    }
-
 
722
 
-
 
723
                    return $this->warning('warning: %s conflicts with package "' . $depname . '"' . $extra . $rest);
698
                }
724
                }
-
 
725
 
699
                return true;
726
                return true;
700
            } else {
727
            }
-
 
728
 
701
                if (isset($dep['conflicts'])) {
729
            if (isset($dep['conflicts'])) {
702
                    return true;
730
                return true;
703
                }
731
            }
-
 
732
 
704
                if ($required) {
733
            if ($required) {
705
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
734
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
706
                        return $this->raiseError('%s requires package "' . $depname . '"' .
735
                    return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
707
                            $extra);
-
 
708
                    } else {
-
 
709
                        return $this->warning('warning: %s requires package "' . $depname . '"' .
-
 
710
                            $extra);
-
 
711
                    }
-
 
712
                } else {
-
 
713
                    return $this->warning('%s can optionally use package "' . $depname . '"' .
-
 
714
                        $extra);
-
 
715
                }
736
                }
-
 
737
 
-
 
738
                return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
716
            }
739
            }
-
 
740
 
-
 
741
            return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
717
        }
742
        }
-
 
743
 
718
        if (!$installed && !$downloaded) {
744
        if (!$installed && !$downloaded) {
719
            if (isset($dep['conflicts'])) {
745
            if (isset($dep['conflicts'])) {
720
                return true;
746
                return true;
721
            }
747
            }
-
 
748
 
722
            if ($required) {
749
            if ($required) {
723
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
750
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
724
                    return $this->raiseError('%s requires package "' . $depname . '"' .
751
                    return $this->raiseError('%s requires package "' . $depname . '"' . $extra);
725
                        $extra);
-
 
726
                } else {
-
 
727
                    return $this->warning('warning: %s requires package "' . $depname . '"' .
-
 
728
                        $extra);
-
 
729
                }
752
                }
730
            } else {
-
 
-
 
753
 
731
                return $this->warning('%s can optionally use package "' . $depname . '"' .
754
                return $this->warning('warning: %s requires package "' . $depname . '"' . $extra);
732
                    $extra);
-
 
733
            }
755
            }
-
 
756
 
-
 
757
            return $this->warning('%s can optionally use package "' . $depname . '"' . $extra);
734
        }
758
        }
-
 
759
 
735
        $fail = false;
760
        $fail = false;
736
        if (isset($dep['min'])) {
-
 
737
            if (version_compare($version, $dep['min'], '<')) {
761
        if (isset($dep['min']) && version_compare($version, $dep['min'], '<')) {
738
                $fail = true;
762
            $fail = true;
739
            }
-
 
740
        }
763
        }
741
        if (isset($dep['max'])) {
-
 
-
 
764
 
742
            if (version_compare($version, $dep['max'], '>')) {
765
        if (isset($dep['max']) && version_compare($version, $dep['max'], '>')) {
743
                $fail = true;
766
            $fail = true;
744
            }
-
 
745
        }
767
        }
-
 
768
 
746
        if ($fail && !isset($dep['conflicts'])) {
769
        if ($fail && !isset($dep['conflicts'])) {
747
            $installed = $installed ? 'installed' : 'downloaded';
770
            $installed = $installed ? 'installed' : 'downloaded';
748
            $dep['package'] = $dep['name'];
771
            $dep['package'] = $dep['name'];
749
            $dep = $this->_registry->parsedPackageNameToString($dep, true);
772
            $dep = $this->_registry->parsedPackageNameToString($dep, true);
750
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
773
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
751
                return $this->raiseError('%s requires package "' . $depname . '"' .
774
                return $this->raiseError('%s requires package "' . $depname . '"' .
752
                    $extra . ", $installed version is " . $version);
775
                    $extra . ", $installed version is " . $version);
753
            } else {
-
 
754
                return $this->warning('warning: %s requires package "' . $depname . '"' .
-
 
755
                    $extra . ", $installed version is " . $version);
-
 
756
            }
776
            }
-
 
777
 
-
 
778
            return $this->warning('warning: %s requires package "' . $depname . '"' .
-
 
779
                $extra . ", $installed version is " . $version);
757
        } elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail &&
780
        } elseif ((isset($dep['min']) || isset($dep['max'])) && !$fail &&
758
              isset($dep['conflicts']) && !isset($dep['exclude'])) {
781
              isset($dep['conflicts']) && !isset($dep['exclude'])) {
759
            $installed = $installed ? 'installed' : 'downloaded';
782
            $installed = $installed ? 'installed' : 'downloaded';
760
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
783
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
761
                return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra .
784
                return $this->raiseError('%s conflicts with package "' . $depname . '"' . $extra .
762
                    ", $installed version is " . $version);
785
                    ", $installed version is " . $version);
763
            } else {
-
 
764
                return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
-
 
765
                    $extra . ", $installed version is " . $version);
-
 
766
            }
786
            }
-
 
787
 
-
 
788
            return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
-
 
789
                $extra . ", $installed version is " . $version);
767
        }
790
        }
-
 
791
 
768
        if (isset($dep['exclude'])) {
792
        if (isset($dep['exclude'])) {
769
            $installed = $installed ? 'installed' : 'downloaded';
793
            $installed = $installed ? 'installed' : 'downloaded';
770
            foreach ($dep['exclude'] as $exclude) {
794
            foreach ($dep['exclude'] as $exclude) {
771
                if (version_compare($version, $exclude, '==') && !isset($dep['conflicts'])) {
795
                if (version_compare($version, $exclude, '==') && !isset($dep['conflicts'])) {
772
                    if (!isset($this->_options['nodeps']) &&
796
                    if (!isset($this->_options['nodeps']) &&
773
                          !isset($this->_options['force'])) {
797
                          !isset($this->_options['force'])
-
 
798
                    ) {
774
                        return $this->raiseError('%s is not compatible with ' .
799
                        return $this->raiseError('%s is not compatible with ' .
775
                            $installed . ' package "' .
800
                            $installed . ' package "' .
776
                            $depname . '" version ' .
801
                            $depname . '" version ' .
777
                            $exclude);
802
                            $exclude);
778
                    } else {
-
 
779
                        return $this->warning('warning: %s is not compatible with ' .
-
 
780
                            $installed . ' package "' .
-
 
781
                            $depname . '" version ' .
-
 
782
                            $exclude);
-
 
783
                    }
803
                    }
-
 
804
 
-
 
805
                    return $this->warning('warning: %s is not compatible with ' .
-
 
806
                        $installed . ' package "' .
-
 
807
                        $depname . '" version ' .
-
 
808
                        $exclude);
784
                } elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
809
                } elseif (version_compare($version, $exclude, '!=') && isset($dep['conflicts'])) {
785
                    $installed = $installed ? 'installed' : 'downloaded';
810
                    $installed = $installed ? 'installed' : 'downloaded';
786
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
811
                    if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
787
                        return $this->raiseError('%s conflicts with package "' . $depname . '"' .
812
                        return $this->raiseError('%s conflicts with package "' . $depname . '"' .
788
                            $extra . ", $installed version is " . $version);
813
                            $extra . ", $installed version is " . $version);
789
                    } else {
-
 
790
                        return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
-
 
791
                            $extra . ", $installed version is " . $version);
-
 
792
                    }
814
                    }
-
 
815
 
-
 
816
                    return $this->warning('warning: %s conflicts with package "' . $depname . '"' .
-
 
817
                        $extra . ", $installed version is " . $version);
793
                }
818
                }
794
            }
819
            }
795
        }
820
        }
-
 
821
 
796
        if (isset($dep['recommended'])) {
822
        if (isset($dep['recommended'])) {
797
            $installed = $installed ? 'installed' : 'downloaded';
823
            $installed = $installed ? 'installed' : 'downloaded';
798
            if (version_compare($version, $dep['recommended'], '==')) {
824
            if (version_compare($version, $dep['recommended'], '==')) {
799
                return true;
825
                return true;
800
            } else {
826
            }
-
 
827
 
801
                if (!$found && $installed) {
828
            if (!$found && $installed) {
802
                    $param = $this->_registry->getPackage($dep['name'], $dep['channel']);
829
                $param = $this->_registry->getPackage($dep['name'], $dep['channel']);
-
 
830
            }
-
 
831
 
-
 
832
            if ($param) {
-
 
833
                $found = false;
-
 
834
                foreach ($params as $parent) {
-
 
835
                    if ($parent->isEqual($this->_currentPackage)) {
-
 
836
                        $found = true;
-
 
837
                        break;
-
 
838
                    }
803
                }
839
                }
-
 
840
 
804
                if ($param) {
841
                if ($found) {
805
                    $found = false;
-
 
806
                    foreach ($params as $parent) {
842
                    if ($param->isCompatible($parent)) {
807
                        if ($parent->isEqual($this->_currentPackage)) {
-
 
808
                            $found = true;
843
                        return true;
809
                            break;
-
 
810
                        }
-
 
811
                    }
844
                    }
812
                    if ($found) {
-
 
813
                        if ($param->isCompatible($parent)) {
-
 
814
                            return true;
-
 
815
                        }
-
 
816
                    } else { // this is for validPackage() calls
845
                } else { // this is for validPackage() calls
817
                        $parent = $this->_registry->getPackage($this->_currentPackage['package'],
846
                    $parent = $this->_registry->getPackage($this->_currentPackage['package'],
818
                            $this->_currentPackage['channel']);
847
                        $this->_currentPackage['channel']);
819
                        if ($parent !== null) {
-
 
820
                            if ($param->isCompatible($parent)) {
848
                    if ($parent !== null && $param->isCompatible($parent)) {
821
                                return true;
849
                        return true;
822
                            }
-
 
823
                        }
-
 
824
                    }
850
                    }
825
                }
851
                }
826
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force']) &&
-
 
827
                      !isset($this->_options['loose'])) {
-
 
828
                    return $this->raiseError('%s dependency package "' . $depname .
-
 
829
                        '" ' . $installed . ' version ' . $version . 
-
 
830
                        ' is not the recommended version ' . $dep['recommended'] .
-
 
831
                        ', but may be compatible, use --force to install');
-
 
832
                } else {
-
 
833
                    return $this->warning('warning: %s dependency package "' . $depname .
-
 
834
                        '" ' . $installed . ' version ' . $version .
-
 
835
                        ' is not the recommended version ' . $dep['recommended']);
-
 
836
                }
-
 
837
            }
852
            }
-
 
853
 
-
 
854
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force']) &&
-
 
855
                  !isset($this->_options['loose'])
-
 
856
            ) {
-
 
857
                return $this->raiseError('%s dependency package "' . $depname .
-
 
858
                    '" ' . $installed . ' version ' . $version .
-
 
859
                    ' is not the recommended version ' . $dep['recommended'] .
-
 
860
                    ', but may be compatible, use --force to install');
-
 
861
            }
-
 
862
 
-
 
863
            return $this->warning('warning: %s dependency package "' . $depname .
-
 
864
                '" ' . $installed . ' version ' . $version .
-
 
865
                ' is not the recommended version ' . $dep['recommended']);
838
        }
866
        }
-
 
867
 
839
        return true;
868
        return true;
840
    }
869
    }
Line 841... Line 870...
841
 
870
 
842
    function _validatePackageInstall($dep, $required, $depv1 = false)
871
    function _validatePackageInstall($dep, $required, $depv1 = false)
Line 853... Line 882...
853
    function validatePackageUninstall(&$dl)
882
    function validatePackageUninstall(&$dl)
854
    {
883
    {
855
        if (PEAR::isError($this->_dependencydb)) {
884
        if (PEAR::isError($this->_dependencydb)) {
856
            return $this->_dependencydb;
885
            return $this->_dependencydb;
857
        }
886
        }
-
 
887
 
858
        $params = array();
888
        $params = array();
859
        // construct an array of "downloaded" packages to fool the package dependency checker
889
        // construct an array of "downloaded" packages to fool the package dependency checker
860
        // into using these to validate uninstalls of circular dependencies
890
        // into using these to validate uninstalls of circular dependencies
861
        $downloaded = &$dl->getUninstallPackages();
891
        $downloaded = &$dl->getUninstallPackages();
862
        foreach ($downloaded as $i => $pf) {
892
        foreach ($downloaded as $i => $pf) {
863
            if (!class_exists('PEAR_Downloader_Package')) {
893
            if (!class_exists('PEAR_Downloader_Package')) {
864
                require_once 'PEAR/Downloader/Package.php';
894
                require_once 'PEAR/Downloader/Package.php';
865
            }
895
            }
866
            $dp = &new PEAR_Downloader_Package($dl);
896
            $dp = new PEAR_Downloader_Package($dl);
867
            $dp->setPackageFile($downloaded[$i]);
897
            $dp->setPackageFile($downloaded[$i]);
868
            $params[$i] = &$dp;
898
            $params[$i] = $dp;
869
        }
899
        }
-
 
900
 
870
        // check cache
901
        // check cache
871
        $memyselfandI = strtolower($this->_currentPackage['channel']) . '/' .
902
        $memyselfandI = strtolower($this->_currentPackage['channel']) . '/' .
872
            strtolower($this->_currentPackage['package']);
903
            strtolower($this->_currentPackage['package']);
873
        if (isset($dl->___uninstall_package_cache)) {
904
        if (isset($dl->___uninstall_package_cache)) {
874
            $badpackages = $dl->___uninstall_package_cache;
905
            $badpackages = $dl->___uninstall_package_cache;
875
            if (isset($badpackages[$memyselfandI]['warnings'])) {
906
            if (isset($badpackages[$memyselfandI]['warnings'])) {
876
                foreach ($badpackages[$memyselfandI]['warnings'] as $warning) {
907
                foreach ($badpackages[$memyselfandI]['warnings'] as $warning) {
877
                    $dl->log(0, $warning[0]);
908
                    $dl->log(0, $warning[0]);
878
                }
909
                }
879
            }
910
            }
-
 
911
 
880
            if (isset($badpackages[$memyselfandI]['errors'])) {
912
            if (isset($badpackages[$memyselfandI]['errors'])) {
881
                foreach ($badpackages[$memyselfandI]['errors'] as $error) {
913
                foreach ($badpackages[$memyselfandI]['errors'] as $error) {
-
 
914
                    if (is_array($error)) {
-
 
915
                        $dl->log(0, $error[0]);
-
 
916
                    } else {
882
                    $dl->log(0, $error->getMessage());
917
                        $dl->log(0, $error->getMessage());
-
 
918
                    }
883
                }
919
                }
-
 
920
 
884
                if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
921
                if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
885
                    return $this->warning(
922
                    return $this->warning(
886
                        'warning: %s should not be uninstalled, other installed packages depend ' .
923
                        'warning: %s should not be uninstalled, other installed packages depend ' .
887
                        'on this package');
924
                        'on this package');
888
                } else {
-
 
889
                    return $this->raiseError(
-
 
890
                        '%s cannot be uninstalled, other installed packages depend on this package');
-
 
891
                }
925
                }
-
 
926
 
-
 
927
                return $this->raiseError(
-
 
928
                    '%s cannot be uninstalled, other installed packages depend on this package');
892
            }
929
            }
-
 
930
 
893
            return true;
931
            return true;
894
        }
932
        }
-
 
933
 
895
        // first, list the immediate parents of each package to be uninstalled
934
        // first, list the immediate parents of each package to be uninstalled
896
        $perpackagelist = array();
935
        $perpackagelist = array();
897
        $allparents = array();
936
        $allparents = array();
898
        foreach ($params as $i => $param) {
937
        foreach ($params as $i => $param) {
-
 
938
            $a = array(
899
            $a = array('channel' => strtolower($param->getChannel()),
939
                'channel' => strtolower($param->getChannel()),
900
                      'package' => strtolower($param->getPackage()));
940
                'package' => strtolower($param->getPackage())
-
 
941
            );
-
 
942
 
901
            $deps = $this->_dependencydb->getDependentPackages($a);
943
            $deps = $this->_dependencydb->getDependentPackages($a);
902
            if ($deps) {
944
            if ($deps) {
903
                foreach ($deps as $d) {
945
                foreach ($deps as $d) {
904
                    $pardeps = $this->_dependencydb->getDependencies($d);
946
                    $pardeps = $this->_dependencydb->getDependencies($d);
905
                    foreach ($pardeps as $dep) {
947
                    foreach ($pardeps as $dep) {
Line 922... Line 964...
922
                        }
964
                        }
923
                    }
965
                    }
924
                }
966
                }
925
            }
967
            }
926
        }
968
        }
-
 
969
 
927
        // next, remove any packages from the parents list that are not installed
970
        // next, remove any packages from the parents list that are not installed
928
        $remove = array();
971
        $remove = array();
929
        foreach ($allparents as $parent => $d1) {
972
        foreach ($allparents as $parent => $d1) {
930
            foreach ($d1 as $d) {
973
            foreach ($d1 as $d) {
931
                if ($this->_registry->packageExists($d[0][0]['package'], $d[0][0]['channel'])) {
974
                if ($this->_registry->packageExists($d[0][0]['package'], $d[0][0]['channel'])) {
932
                    continue;
975
                    continue;
933
                }
976
                }
934
                $remove[$parent] = true;
977
                $remove[$parent] = true;
935
            }
978
            }
936
        }
979
        }
-
 
980
 
937
        // next remove any packages from the parents list that are not passed in for
981
        // next remove any packages from the parents list that are not passed in for
938
        // uninstallation
982
        // uninstallation
939
        foreach ($allparents as $parent => $d1) {
983
        foreach ($allparents as $parent => $d1) {
940
            foreach ($d1 as $d) {
984
            foreach ($d1 as $d) {
941
                foreach ($params as $param) {
985
                foreach ($params as $param) {
Line 946... Line 990...
946
                    }
990
                    }
947
                }
991
                }
948
                $remove[$parent] = true;
992
                $remove[$parent] = true;
949
            }
993
            }
950
        }
994
        }
-
 
995
 
951
        // remove all packages whose dependencies fail
996
        // remove all packages whose dependencies fail
952
        // save which ones failed for error reporting
997
        // save which ones failed for error reporting
953
        $badchildren = array();
998
        $badchildren = array();
954
        do {
999
        do {
955
            $fail = false;
1000
            $fail = false;
956
            foreach ($remove as $package => $unused) {
1001
            foreach ($remove as $package => $unused) {
957
                if (!isset($allparents[$package])) {
1002
                if (!isset($allparents[$package])) {
958
                    continue;
1003
                    continue;
959
                }
1004
                }
-
 
1005
 
960
                foreach ($allparents[$package] as $kid => $d1) {
1006
                foreach ($allparents[$package] as $kid => $d1) {
961
                    foreach ($d1 as $depinfo) {
1007
                    foreach ($d1 as $depinfo) {
962
                        if ($depinfo[1]['type'] != 'optional') {
1008
                        if ($depinfo[1]['type'] != 'optional') {
963
                            if (isset($badchildren[$kid])) {
1009
                            if (isset($badchildren[$kid])) {
964
                                continue;
1010
                                continue;
Line 974... Line 1020...
974
                    // start over, we removed some children
1020
                    // start over, we removed some children
975
                    continue 2;
1021
                    continue 2;
976
                }
1022
                }
977
            }
1023
            }
978
        } while ($fail);
1024
        } while ($fail);
-
 
1025
 
979
        // next, construct the list of packages that can't be uninstalled
1026
        // next, construct the list of packages that can't be uninstalled
980
        $badpackages = array();
1027
        $badpackages = array();
981
        $save = $this->_currentPackage;
1028
        $save = $this->_currentPackage;
982
        foreach ($perpackagelist as $package => $packagedeps) {
1029
        foreach ($perpackagelist as $package => $packagedeps) {
983
            foreach ($packagedeps as $parent) {
1030
            foreach ($packagedeps as $parent) {
984
                if (!isset($remove[$parent[0]])) {
1031
                if (!isset($remove[$parent[0]])) {
985
                    continue;
1032
                    continue;
986
                }
1033
                }
-
 
1034
 
987
                $packagename = $this->_registry->parsePackageName($parent[0]);
1035
                $packagename = $this->_registry->parsePackageName($parent[0]);
988
                $packagename['channel'] = $this->_registry->channelAlias($packagename['channel']);
1036
                $packagename['channel'] = $this->_registry->channelAlias($packagename['channel']);
989
                $pa = $this->_registry->getPackage($packagename['package'], $packagename['channel']);
1037
                $pa = $this->_registry->getPackage($packagename['package'], $packagename['channel']);
990
                $packagename['package'] = $pa->getPackage();
1038
                $packagename['package'] = $pa->getPackage();
991
                $this->_currentPackage = $packagename;
1039
                $this->_currentPackage = $packagename;
Line 1007... Line 1055...
1007
                        $badpackages[$package]['errors'][] = $test;
1055
                        $badpackages[$package]['errors'][] = $test;
1008
                    }
1056
                    }
1009
                }
1057
                }
1010
            }
1058
            }
1011
        }
1059
        }
-
 
1060
 
1012
        $this->_currentPackage = $save;
1061
        $this->_currentPackage          = $save;
1013
        $dl->___uninstall_package_cache = $badpackages;
1062
        $dl->___uninstall_package_cache = $badpackages;
1014
        if (isset($badpackages[$memyselfandI])) {
1063
        if (isset($badpackages[$memyselfandI])) {
1015
            if (isset($badpackages[$memyselfandI]['warnings'])) {
1064
            if (isset($badpackages[$memyselfandI]['warnings'])) {
1016
                foreach ($badpackages[$memyselfandI]['warnings'] as $warning) {
1065
                foreach ($badpackages[$memyselfandI]['warnings'] as $warning) {
1017
                    $dl->log(0, $warning[0]);
1066
                    $dl->log(0, $warning[0]);
1018
                }
1067
                }
1019
            }
1068
            }
-
 
1069
 
1020
            if (isset($badpackages[$memyselfandI]['errors'])) {
1070
            if (isset($badpackages[$memyselfandI]['errors'])) {
1021
                foreach ($badpackages[$memyselfandI]['errors'] as $error) {
1071
                foreach ($badpackages[$memyselfandI]['errors'] as $error) {
-
 
1072
                    if (is_array($error)) {
-
 
1073
                        $dl->log(0, $error[0]);
-
 
1074
                    } else {
1022
                    $dl->log(0, $error->getMessage());
1075
                        $dl->log(0, $error->getMessage());
-
 
1076
                    }
1023
                }
1077
                }
-
 
1078
 
1024
                if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
1079
                if (isset($this->_options['nodeps']) || isset($this->_options['force'])) {
1025
                    return $this->warning(
1080
                    return $this->warning(
1026
                        'warning: %s should not be uninstalled, other installed packages depend ' .
1081
                        'warning: %s should not be uninstalled, other installed packages depend ' .
1027
                        'on this package');
1082
                        'on this package');
1028
                } else {
-
 
1029
                    return $this->raiseError(
-
 
1030
                        '%s cannot be uninstalled, other installed packages depend on this package');
-
 
1031
                }
1083
                }
-
 
1084
 
-
 
1085
                return $this->raiseError(
-
 
1086
                    '%s cannot be uninstalled, other installed packages depend on this package');
1032
            }
1087
            }
1033
        }
1088
        }
-
 
1089
 
1034
        return true;
1090
        return true;
1035
    }
1091
    }
Line 1036... Line 1092...
1036
 
1092
 
1037
    function _validatePackageUninstall($dep, $required, $dl)
1093
    function _validatePackageUninstall($dep, $required, $dl)
1038
    {
1094
    {
1039
        $depname = $this->_registry->parsedPackageNameToString($dep, true);
1095
        $depname = $this->_registry->parsedPackageNameToString($dep, true);
1040
        $version = $this->_registry->packageinfo($dep['package'], 'version',
-
 
1041
            $dep['channel']);
1096
        $version = $this->_registry->packageinfo($dep['package'], 'version', $dep['channel']);
1042
        if (!$version) {
1097
        if (!$version) {
1043
            return true;
1098
            return true;
-
 
1099
        }
1044
        }
1100
 
1045
        $extra = $this->_getExtraString($dep);
-
 
1046
        if (isset($dep['exclude'])) {
1101
        $extra = $this->_getExtraString($dep);
1047
            if (!is_array($dep['exclude'])) {
1102
        if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
1048
                $dep['exclude'] = array($dep['exclude']);
-
 
1049
            }
1103
            $dep['exclude'] = array($dep['exclude']);
-
 
1104
        }
1050
        }
1105
 
1051
        if (isset($dep['conflicts'])) {
1106
        if (isset($dep['conflicts'])) {
1052
            return true; // uninstall OK - these packages conflict (probably installed with --force)
1107
            return true; // uninstall OK - these packages conflict (probably installed with --force)
-
 
1108
        }
1053
        }
1109
 
1054
        if (!isset($dep['min']) && !isset($dep['max'])) {
1110
        if (!isset($dep['min']) && !isset($dep['max'])) {
1055
            if ($required) {
-
 
1056
                if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
1057
                    return $this->raiseError('"' . $depname . '" is required by ' .
-
 
1058
                        'installed package %s' . $extra);
-
 
1059
                } else {
-
 
1060
                    return $this->warning('warning: "' . $depname . '" is required by ' .
-
 
1061
                        'installed package %s' . $extra);
-
 
1062
                }
-
 
1063
            } else {
1111
            if (!$required) {
1064
                return $this->warning('"' . $depname . '" can be optionally used by ' .
1112
                return $this->warning('"' . $depname . '" can be optionally used by ' .
1065
                        'installed package %s' . $extra);
1113
                        'installed package %s' . $extra);
-
 
1114
            }
-
 
1115
 
-
 
1116
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
1117
                return $this->raiseError('"' . $depname . '" is required by ' .
-
 
1118
                    'installed package %s' . $extra);
-
 
1119
            }
-
 
1120
 
-
 
1121
            return $this->warning('warning: "' . $depname . '" is required by ' .
1066
            }
1122
                'installed package %s' . $extra);
-
 
1123
        }
1067
        }
1124
 
1068
        $fail = false;
-
 
1069
        if (isset($dep['min'])) {
1125
        $fail = false;
1070
            if (version_compare($version, $dep['min'], '>=')) {
1126
        if (isset($dep['min']) && version_compare($version, $dep['min'], '>=')) {
1071
                $fail = true;
-
 
1072
            }
1127
            $fail = true;
1073
        }
-
 
-
 
1128
        }
1074
        if (isset($dep['max'])) {
1129
 
1075
            if (version_compare($version, $dep['max'], '<=')) {
1130
        if (isset($dep['max']) && version_compare($version, $dep['max'], '<=')) {
1076
                $fail = true;
-
 
1077
            }
1131
            $fail = true;
-
 
1132
        }
1078
        }
1133
 
1079
        // we re-use this variable, preserve the original value
1134
        // we re-use this variable, preserve the original value
1080
        $saverequired = $required;
1135
        $saverequired = $required;
1081
        if ($required) {
-
 
1082
            if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
-
 
1083
                return $this->raiseError($depname . $extra . ' is required by installed package' .
-
 
1084
                    ' "%s"');
-
 
1085
            } else {
-
 
1086
                return $this->raiseError('warning: ' . $depname . $extra .
-
 
1087
                    ' is required by installed package "%s"');
-
 
1088
            }
-
 
1089
        } else {
1136
        if (!$required) {
1090
            return $this->warning($depname . $extra . ' can be optionally used by installed package' .
1137
            return $this->warning($depname . $extra . ' can be optionally used by installed package' .
1091
                    ' "%s"');
1138
                    ' "%s"');
-
 
1139
        }
-
 
1140
 
-
 
1141
        if (!isset($this->_options['nodeps']) && !isset($this->_options['force'])) {
1092
        }
1142
            return $this->raiseError($depname . $extra . ' is required by installed package' .
-
 
1143
                ' "%s"');
-
 
1144
        }
-
 
1145
 
-
 
1146
        return $this->raiseError('warning: ' . $depname . $extra .
1093
        return true;
1147
            ' is required by installed package "%s"');
Line 1094... Line 1148...
1094
    }
1148
    }
1095
 
1149
 
1096
    /**
1150
    /**
1097
     * validate a downloaded package against installed packages
1151
     * validate a downloaded package against installed packages
1098
     * 
1152
     *
1099
     * As of PEAR 1.4.3, this will only validate
1153
     * As of PEAR 1.4.3, this will only validate
1100
     *
1154
     *
1101
     * @param array|PEAR_Downloader_Package|PEAR_PackageFile_v1|PEAR_PackageFile_v2
1155
     * @param array|PEAR_Downloader_Package|PEAR_PackageFile_v1|PEAR_PackageFile_v2
Line 1111... Line 1165...
1111
        if (is_array($pkg) && isset($pkg['info'])) {
1165
        if (is_array($pkg) && isset($pkg['info'])) {
1112
            $deps = $this->_dependencydb->getDependentPackageDependencies($pkg['info']);
1166
            $deps = $this->_dependencydb->getDependentPackageDependencies($pkg['info']);
1113
        } else {
1167
        } else {
1114
            $deps = $this->_dependencydb->getDependentPackageDependencies($pkg);
1168
            $deps = $this->_dependencydb->getDependentPackageDependencies($pkg);
1115
        }
1169
        }
-
 
1170
 
1116
        $fail = false;
1171
        $fail = false;
1117
        if ($deps) {
1172
        if ($deps) {
1118
            if (!class_exists('PEAR_Downloader_Package')) {
1173
            if (!class_exists('PEAR_Downloader_Package')) {
1119
                require_once 'PEAR/Downloader/Package.php';
1174
                require_once 'PEAR/Downloader/Package.php';
1120
            }
1175
            }
-
 
1176
 
1121
            $dp = &new PEAR_Downloader_Package($dl);
1177
            $dp = new PEAR_Downloader_Package($dl);
1122
            if (is_object($pkg)) {
1178
            if (is_object($pkg)) {
1123
                $dp->setPackageFile($pkg);
1179
                $dp->setPackageFile($pkg);
1124
            } else {
1180
            } else {
1125
                $dp->setDownloadURL($pkg);
1181
                $dp->setDownloadURL($pkg);
1126
            }
1182
            }
-
 
1183
 
1127
            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
1184
            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
1128
            foreach ($deps as $channel => $info) {
1185
            foreach ($deps as $channel => $info) {
1129
                foreach ($info as $package => $ds) {
1186
                foreach ($info as $package => $ds) {
1130
                    foreach ($params as $packd) {
1187
                    foreach ($params as $packd) {
1131
                        if (strtolower($packd->getPackage()) == strtolower($package) &&
1188
                        if (strtolower($packd->getPackage()) == strtolower($package) &&
Line 1137... Line 1194...
1137
                                        '", version "' . $packd->getVersion() . '" will be ' .
1194
                                        '", version "' . $packd->getVersion() . '" will be ' .
1138
                                        'downloaded and installed');
1195
                                        'downloaded and installed');
1139
                            continue 2; // jump to next package
1196
                            continue 2; // jump to next package
1140
                        }
1197
                        }
1141
                    }
1198
                    }
-
 
1199
 
1142
                    foreach ($ds as $d) {
1200
                    foreach ($ds as $d) {
1143
                        $checker = &new PEAR_Dependency2($this->_config, $this->_options,
1201
                        $checker = new PEAR_Dependency2($this->_config, $this->_options,
1144
                            array('channel' => $channel, 'package' => $package), $this->_state);
1202
                            array('channel' => $channel, 'package' => $package), $this->_state);
1145
                        $dep = $d['dep'];
1203
                        $dep = $d['dep'];
1146
                        $required = $d['type'] == 'required';
1204
                        $required = $d['type'] == 'required';
1147
                        $ret = $checker->_validatePackageDownload($dep, $required, array(&$dp));
1205
                        $ret = $checker->_validatePackageDownload($dep, $required, array(&$dp));
1148
                        if (is_array($ret)) {
1206
                        if (is_array($ret)) {
Line 1154... Line 1212...
1154
                    }
1212
                    }
1155
                }
1213
                }
1156
            }
1214
            }
1157
            PEAR::popErrorHandling();
1215
            PEAR::popErrorHandling();
1158
        }
1216
        }
-
 
1217
 
1159
        if ($fail) {
1218
        if ($fail) {
1160
            return $this->raiseError(
1219
            return $this->raiseError(
1161
                '%s cannot be installed, conflicts with installed packages');
1220
                '%s cannot be installed, conflicts with installed packages');
1162
        }
1221
        }
-
 
1222
 
1163
        return true;
1223
        return true;
1164
    }
1224
    }
Line 1165... Line 1225...
1165
 
1225
 
1166
    /**
1226
    /**
Line 1169... Line 1229...
1169
    function validateDependency1($dep, $params = array())
1229
    function validateDependency1($dep, $params = array())
1170
    {
1230
    {
1171
        if (!isset($dep['optional'])) {
1231
        if (!isset($dep['optional'])) {
1172
            $dep['optional'] = 'no';
1232
            $dep['optional'] = 'no';
1173
        }
1233
        }
-
 
1234
 
1174
        list($newdep, $type) = $this->normalizeDep($dep);
1235
        list($newdep, $type) = $this->normalizeDep($dep);
1175
        if (!$newdep) {
1236
        if (!$newdep) {
1176
            return $this->raiseError("Invalid Dependency");
1237
            return $this->raiseError("Invalid Dependency");
1177
        }
1238
        }
-
 
1239
 
1178
        if (method_exists($this, "validate{$type}Dependency")) {
1240
        if (method_exists($this, "validate{$type}Dependency")) {
1179
            return $this->{"validate{$type}Dependency"}($newdep, $dep['optional'] == 'no',
1241
            return $this->{"validate{$type}Dependency"}($newdep, $dep['optional'] == 'no',
1180
                $params, true);
1242
                $params, true);
1181
        }
1243
        }
1182
    }
1244
    }
Line 1190... Line 1252...
1190
            'pkg' => 'Package',
1252
            'pkg' => 'Package',
1191
            'ext' => 'Extension',
1253
            'ext' => 'Extension',
1192
            'os' => 'Os',
1254
            'os' => 'Os',
1193
            'php' => 'Php'
1255
            'php' => 'Php'
1194
        );
1256
        );
-
 
1257
 
1195
        if (isset($types[$dep['type']])) {
1258
        if (!isset($types[$dep['type']])) {
1196
            $type = $types[$dep['type']];
-
 
1197
        } else {
-
 
1198
            return array(false, false);
1259
            return array(false, false);
1199
        }
1260
        }
-
 
1261
 
-
 
1262
        $type = $types[$dep['type']];
-
 
1263
 
1200
        $newdep = array();
1264
        $newdep = array();
1201
        switch ($type) {
1265
        switch ($type) {
1202
            case 'Package' :
1266
            case 'Package' :
1203
                $newdep['channel'] = 'pear.php.net';
1267
                $newdep['channel'] = 'pear.php.net';
1204
            case 'Extension' :
1268
            case 'Extension' :
1205
            case 'Os' :
1269
            case 'Os' :
1206
                $newdep['name'] = $dep['name'];
1270
                $newdep['name'] = $dep['name'];
1207
            break;
1271
            break;
1208
        }
1272
        }
-
 
1273
 
1209
        $dep['rel'] = PEAR_Dependency2::signOperator($dep['rel']);
1274
        $dep['rel'] = PEAR_Dependency2::signOperator($dep['rel']);
1210
        switch ($dep['rel']) {
1275
        switch ($dep['rel']) {
1211
            case 'has' :
1276
            case 'has' :
1212
                return array($newdep, $type);
1277
                return array($newdep, $type);
1213
            break;
1278
            break;
Line 1239... Line 1304...
1239
                $newdep['max'] = $dep['version'];
1304
                $newdep['max'] = $dep['version'];
1240
            break;
1305
            break;
1241
        }
1306
        }
1242
        if ($type == 'Php') {
1307
        if ($type == 'Php') {
1243
            if (!isset($newdep['min'])) {
1308
            if (!isset($newdep['min'])) {
1244
                $newdep['min'] = '4.2.0';
1309
                $newdep['min'] = '4.4.0';
1245
            }
1310
            }
-
 
1311
 
1246
            if (!isset($newdep['max'])) {
1312
            if (!isset($newdep['max'])) {
1247
                $newdep['max'] = '6.0.0';
1313
                $newdep['max'] = '6.0.0';
1248
            }
1314
            }
1249
        }
1315
        }
1250
        return array($newdep, $type);
1316
        return array($newdep, $type);
Line 1276... Line 1342...
1276
    function raiseError($msg)
1342
    function raiseError($msg)
1277
    {
1343
    {
1278
        if (isset($this->_options['ignore-errors'])) {
1344
        if (isset($this->_options['ignore-errors'])) {
1279
            return $this->warning($msg);
1345
            return $this->warning($msg);
1280
        }
1346
        }
-
 
1347
 
1281
        return PEAR::raiseError(sprintf($msg, $this->_registry->parsedPackageNameToString(
1348
        return PEAR::raiseError(sprintf($msg, $this->_registry->parsedPackageNameToString(
1282
            $this->_currentPackage, true)));
1349
            $this->_currentPackage, true)));
1283
    }
1350
    }
Line 1284... Line 1351...
1284
 
1351
 
1285
    function warning($msg)
1352
    function warning($msg)
1286
    {
1353
    {
1287
        return array(sprintf($msg, $this->_registry->parsedPackageNameToString(
1354
        return array(sprintf($msg, $this->_registry->parsedPackageNameToString(
1288
            $this->_currentPackage, true)));
1355
            $this->_currentPackage, true)));
1289
    }
1356
    }
1290
}
-
 
1291
?>
1357
}