Хранилища Subversion ant

Редакция

Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 69 Редакция 87
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_Command_Config (config-show, config-get, config-set, config-help, config-create commands)
3
 * PEAR_Command_Config (config-show, config-get, config-set, config-help, config-create commands)
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
8
 * that is available through the world-wide-web at the following URI:
8
 * that is available through the world-wide-web at the following URI:
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
10
 * the PHP License and are unable to obtain it through the web, please
10
 * the PHP License and are unable to obtain it through the web, please
11
 * send a note to license@php.net so we can mail you a copy immediately.
11
 * send a note to license@php.net so we can mail you a copy immediately.
12
 *
12
 *
13
 * @category   pear
13
 * @category   pear
14
 * @package    PEAR
14
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
15
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2008 The PHP Group
17
 * @copyright  1997-2008 The PHP Group
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
19
 * @version    CVS: $Id: Config.php,v 1.56 2008/01/03 20:26:36 cellog Exp $
19
 * @version    CVS: $Id: Config.php,v 1.56 2008/01/03 20:26:36 cellog Exp $
20
 * @link       http://pear.php.net/package/PEAR
20
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
21
 * @since      File available since Release 0.1
22
 */
22
 */
23
23
24
/**
24
/**
25
 * base class
25
 * base class
26
 */
26
 */
27
require_once 'PEAR/Command/Common.php';
27
require_once 'PEAR/Command/Common.php';
28
28
29
/**
29
/**
30
 * PEAR commands for managing configuration data.
30
 * PEAR commands for managing configuration data.
31
 *
31
 *
32
 * @category   pear
32
 * @category   pear
33
 * @package    PEAR
33
 * @package    PEAR
34
 * @author     Stig Bakken <ssb@php.net>
34
 * @author     Stig Bakken <ssb@php.net>
35
 * @author     Greg Beaver <cellog@php.net>
35
 * @author     Greg Beaver <cellog@php.net>
36
 * @copyright  1997-2008 The PHP Group
36
 * @copyright  1997-2008 The PHP Group
37
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
37
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
38
 * @version    Release: 1.7.2
38
 * @version    Release: 1.7.2
39
 * @link       http://pear.php.net/package/PEAR
39
 * @link       http://pear.php.net/package/PEAR
40
 * @since      Class available since Release 0.1
40
 * @since      Class available since Release 0.1
41
 */
41
 */
42
class PEAR_Command_Config extends PEAR_Command_Common
42
class PEAR_Command_Config extends PEAR_Command_Common
43
{
43
{
44
    // {{{ properties
44
    // {{{ properties
45
45
46
    var $commands = array(
46
    var $commands = array(
47
        'config-show' => array(
47
        'config-show' => array(
48
            'summary' => 'Show All Settings',
48
            'summary' => 'Show All Settings',
49
            'function' => 'doConfigShow',
49
            'function' => 'doConfigShow',
50
            'shortcut' => 'csh',
50
            'shortcut' => 'csh',
51
            'options' => array(
51
            'options' => array(
52
                'channel' => array(
52
                'channel' => array(
53
                    'shortopt' => 'c',
53
                    'shortopt' => 'c',
54
                    'doc' => 'show configuration variables for another channel',
54
                    'doc' => 'show configuration variables for another channel',
55
                    'arg' => 'CHAN',
55
                    'arg' => 'CHAN',
56
                    ),
56
                    ),
57
),
57
),
58
            'doc' => '[layer]
58
            'doc' => '[layer]
59
Displays all configuration values.  An optional argument
59
Displays all configuration values.  An optional argument
60
may be used to tell which configuration layer to display.  Valid
60
may be used to tell which configuration layer to display.  Valid
61
configuration layers are "user", "system" and "default". To display
61
configuration layers are "user", "system" and "default". To display
62
configurations for different channels, set the default_channel
62
configurations for different channels, set the default_channel
63
configuration variable and run config-show again.
63
configuration variable and run config-show again.
64
',
64
',
65
            ),
65
            ),
66
        'config-get' => array(
66
        'config-get' => array(
67
            'summary' => 'Show One Setting',
67
            'summary' => 'Show One Setting',
68
            'function' => 'doConfigGet',
68
            'function' => 'doConfigGet',
69
            'shortcut' => 'cg',
69
            'shortcut' => 'cg',
70
            'options' => array(
70
            'options' => array(
71
                'channel' => array(
71
                'channel' => array(
72
                    'shortopt' => 'c',
72
                    'shortopt' => 'c',
73
                    'doc' => 'show configuration variables for another channel',
73
                    'doc' => 'show configuration variables for another channel',
74
                    'arg' => 'CHAN',
74
                    'arg' => 'CHAN',
75
                    ),
75
                    ),
76
),
76
),
77
            'doc' => '<parameter> [layer]
77
            'doc' => '<parameter> [layer]
78
Displays the value of one configuration parameter.  The
78
Displays the value of one configuration parameter.  The
79
first argument is the name of the parameter, an optional second argument
79
first argument is the name of the parameter, an optional second argument
80
may be used to tell which configuration layer to look in.  Valid configuration
80
may be used to tell which configuration layer to look in.  Valid configuration
81
layers are "user", "system" and "default".  If no layer is specified, a value
81
layers are "user", "system" and "default".  If no layer is specified, a value
82
will be picked from the first layer that defines the parameter, in the order
82
will be picked from the first layer that defines the parameter, in the order
83
just specified.  The configuration value will be retrieved for the channel
83
just specified.  The configuration value will be retrieved for the channel
84
specified by the default_channel configuration variable.
84
specified by the default_channel configuration variable.
85
',
85
',
86
            ),
86
            ),
87
        'config-set' => array(
87
        'config-set' => array(
88
            'summary' => 'Change Setting',
88
            'summary' => 'Change Setting',
89
            'function' => 'doConfigSet',
89
            'function' => 'doConfigSet',
90
            'shortcut' => 'cs',
90
            'shortcut' => 'cs',
91
            'options' => array(
91
            'options' => array(
92
                'channel' => array(
92
                'channel' => array(
93
                    'shortopt' => 'c',
93
                    'shortopt' => 'c',
94
                    'doc' => 'show configuration variables for another channel',
94
                    'doc' => 'show configuration variables for another channel',
95
                    'arg' => 'CHAN',
95
                    'arg' => 'CHAN',
96
                    ),
96
                    ),
97
),
97
),
98
            'doc' => '<parameter> <value> [layer]
98
            'doc' => '<parameter> <value> [layer]
99
Sets the value of one configuration parameter.  The first argument is
99
Sets the value of one configuration parameter.  The first argument is
100
the name of the parameter, the second argument is the new value.  Some
100
the name of the parameter, the second argument is the new value.  Some
101
parameters are subject to validation, and the command will fail with
101
parameters are subject to validation, and the command will fail with
102
an error message if the new value does not make sense.  An optional
102
an error message if the new value does not make sense.  An optional
103
third argument may be used to specify in which layer to set the
103
third argument may be used to specify in which layer to set the
104
configuration parameter.  The default layer is "user".  The
104
configuration parameter.  The default layer is "user".  The
105
configuration value will be set for the current channel, which
105
configuration value will be set for the current channel, which
106
is controlled by the default_channel configuration variable.
106
is controlled by the default_channel configuration variable.
107
',
107
',
108
            ),
108
            ),
109
        'config-help' => array(
109
        'config-help' => array(
110
            'summary' => 'Show Information About Setting',
110
            'summary' => 'Show Information About Setting',
111
            'function' => 'doConfigHelp',
111
            'function' => 'doConfigHelp',
112
            'shortcut' => 'ch',
112
            'shortcut' => 'ch',
113
            'options' => array(),
113
            'options' => array(),
114
            'doc' => '[parameter]
114
            'doc' => '[parameter]
115
Displays help for a configuration parameter.  Without arguments it
115
Displays help for a configuration parameter.  Without arguments it
116
displays help for all configuration parameters.
116
displays help for all configuration parameters.
117
',
117
',
118
           ),
118
           ),
119
        'config-create' => array(
119
        'config-create' => array(
120
            'summary' => 'Create a Default configuration file',
120
            'summary' => 'Create a Default configuration file',
121
            'function' => 'doConfigCreate',
121
            'function' => 'doConfigCreate',
122
            'shortcut' => 'coc',
122
            'shortcut' => 'coc',
123
            'options' => array(
123
            'options' => array(
124
                'windows' => array(
124
                'windows' => array(
125
                    'shortopt' => 'w',
125
                    'shortopt' => 'w',
126
                    'doc' => 'create a config file for a windows install',
126
                    'doc' => 'create a config file for a windows install',
127
                    ),
127
                    ),
128
            ),
128
            ),
129
            'doc' => '<root path> <filename>
129
            'doc' => '<root path> <filename>
130
Create a default configuration file with all directory configuration
130
Create a default configuration file with all directory configuration
131
variables set to subdirectories of <root path>, and save it as <filename>.
131
variables set to subdirectories of <root path>, and save it as <filename>.
132
This is useful especially for creating a configuration file for a remote
132
This is useful especially for creating a configuration file for a remote
133
PEAR installation (using the --remoteconfig option of install, upgrade,
133
PEAR installation (using the --remoteconfig option of install, upgrade,
134
and uninstall).
134
and uninstall).
135
',
135
',
136
            ),
136
            ),
137
        );
137
        );
138
138
139
    // }}}
139
    // }}}
140
    // {{{ constructor
140
    // {{{ constructor
141
141
142
    /**
142
    /**
143
     * PEAR_Command_Config constructor.
143
     * PEAR_Command_Config constructor.
144
     *
144
     *
145
     * @access public
145
     * @access public
146
     */
146
     */
147
    function PEAR_Command_Config(&$ui, &$config)
147
    function PEAR_Command_Config(&$ui, &$config)
148
    {
148
    {
149
        parent::PEAR_Command_Common($ui, $config);
149
        parent::PEAR_Command_Common($ui, $config);
150
    }
150
    }
151
151
152
    // }}}
152
    // }}}
153
153
154
    // {{{ doConfigShow()
154
    // {{{ doConfigShow()
155
155
156
    function doConfigShow($command, $options, $params)
156
    function doConfigShow($command, $options, $params)
157
    {
157
    {
158
        if (is_array($params)) {
158
        if (is_array($params)) {
159
            $layer = isset($params[0]) ? $params[0] : NULL;
159
            $layer = isset($params[0]) ? $params[0] : NULL;
160
        } else {
160
        } else {
161
            $layer = NULL;
161
            $layer = NULL;
162
        }
162
        }
163
163
164
        // $params[0] -> the layer
164
        // $params[0] -> the layer
165
        if ($error = $this->_checkLayer($layer)) {
165
        if ($error = $this->_checkLayer($layer)) {
166
            return $this->raiseError("config-show:$error");
166
            return $this->raiseError("config-show:$error");
167
        }
167
        }
168
        $keys = $this->config->getKeys();
168
        $keys = $this->config->getKeys();
169
        sort($keys);
169
        sort($keys);
170
        $channel = isset($options['channel']) ? $options['channel'] :
170
        $channel = isset($options['channel']) ? $options['channel'] :
171
            $this->config->get('default_channel');
171
            $this->config->get('default_channel');
172
        $reg = &$this->config->getRegistry();
172
        $reg = &$this->config->getRegistry();
173
        if (!$reg->channelExists($channel)) {
173
        if (!$reg->channelExists($channel)) {
174
            return $this->raiseError('Channel "' . $channel . '" does not exist');
174
            return $this->raiseError('Channel "' . $channel . '" does not exist');
175
        }
175
        }
176
        $data = array('caption' => 'Configuration (channel ' . $channel . '):');
176
        $data = array('caption' => 'Configuration (channel ' . $channel . '):');
177
        foreach ($keys as $key) {
177
        foreach ($keys as $key) {
178
            $type = $this->config->getType($key);
178
            $type = $this->config->getType($key);
179
            $value = $this->config->get($key, $layer, $channel);
179
            $value = $this->config->get($key, $layer, $channel);
180
            if ($type == 'password' && $value) {
180
            if ($type == 'password' && $value) {
181
                $value = '********';
181
                $value = '********';
182
            }
182
            }
183
            if ($value === false) {
183
            if ($value === false) {
184
                $value = 'false';
184
                $value = 'false';
185
            } elseif ($value === true) {
185
            } elseif ($value === true) {
186
                $value = 'true';
186
                $value = 'true';
187
            }
187
            }
188
            $data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
188
            $data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
189
        }
189
        }
190
        foreach ($this->config->getLayers() as $layer) {
190
        foreach ($this->config->getLayers() as $layer) {
191
            $data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer));
191
            $data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer));
192
        }
192
        }
193
193
194
        $this->ui->outputData($data, $command);
194
        $this->ui->outputData($data, $command);
195
        return true;
195
        return true;
196
    }
196
    }
197
197
198
    // }}}
198
    // }}}
199
    // {{{ doConfigGet()
199
    // {{{ doConfigGet()
200
200
201
    function doConfigGet($command, $options, $params)
201
    function doConfigGet($command, $options, $params)
202
    {
202
    {
203
        if (!is_array($params)) {
203
        if (!is_array($params)) {
204
            $args_cnt = 0;
204
            $args_cnt = 0;
205
        } else {
205
        } else {
206
            $args_cnt  = count($params);
206
            $args_cnt  = count($params);
207
        }
207
        }
208
208
209
        switch ($args_cnt) {
209
        switch ($args_cnt) {
210
            case 1:
210
            case 1:
211
                $config_key = $params[0];
211
                $config_key = $params[0];
212
                $layer = NULL;
212
                $layer = NULL;
213
                break;
213
                break;
214
            case 2:
214
            case 2:
215
                $config_key = $params[0];
215
                $config_key = $params[0];
216
                $layer = $params[1];
216
                $layer = $params[1];
217
                if ($error = $this->_checkLayer($layer)) {
217
                if ($error = $this->_checkLayer($layer)) {
218
                    return $this->raiseError("config-get:$error");
218
                    return $this->raiseError("config-get:$error");
219
                }
219
                }
220
                break;
220
                break;
221
            case 0:
221
            case 0:
222
            default:
222
            default:
223
                return $this->raiseError("config-get expects 1 or 2 parameters");
223
                return $this->raiseError("config-get expects 1 or 2 parameters");
224
        }
224
        }
225
225
226
        $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
226
        $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
227
        $reg = &$this->config->getRegistry();
227
        $reg = &$this->config->getRegistry();
228
228
229
        if (!$reg->channelExists($channel)) {
229
        if (!$reg->channelExists($channel)) {
230
            return $this->raiseError('Channel "' . $channel . '" does not exist');
230
            return $this->raiseError('Channel "' . $channel . '" does not exist');
231
        }
231
        }
232
232
233
        $this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
233
        $this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
234
234
235
        return true;
235
        return true;
236
    }
236
    }
237
237
238
    // }}}
238
    // }}}
239
    // {{{ doConfigSet()
239
    // {{{ doConfigSet()
240
240
241
    function doConfigSet($command, $options, $params)
241
    function doConfigSet($command, $options, $params)
242
    {
242
    {
243
        // $param[0] -> a parameter to set
243
        // $param[0] -> a parameter to set
244
        // $param[1] -> the value for the parameter
244
        // $param[1] -> the value for the parameter
245
        // $param[2] -> the layer
245
        // $param[2] -> the layer
246
        $failmsg = '';
246
        $failmsg = '';
247
        if (sizeof($params) < 2 || sizeof($params) > 3) {
247
        if (sizeof($params) < 2 || sizeof($params) > 3) {
248
            $failmsg .= "config-set expects 2 or 3 parameters";
248
            $failmsg .= "config-set expects 2 or 3 parameters";
249
            return PEAR::raiseError($failmsg);
249
            return PEAR::raiseError($failmsg);
250
        }
250
        }
251
        if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) {
251
        if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) {
252
            $failmsg .= $error;
252
            $failmsg .= $error;
253
            return PEAR::raiseError("config-set:$failmsg");
253
            return PEAR::raiseError("config-set:$failmsg");
254
        }
254
        }
255
        $channel = isset($options['channel']) ? $options['channel'] :
255
        $channel = isset($options['channel']) ? $options['channel'] :
256
            $this->config->get('default_channel');
256
            $this->config->get('default_channel');
257
        $reg = &$this->config->getRegistry();
257
        $reg = &$this->config->getRegistry();
258
        if (!$reg->channelExists($channel)) {
258
        if (!$reg->channelExists($channel)) {
259
            return $this->raiseError('Channel "' . $channel . '" does not exist');
259
            return $this->raiseError('Channel "' . $channel . '" does not exist');
260
        }
260
        }
261
        if ($params[0] == 'default_channel') {
261
        if ($params[0] == 'default_channel') {
262
            if (!$reg->channelExists($params[1])) {
262
            if (!$reg->channelExists($params[1])) {
263
                return $this->raiseError('Channel "' . $params[1] . '" does not exist');
263
                return $this->raiseError('Channel "' . $params[1] . '" does not exist');
264
            }
264
            }
265
        }
265
        }
266
        if (count($params) == 2) {
266
        if (count($params) == 2) {
267
            array_push($params, 'user');
267
            array_push($params, 'user');
268
            $layer = 'user';
268
            $layer = 'user';
269
        } else {
269
        } else {
270
            $layer = $params[2];
270
            $layer = $params[2];
271
        }
271
        }
272
        array_push($params, $channel);
272
        array_push($params, $channel);
273
        if (!call_user_func_array(array(&$this->config, 'set'), $params))
273
        if (!call_user_func_array(array(&$this->config, 'set'), $params))
274
        {
274
        {
275
            array_pop($params);
275
            array_pop($params);
276
            $failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel";
276
            $failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel";
277
        } else {
277
        } else {
278
            $this->config->store($layer);
278
            $this->config->store($layer);
279
        }
279
        }
280
        if ($failmsg) {
280
        if ($failmsg) {
281
            return $this->raiseError($failmsg);
281
            return $this->raiseError($failmsg);
282
        }
282
        }
283
        $this->ui->outputData('config-set succeeded', $command);
283
        $this->ui->outputData('config-set succeeded', $command);
284
        return true;
284
        return true;
285
    }
285
    }
286
286
287
    // }}}
287
    // }}}
288
    // {{{ doConfigHelp()
288
    // {{{ doConfigHelp()
289
289
290
    function doConfigHelp($command, $options, $params)
290
    function doConfigHelp($command, $options, $params)
291
    {
291
    {
292
        if (empty($params)) {
292
        if (empty($params)) {
293
            $params = $this->config->getKeys();
293
            $params = $this->config->getKeys();
294
        }
294
        }
295
        $data['caption']  = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
295
        $data['caption']  = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
296
        $data['headline'] = array('Name', 'Type', 'Description');
296
        $data['headline'] = array('Name', 'Type', 'Description');
297
        $data['border']   = true;
297
        $data['border']   = true;
298
        foreach ($params as $name) {
298
        foreach ($params as $name) {
299
            $type = $this->config->getType($name);
299
            $type = $this->config->getType($name);
300
            $docs = $this->config->getDocs($name);
300
            $docs = $this->config->getDocs($name);
301
            if ($type == 'set') {
301
            if ($type == 'set') {
302
                $docs = rtrim($docs) . "\nValid set: " .
302
                $docs = rtrim($docs) . "\nValid set: " .
303
                    implode(' ', $this->config->getSetValues($name));
303
                    implode(' ', $this->config->getSetValues($name));
304
            }
304
            }
305
            $data['data'][] = array($name, $type, $docs);
305
            $data['data'][] = array($name, $type, $docs);
306
        }
306
        }
307
        $this->ui->outputData($data, $command);
307
        $this->ui->outputData($data, $command);
308
    }
308
    }
309
309
310
    // }}}
310
    // }}}
311
    // {{{ doConfigCreate()
311
    // {{{ doConfigCreate()
312
312
313
    function doConfigCreate($command, $options, $params)
313
    function doConfigCreate($command, $options, $params)
314
    {
314
    {
315
        if (count($params) != 2) {
315
        if (count($params) != 2) {
316
            return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
316
            return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
317
                'filename to save as');
317
                'filename to save as');
318
        }
318
        }
319
        $root = $params[0];
319
        $root = $params[0];
320
        // Clean up the DIRECTORY_SEPARATOR mess
320
        // Clean up the DIRECTORY_SEPARATOR mess
321
        $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
321
        $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
322
        $root = preg_replace(array('!\\\\+!', '!/+!', "!$ds2+!"),
322
        $root = preg_replace(array('!\\\\+!', '!/+!', "!$ds2+!"),
323
                             array('/', '/', '/'),
323
                             array('/', '/', '/'),
324
                            $root);
324
                            $root);
325
        if ($root{0} != '/') {
325
        if ($root{0} != '/') {
326
            if (isset($options['windows'])) {
326
            if (isset($options['windows'])) {
327
                if (!preg_match('/^[A-Za-z]:/', $root)) {
327
                if (!preg_match('/^[A-Za-z]:/', $root)) {
328
                    return PEAR::raiseError('Root directory must be an absolute path beginning ' .
328
                    return PEAR::raiseError('Root directory must be an absolute path beginning ' .
329
                        'with "\\" or "C:\\", was: "' . $root . '"');
329
                        'with "\\" or "C:\\", was: "' . $root . '"');
330
                }
330
                }
331
            } else {
331
            } else {
332
                return PEAR::raiseError('Root directory must be an absolute path beginning ' .
332
                return PEAR::raiseError('Root directory must be an absolute path beginning ' .
333
                    'with "/", was: "' . $root . '"');
333
                    'with "/", was: "' . $root . '"');
334
            }
334
            }
335
        }
335
        }
336
        $windows = isset($options['windows']);
336
        $windows = isset($options['windows']);
337
        if ($windows) {
337
        if ($windows) {
338
            $root = str_replace('/', '\\', $root);
338
            $root = str_replace('/', '\\', $root);
339
        }
339
        }
340
        if (!file_exists($params[1])) {
340
        if (!file_exists($params[1])) {
341
            if (!@touch($params[1])) {
341
            if (!@touch($params[1])) {
342
                return PEAR::raiseError('Could not create "' . $params[1] . '"');
342
                return PEAR::raiseError('Could not create "' . $params[1] . '"');
343
            }
343
            }
344
        }
344
        }
345
        $params[1] = realpath($params[1]);
345
        $params[1] = realpath($params[1]);
346
        $config = &new PEAR_Config($params[1], '#no#system#config#', false, false);
346
        $config = &new PEAR_Config($params[1], '#no#system#config#', false, false);
347
        if ($root{strlen($root) - 1} == '/') {
347
        if ($root{strlen($root) - 1} == '/') {
348
            $root = substr($root, 0, strlen($root) - 1);
348
            $root = substr($root, 0, strlen($root) - 1);
349
        }
349
        }
350
        $config->noRegistry();
350
        $config->noRegistry();
351
        $config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user');
351
        $config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user');
352
        $config->set('data_dir', $windows ? "$root\\pear\\data" : "$root/pear/data");
352
        $config->set('data_dir', $windows ? "$root\\pear\\data" : "$root/pear/data");
353
        $config->set('www_dir', $windows ? "$root\\pear\\www" : "$root/pear/www");
353
        $config->set('www_dir', $windows ? "$root\\pear\\www" : "$root/pear/www");
354
        $config->set('cfg_dir', $windows ? "$root\\pear\\cfg" : "$root/pear/cfg");
354
        $config->set('cfg_dir', $windows ? "$root\\pear\\cfg" : "$root/pear/cfg");
355
        $config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext");
355
        $config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext");
356
        $config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs");
356
        $config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs");
357
        $config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests");
357
        $config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests");
358
        $config->set('cache_dir', $windows ? "$root\\pear\\cache" : "$root/pear/cache");
358
        $config->set('cache_dir', $windows ? "$root\\pear\\cache" : "$root/pear/cache");
359
        $config->set('download_dir', $windows ? "$root\\pear\\download" : "$root/pear/download");
359
        $config->set('download_dir', $windows ? "$root\\pear\\download" : "$root/pear/download");
360
        $config->set('temp_dir', $windows ? "$root\\pear\\temp" : "$root/pear/temp");
360
        $config->set('temp_dir', $windows ? "$root\\pear\\temp" : "$root/pear/temp");
361
        $config->set('bin_dir', $windows ? "$root\\pear" : "$root/pear");
361
        $config->set('bin_dir', $windows ? "$root\\pear" : "$root/pear");
362
        $config->writeConfigFile();
362
        $config->writeConfigFile();
363
        $this->_showConfig($config);
363
        $this->_showConfig($config);
364
        $this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"',
364
        $this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"',
365
            $command);
365
            $command);
366
    }
366
    }
367
367
368
    // }}}
368
    // }}}
369
369
370
    function _showConfig(&$config)
370
    function _showConfig(&$config)
371
    {
371
    {
372
        $params = array('user');
372
        $params = array('user');
373
        $keys = $config->getKeys();
373
        $keys = $config->getKeys();
374
        sort($keys);
374
        sort($keys);
375
        $channel = 'pear.php.net';
375
        $channel = 'pear.php.net';
376
        $data = array('caption' => 'Configuration (channel ' . $channel . '):');
376
        $data = array('caption' => 'Configuration (channel ' . $channel . '):');
377
        foreach ($keys as $key) {
377
        foreach ($keys as $key) {
378
            $type = $config->getType($key);
378
            $type = $config->getType($key);
379
            $value = $config->get($key, 'user', $channel);
379
            $value = $config->get($key, 'user', $channel);
380
            if ($type == 'password' && $value) {
380
            if ($type == 'password' && $value) {
381
                $value = '********';
381
                $value = '********';
382
            }
382
            }
383
            if ($value === false) {
383
            if ($value === false) {
384
                $value = 'false';
384
                $value = 'false';
385
            } elseif ($value === true) {
385
            } elseif ($value === true) {
386
                $value = 'true';
386
                $value = 'true';
387
            }
387
            }
388
            $data['data'][$config->getGroup($key)][] =
388
            $data['data'][$config->getGroup($key)][] =
389
                array($config->getPrompt($key) , $key, $value);
389
                array($config->getPrompt($key) , $key, $value);
390
        }
390
        }
391
        foreach ($config->getLayers() as $layer) {
391
        foreach ($config->getLayers() as $layer) {
392
            $data['data']['Config Files'][] =
392
            $data['data']['Config Files'][] =
393
                array(ucfirst($layer) . ' Configuration File', 'Filename' ,
393
                array(ucfirst($layer) . ' Configuration File', 'Filename' ,
394
                    $config->getConfFile($layer));
394
                    $config->getConfFile($layer));
395
        }
395
        }
396
396
397
        $this->ui->outputData($data, 'config-show');
397
        $this->ui->outputData($data, 'config-show');
398
        return true;
398
        return true;
399
    }
399
    }
400
    // {{{ _checkLayer()
400
    // {{{ _checkLayer()
401
401
402
    /**
402
    /**
403
     * Checks if a layer is defined or not
403
     * Checks if a layer is defined or not
404
     *
404
     *
405
     * @param string $layer The layer to search for
405
     * @param string $layer The layer to search for
406
     * @return mixed False on no error or the error message
406
     * @return mixed False on no error or the error message
407
     */
407
     */
408
    function _checkLayer($layer = null)
408
    function _checkLayer($layer = null)
409
    {
409
    {
410
        if (!empty($layer) && $layer != 'default') {
410
        if (!empty($layer) && $layer != 'default') {
411
            $layers = $this->config->getLayers();
411
            $layers = $this->config->getLayers();
412
            if (!in_array($layer, $layers)) {
412
            if (!in_array($layer, $layers)) {
413
                return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
413
                return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
414
            }
414
            }
415
        }
415
        }
416
        return false;
416
        return false;
417
    }
417
    }
418
418
419
    // }}}
419
    // }}}
420
}
420
}
421
421
422
?>
422
?>
423
 
423