kahlan\cli\CommandLine::option PHP Méthode

option() public méthode

Gets/Sets/Overrides an option's attributes.
public option ( string $name = null, array $config = [], $value = null ) : array
$name string The name of the option.
$config array The option attributes to set.
Résultat array
    public function option($name = null, $config = [], $value = null)
    {
        $defaults = ['type' => 'string', 'group' => false, 'array' => false, 'value' => null, 'default' => null];
        if (func_num_args() === 1) {
            if (isset($this->_options[$name])) {
                return $this->_options[$name];
            }
            return $defaults;
        }
        $config = is_array($config) ? $config + $defaults : [$config => $value] + $this->option($name);
        $this->_options[$name] = $config;
        list($key, $extra) = $this->_splitOptionName($name);
        if ($extra) {
            $this->option($key, ['group' => true, 'array' => true]);
        }
        if ($config['default'] !== null) {
            $this->_defaults[$key][$extra] = $this->_get($name);
        }
        return $config;
    }

Usage Example

Exemple #1
0
 /**
  * Load the config.
  *
  * @param string $argv The command line string.
  */
 public function loadConfig($argv = [])
 {
     $commandLine = new CommandLine();
     $commandLine->option('config', ['default' => 'kahlan-config.php']);
     $commandLine->option('help', ['type' => 'boolean']);
     $commandLine->option('version', ['type' => 'boolean']);
     $commandLine->parse($argv);
     $run = function ($commandLine) {
         if (file_exists($commandLine->get('config'))) {
             require $commandLine->get('config');
         }
     };
     $run($commandLine);
     $this->_commandLine->parse($argv, false);
     if ($commandLine->get('help')) {
         return $this->_help();
     }
     if ($commandLine->get('version')) {
         return $this->_version();
     }
 }
All Usage Examples Of kahlan\cli\CommandLine::option