Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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