Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Command_Config Class Reference
Inheritance diagram for PEAR_Command_Config:
Collaboration diagram for PEAR_Command_Config:

Public Member Functions

 __construct (&$ui, &$config)
 _checkLayer ($layer=null)
 _showConfig (&$config)
 doConfigCreate ($command, $options, $params)
 doConfigGet ($command, $options, $params)
 doConfigHelp ($command, $options, $params)
 doConfigSet ($command, $options, $params)
 doConfigShow ($command, $options, $params)
Public Member Functions inherited from PEAR_Command_Common
 getCommands ()
 getGetoptArgs ($command, &$short_args, &$long_args)
 getHelp ($command)
 getHelpArgs ($command)
 getOptions ($command)
 getShortcuts ()
 run ($command, $options, $params)
Public Member Functions inherited from PEAR
 __call ($method, $arguments)
 __construct ($error_class=null)
 _checkDelExpect ($error_code)
 _PEAR ()
 delExpect ($error_code)
 expectError ($code=' *')
 PEAR ($error_class=null)
 popExpect ()

Data Fields

 $commands
Data Fields inherited from PEAR_Command_Common
 $_deps_rel_trans
 $_deps_type_trans
 $_registry
 $config
 $ui
Data Fields inherited from PEAR
 $_debug = false
 $_default_error_handler = ''
 $_default_error_mode = null
 $_default_error_options = null
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Additional Inherited Members

Static Public Member Functions inherited from PEAR
static __callStatic ($method, $arguments)
static getSourceDateEpoch ()
static & getStaticProperty ($class, $var)
static isError ($data, $code=null)
static loadExtension ($ext)
static registerShutdownFunc ($func, $args=array())
static staticPopErrorHandling ()
static staticPushErrorHandling ($mode, $options=null)
Static Protected Member Functions inherited from PEAR
static _popErrorHandling ($object)
static _pushErrorHandling ($object, $mode, $options=null)
static _raiseError ($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
static _setErrorHandling ( $object, $mode=null, $options=null)
static _throwError ($object, $message=null, $code=null, $userinfo=null)
Static Protected Attributes inherited from PEAR
static $bivalentMethods

Detailed Description

Definition at line 35 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( & $ui,
& $config )

PEAR_Command_Config constructor.

@access public

Reimplemented from PEAR_Command_Common.

Definition at line 135 of file Config.php.

136 {
137 parent::__construct($ui, $config);
138 }

References PEAR_Command_Common\$config, and PEAR_Command_Common\$ui.

Member Function Documentation

◆ _checkLayer()

_checkLayer ( $layer = null)

Checks if a layer is defined or not

Parameters
string$layerThe layer to search for
Returns
mixed False on no error or the error message

Definition at line 403 of file Config.php.

404 {
405 if (!empty($layer) && $layer != 'default') {
406 $layers = $this->config->getLayers();
407 if (!in_array($layer, $layers)) {
408 return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
409 }
410 }
411
412 return false;
413 }

Referenced by doConfigGet(), doConfigSet(), and doConfigShow().

Here is the caller graph for this function:

◆ _showConfig()

_showConfig ( & $config)

Definition at line 364 of file Config.php.

365 {
366 $params = array('user');
367 $keys = $config->getKeys();
368 sort($keys);
369 $channel = 'pear.php.net';
370 $data = array('caption' => 'Configuration (channel ' . $channel . '):');
371 foreach ($keys as $key) {
372 $type = $config->getType($key);
373 $value = $config->get($key, 'user', $channel);
374 if ($type == 'password' && $value) {
375 $value = '********';
376 }
377
378 if ($value === false) {
379 $value = 'false';
380 } elseif ($value === true) {
381 $value = 'true';
382 }
383 $data['data'][$config->getGroup($key)][] =
384 array($config->getPrompt($key) , $key, $value);
385 }
386
387 foreach ($config->getLayers() as $layer) {
388 $data['data']['Config Files'][] =
389 array(ucfirst($layer) . ' Configuration File', 'Filename' ,
390 $config->getConfFile($layer));
391 }
392
393 $this->ui->outputData($data, 'config-show');
394 return true;
395 }

References PEAR_Command_Common\$config.

Referenced by doConfigCreate().

Here is the caller graph for this function:

◆ doConfigCreate()

doConfigCreate ( $command,
$options,
$params )

Definition at line 305 of file Config.php.

306 {
307 if (count($params) != 2) {
308 return PEAR::raiseError('config-create: must have 2 parameters, root path and ' .
309 'filename to save as');
310 }
311
312 $root = $params[0];
313 // Clean up the DIRECTORY_SEPARATOR mess
314 $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
315 $root = preg_replace(array('!\\\\+!', '!/+!', "!$ds2+!"),
316 array('/', '/', '/'),
317 $root);
318 if ($root[0] != '/') {
319 if (!isset($options['windows'])) {
320 return PEAR::raiseError('Root directory must be an absolute path beginning ' .
321 'with "/", was: "' . $root . '"');
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 }
328 }
329
330 $windows = isset($options['windows']);
331 if ($windows) {
332 $root = str_replace('/', '\\', $root);
333 }
334
335 if (!file_exists($params[1]) && !@touch($params[1])) {
336 return PEAR::raiseError('Could not create "' . $params[1] . '"');
337 }
338
339 $params[1] = realpath($params[1]);
340 $config = new PEAR_Config($params[1], '#no#system#config#', false, false);
341 if ($root[strlen($root) - 1] == '/') {
342 $root = substr($root, 0, strlen($root) - 1);
343 }
344
345 $config->noRegistry();
346 $config->set('php_dir', $windows ? "$root\\pear\\php" : "$root/pear/php", 'user');
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");
350 $config->set('ext_dir', $windows ? "$root\\pear\\ext" : "$root/pear/ext");
351 $config->set('doc_dir', $windows ? "$root\\pear\\docs" : "$root/pear/docs");
352 $config->set('test_dir', $windows ? "$root\\pear\\tests" : "$root/pear/tests");
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");
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();
359 $this->_showConfig($config);
360 $this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"',
361 $command);
362 }
_showConfig(&$config)
Definition Config.php:364
$options
Definition pearcmd.php:145
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322

References $command, PEAR_Command_Common\$config, $options, and _showConfig().

Here is the call graph for this function:

◆ doConfigGet()

doConfigGet ( $command,
$options,
$params )

Definition at line 187 of file Config.php.

188 {
189 $args_cnt = is_array($params) ? count($params) : 0;
190 switch ($args_cnt) {
191 case 1:
192 $config_key = $params[0];
193 $layer = null;
194 break;
195 case 2:
196 $config_key = $params[0];
197 $layer = $params[1];
198 if ($error = $this->_checkLayer($layer)) {
199 return $this->raiseError("config-get:$error");
200 }
201 break;
202 case 0:
203 default:
204 return $this->raiseError("config-get expects 1 or 2 parameters");
205 }
206
207 $reg = &$this->config->getRegistry();
208 $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
209 if (!$reg->channelExists($channel)) {
210 return $this->raiseError('Channel "' . $channel . '" does not exist');
211 }
212
213 $channel = $reg->channelName($channel);
214 $this->ui->outputData($this->config->get($config_key, $layer, $channel), $command);
215 return true;
216 }
_checkLayer($layer=null)
Definition Config.php:403

References $command, $options, and _checkLayer().

Here is the call graph for this function:

◆ doConfigHelp()

doConfigHelp ( $command,
$options,
$params )

Definition at line 282 of file Config.php.

283 {
284 if (empty($params)) {
285 $params = $this->config->getKeys();
286 }
287
288 $data['caption'] = "Config help" . ((count($params) == 1) ? " for $params[0]" : '');
289 $data['headline'] = array('Name', 'Type', 'Description');
290 $data['border'] = true;
291 foreach ($params as $name) {
292 $type = $this->config->getType($name);
293 $docs = $this->config->getDocs($name);
294 if ($type == 'set') {
295 $docs = rtrim($docs) . "\nValid set: " .
296 implode(' ', $this->config->getSetValues($name));
297 }
298
299 $data['data'][] = array($name, $type, $docs);
300 }
301
302 $this->ui->outputData($data, $command);
303 }

References $command, and $options.

◆ doConfigSet()

doConfigSet ( $command,
$options,
$params )

Definition at line 218 of file Config.php.

219 {
220 // $param[0] -> a parameter to set
221 // $param[1] -> the value for the parameter
222 // $param[2] -> the layer
223 $failmsg = '';
224 if (count($params) < 2 || count($params) > 3) {
225 $failmsg .= "config-set expects 2 or 3 parameters";
226 return PEAR::raiseError($failmsg);
227 }
228
229 if (isset($params[2]) && ($error = $this->_checkLayer($params[2]))) {
230 $failmsg .= $error;
231 return PEAR::raiseError("config-set:$failmsg");
232 }
233
234 $channel = isset($options['channel']) ? $options['channel'] : $this->config->get('default_channel');
235 $reg = &$this->config->getRegistry();
236 if (!$reg->channelExists($channel)) {
237 return $this->raiseError('Channel "' . $channel . '" does not exist');
238 }
239
240 $channel = $reg->channelName($channel);
241 if ($params[0] == 'default_channel' && !$reg->channelExists($params[1])) {
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])
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);
257 }
258
259 if (count($params) == 2) {
260 array_push($params, 'user');
261 $layer = 'user';
262 } else {
263 $layer = $params[2];
264 }
265
266 array_push($params, $channel);
267 if (!call_user_func_array(array(&$this->config, 'set'), $params)) {
268 array_pop($params);
269 $failmsg = "config-set (" . implode(", ", $params) . ") failed, channel $channel";
270 } else {
271 $this->config->store($layer);
272 }
273
274 if ($failmsg) {
275 return $this->raiseError($failmsg);
276 }
277
278 $this->ui->outputData('config-set succeeded', $command);
279 return true;
280 }

References $command, $options, and _checkLayer().

Here is the call graph for this function:

◆ doConfigShow()

doConfigShow ( $command,
$options,
$params )

Definition at line 140 of file Config.php.

141 {
142 $layer = null;
143 if (is_array($params)) {
144 $layer = isset($params[0]) ? $params[0] : null;
145 }
146
147 // $params[0] -> the layer
148 if ($error = $this->_checkLayer($layer)) {
149 return $this->raiseError("config-show:$error");
150 }
151
152 $keys = $this->config->getKeys();
153 sort($keys);
154 $channel = isset($options['channel']) ? $options['channel'] :
155 $this->config->get('default_channel');
156 $reg = &$this->config->getRegistry();
157 if (!$reg->channelExists($channel)) {
158 return $this->raiseError('Channel "' . $channel . '" does not exist');
159 }
160
161 $channel = $reg->channelName($channel);
162 $data = array('caption' => 'Configuration (channel ' . $channel . '):');
163 foreach ($keys as $key) {
164 $type = $this->config->getType($key);
165 $value = $this->config->get($key, $layer, $channel);
166 if ($type == 'password' && $value) {
167 $value = '********';
168 }
169
170 if ($value === false) {
171 $value = 'false';
172 } elseif ($value === true) {
173 $value = 'true';
174 }
175
176 $data['data'][$this->config->getGroup($key)][] = array($this->config->getPrompt($key) , $key, $value);
177 }
178
179 foreach ($this->config->getLayers() as $layer) {
180 $data['data']['Config Files'][] = array(ucfirst($layer) . ' Configuration File', 'Filename' , $this->config->getConfFile($layer));
181 }
182
183 $this->ui->outputData($data, $command);
184 return true;
185 }

References $command, $options, and _checkLayer().

Here is the call graph for this function:

Field Documentation

◆ $commands

$commands

Definition at line 37 of file Config.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Command/Config.php