Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Console_Getopt Class Reference

Public Member Functions

 __construct ($rules, $argv=null, $getoptConfig=array())
 
 __get ($key)
 
 __isset ($key)
 
 __set ($key, $value)
 
 __toString ()
 
 __unset ($key)
 
 addArguments ($argv)
 
 setArguments ($argv)
 
 setOptions ($getoptConfig)
 
 setOption ($configKey, $configValue)
 
 addRules ($rules)
 
 toString ()
 
 toArray ()
 
 toJson ()
 
 toXml ()
 
 getOptions ()
 
 getOption ($flag)
 
 getRemainingArgs ()
 
 getUsageMessage ()
 
 setAliases ($aliasMap)
 
 setHelp ($helpMap)
 
 parse ()
 
 checkRequiredArguments ()
 

Data Fields

const MODE_ZEND = 'zend'
 
const MODE_GNU = 'gnu'
 
const PARAM_REQUIRED = '='
 
const PARAM_OPTIONAL = '-'
 
const TYPE_STRING = 's'
 
const TYPE_WORD = 'w'
 
const TYPE_INTEGER = 'i'
 
const CONFIG_RULEMODE = 'ruleMode'
 
const CONFIG_DASHDASH = 'dashDash'
 
const CONFIG_IGNORECASE = 'ignoreCase'
 
const CONFIG_PARSEALL = 'parseAll'
 

Protected Member Functions

 _parseLongOption (&$argv)
 
 _parseShortOptionCluster (&$argv)
 
 _parseSingleOption ($flag, &$argv)
 
 _checkParameterType ($flag, $param)
 
 _addRulesModeGnu ($rules)
 
 _addRulesModeZend ($rules)
 

Protected Attributes

 $_getoptConfig
 
 $_argv = array()
 
 $_progname = ''
 
 $_rules = array()
 
 $_ruleMap = array()
 
 $_options = array()
 
 $_remainingArgs = array()
 
 $_parsed = false
 

Detailed Description

Definition at line 127 of file Getopt.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $rules,
  $argv = null,
  $getoptConfig = array() 
)

The constructor takes one to three parameters.

The first parameter is $rules, which may be a string for gnu-style format, or a structured array for Zend-style format.

The second parameter is $argv, and it is optional. If not specified, $argv is inferred from the global argv.

The third parameter is an array of configuration parameters to control the behavior of this instance of Getopt; it is optional.

Parameters
array$rules
array$argv
array$getoptConfig
Returns
void

Definition at line 242 of file Getopt.php.

243  {
244  if (!isset($_SERVER['argv'])) {
245  #require_once 'Zend/Console/Getopt/Exception.php';
246  if (ini_get('register_argc_argv') == false) {
248  "argv is not available, because ini option 'register_argc_argv' is set Off"
249  );
250  } else {
252  '$_SERVER["argv"] is not set, but Zend_Console_Getopt cannot work without this information.'
253  );
254  }
255  }
256 
257  $this->_progname = $_SERVER['argv'][0];
258  $this->setOptions($getoptConfig);
259  $this->addRules($rules);
260  if (!is_array($argv)) {
261  $argv = array_slice($_SERVER['argv'], 1);
262  }
263  if (isset($argv)) {
264  $this->addArguments((array)$argv);
265  }
266  }
addArguments($argv)
Definition: Getopt.php:350
setOptions($getoptConfig)
Definition: Getopt.php:390
addRules($rules)
Definition: Getopt.php:424

Member Function Documentation

◆ __get()

__get (   $key)

Return the state of the option seen on the command line of the current application invocation. This function returns true, or the parameter to the option, if any. If the option was not given, this function returns null.

The magic __get method works in the context of naming the option as a virtual member of this class.

Parameters
string$key
Returns
string

Definition at line 280 of file Getopt.php.

281  {
282  return $this->getOption($key);
283  }

◆ __isset()

__isset (   $key)

Test whether a given option has been seen.

Parameters
string$key
Returns
boolean

Definition at line 291 of file Getopt.php.

292  {
293  $this->parse();
294  if (isset($this->_ruleMap[$key])) {
295  $key = $this->_ruleMap[$key];
296  return isset($this->_options[$key]);
297  }
298  return false;
299  }

◆ __set()

__set (   $key,
  $value 
)

Set the value for a given option.

Parameters
string$key
string$value
Returns
void

Definition at line 308 of file Getopt.php.

309  {
310  $this->parse();
311  if (isset($this->_ruleMap[$key])) {
312  $key = $this->_ruleMap[$key];
313  $this->_options[$key] = $value;
314  }
315  }
$value
Definition: gender.phtml:16

◆ __toString()

__toString ( )

Return the current set of options and parameters seen as a string.

Returns
string

Definition at line 322 of file Getopt.php.

323  {
324  return $this->toString();
325  }

◆ __unset()

__unset (   $key)

Unset an option.

Parameters
string$key
Returns
void

Definition at line 333 of file Getopt.php.

334  {
335  $this->parse();
336  if (isset($this->_ruleMap[$key])) {
337  $key = $this->_ruleMap[$key];
338  unset($this->_options[$key]);
339  }
340  }

◆ _addRulesModeGnu()

_addRulesModeGnu (   $rules)
protected

Define legal options using the gnu-style format.

Parameters
string$rules
Returns
void

Options may be single alphanumeric characters. Options may have a ':' which indicates a required string parameter. No long options or option aliases are supported in GNU style.

Definition at line 884 of file Getopt.php.

885  {
886  $ruleArray = array();
887 
893  preg_match_all('/([a-zA-Z0-9]:?)/', $rules, $ruleArray);
894  foreach ($ruleArray[1] as $rule) {
895  $r = array();
896  $flag = substr($rule, 0, 1);
897  if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
898  $flag = strtolower($flag);
899  }
900  $r['alias'][] = $flag;
901  if (substr($rule, 1, 1) == ':') {
902  $r['param'] = 'required';
903  $r['paramType'] = 'string';
904  } else {
905  $r['param'] = 'none';
906  }
907  $this->_rules[$flag] = $r;
908  $this->_ruleMap[$flag] = $flag;
909  }
910  }

◆ _addRulesModeZend()

_addRulesModeZend (   $rules)
protected

Define legal options using the Zend-style format.

Parameters
array$rules
Exceptions
Zend_Console_Getopt_Exception
Returns
void

Definition at line 919 of file Getopt.php.

920  {
921  foreach ($rules as $ruleCode => $helpMessage)
922  {
923  // this may have to translate the long parm type if there
924  // are any complaints that =string will not work (even though that use
925  // case is not documented)
926  if (in_array(substr($ruleCode, -2, 1), array('-', '='))) {
927  $flagList = substr($ruleCode, 0, -2);
928  $delimiter = substr($ruleCode, -2, 1);
929  $paramType = substr($ruleCode, -1);
930  } else {
931  $flagList = $ruleCode;
932  $delimiter = $paramType = null;
933  }
934  if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
935  $flagList = strtolower($flagList);
936  }
937  $flags = explode('|', $flagList);
938  $rule = array();
939  $mainFlag = $flags[0];
940  foreach ($flags as $flag) {
941  if (empty($flag)) {
942  #require_once 'Zend/Console/Getopt/Exception.php';
944  "Blank flag not allowed in rule \"$ruleCode\".");
945  }
946  if (strlen($flag) == 1) {
947  if (isset($this->_ruleMap[$flag])) {
948  #require_once 'Zend/Console/Getopt/Exception.php';
950  "Option \"-$flag\" is being defined more than once.");
951  }
952  $this->_ruleMap[$flag] = $mainFlag;
953  $rule['alias'][] = $flag;
954  } else {
955  if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) {
956  #require_once 'Zend/Console/Getopt/Exception.php';
958  "Option \"--$flag\" is being defined more than once.");
959  }
960  $this->_ruleMap[$flag] = $mainFlag;
961  $rule['alias'][] = $flag;
962  }
963  }
964  if (isset($delimiter)) {
965  switch ($delimiter) {
967  $rule['param'] = 'required';
968  break;
970  default:
971  $rule['param'] = 'optional';
972  }
973  switch (substr($paramType, 0, 1)) {
974  case self::TYPE_WORD:
975  $rule['paramType'] = 'word';
976  break;
977  case self::TYPE_INTEGER:
978  $rule['paramType'] = 'integer';
979  break;
980  case self::TYPE_STRING:
981  default:
982  $rule['paramType'] = 'string';
983  }
984  } else {
985  $rule['param'] = 'none';
986  }
987  $rule['help'] = $helpMessage;
988  $this->_rules[$mainFlag] = $rule;
989  }
990  }
const PARAM_OPTIONAL
Definition: Getopt.php:143
const PARAM_REQUIRED
Definition: Getopt.php:142

◆ _checkParameterType()

_checkParameterType (   $flag,
  $param 
)
protected

Return true if the parameter is in a valid format for the option $flag. Throw an exception in most other cases.

Parameters
string$flag
string$param
Exceptions
Zend_Console_Getopt_Exception
Returns
bool

Definition at line 848 of file Getopt.php.

849  {
850  $type = 'string';
851  if (isset($this->_rules[$flag]['paramType'])) {
852  $type = $this->_rules[$flag]['paramType'];
853  }
854  switch ($type) {
855  case 'word':
856  if (preg_match('/\W/', $param)) {
857  #require_once 'Zend/Console/Getopt/Exception.php';
859  "Option \"$flag\" requires a single-word parameter, but was given \"$param\".",
860  $this->getUsageMessage());
861  }
862  break;
863  case 'integer':
864  if (preg_match('/\D/', $param)) {
865  #require_once 'Zend/Console/Getopt/Exception.php';
867  "Option \"$flag\" requires an integer parameter, but was given \"$param\".",
868  $this->getUsageMessage());
869  }
870  break;
871  case 'string':
872  default:
873  break;
874  }
875  return true;
876  }
$type
Definition: item.phtml:13

◆ _parseLongOption()

_parseLongOption ( $argv)
protected

Parse command-line arguments for a single long option. A long option is preceded by a double '–' character. Long options may not be clustered.

Parameters
mixed&$argv
Returns
void

Definition at line 764 of file Getopt.php.

765  {
766  $optionWithParam = ltrim(array_shift($argv), '-');
767  $l = explode('=', $optionWithParam, 2);
768  $flag = array_shift($l);
769  $param = array_shift($l);
770  if (isset($param)) {
771  array_unshift($argv, $param);
772  }
773  $this->_parseSingleOption($flag, $argv);
774  }
_parseSingleOption($flag, &$argv)
Definition: Getopt.php:800
if(isset($opts->o)) if(! $usingStdout) $l

◆ _parseShortOptionCluster()

_parseShortOptionCluster ( $argv)
protected

Parse command-line arguments for short options. Short options are those preceded by a single '-' character. Short options may be clustered.

Parameters
mixed&$argv
Returns
void

Definition at line 784 of file Getopt.php.

785  {
786  $flagCluster = ltrim(array_shift($argv), '-');
787  foreach (str_split($flagCluster) as $flag) {
788  $this->_parseSingleOption($flag, $argv);
789  }
790  }
_parseSingleOption($flag, &$argv)
Definition: Getopt.php:800

◆ _parseSingleOption()

_parseSingleOption (   $flag,
$argv 
)
protected

Parse command-line arguments for a single option.

Parameters
string$flag
mixed$argv
Exceptions
Zend_Console_Getopt_Exception
Returns
void

Definition at line 800 of file Getopt.php.

801  {
802  if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
803  $flag = strtolower($flag);
804  }
805  if (!isset($this->_ruleMap[$flag])) {
806  #require_once 'Zend/Console/Getopt/Exception.php';
808  "Option \"$flag\" is not recognized.",
809  $this->getUsageMessage());
810  }
811  $realFlag = $this->_ruleMap[$flag];
812  switch ($this->_rules[$realFlag]['param']) {
813  case 'required':
814  if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
815  $param = array_shift($argv);
816  $this->_checkParameterType($realFlag, $param);
817  } else {
818  #require_once 'Zend/Console/Getopt/Exception.php';
820  "Option \"$flag\" requires a parameter.",
821  $this->getUsageMessage());
822  }
823  break;
824  case 'optional':
825  if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
826  $param = array_shift($argv);
827  $this->_checkParameterType($realFlag, $param);
828  } else {
829  $param = true;
830  }
831  break;
832  default:
833  $param = true;
834  }
835  $this->_options[$realFlag] = $param;
836  }
_checkParameterType($flag, $param)
Definition: Getopt.php:848

◆ addArguments()

addArguments (   $argv)

Define additional command-line arguments. These are appended to those defined when the constructor was called.

Parameters
array$argv
Exceptions
Zend_Console_Getopt_ExceptionWhen not given an array as parameter
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 350 of file Getopt.php.

351  {
352  if(!is_array($argv)) {
353  #require_once 'Zend/Console/Getopt/Exception.php';
355  "Parameter #1 to addArguments should be an array");
356  }
357  $this->_argv = array_merge($this->_argv, $argv);
358  $this->_parsed = false;
359  return $this;
360  }

◆ addRules()

addRules (   $rules)

Define additional option rules. These are appended to the rules defined when the constructor was called.

Parameters
array$rules
Returns
Zend_Console_Getopt Provides a fluent interface

Call addRulesModeFoo() for ruleMode 'foo'. The developer should subclass Getopt and provide this method.

Definition at line 424 of file Getopt.php.

425  {
426  $ruleMode = $this->_getoptConfig['ruleMode'];
427  switch ($this->_getoptConfig['ruleMode']) {
428  case self::MODE_ZEND:
429  if (is_array($rules)) {
430  $this->_addRulesModeZend($rules);
431  break;
432  }
433  // intentional fallthrough
434  case self::MODE_GNU:
435  $this->_addRulesModeGnu($rules);
436  break;
437  default:
443  $method = '_addRulesMode' . ucfirst($ruleMode);
444  $this->$method($rules);
445  }
446  $this->_parsed = false;
447  return $this;
448  }
$method
Definition: info.phtml:13
_addRulesModeGnu($rules)
Definition: Getopt.php:884
_addRulesModeZend($rules)
Definition: Getopt.php:919

◆ checkRequiredArguments()

checkRequiredArguments ( )
Exceptions
Zend_Console_Getopt_Exception

Definition at line 737 of file Getopt.php.

738  {
739  foreach ($this->_rules as $name => $rule) {
740  if ($rule['param'] === 'required') {
741  $defined = false;
742  foreach ($rule['alias'] as $alias) {
743  $defined = $defined === true ? true : array_key_exists($alias, $this->_options);
744  }
745  if ($defined === false) {
746  #require_once 'Zend/Console/Getopt/Exception.php';
748  'Option "$alias" requires a parameter.',
749  $this->getUsageMessage()
750  );
751  }
752  }
753  }
754  }
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getOption()

getOption (   $flag)

Return the state of the option seen on the command line of the current application invocation.

This function returns true, or the parameter value to the option, if any. If the option was not given, this function returns null.

Parameters
string$flag
Returns
mixed

Definition at line 558 of file Getopt.php.

559  {
560  $this->parse();
561  if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
562  $flag = strtolower($flag);
563  }
564  if (isset($this->_ruleMap[$flag])) {
565  $flag = $this->_ruleMap[$flag];
566  if (isset($this->_options[$flag])) {
567  return $this->_options[$flag];
568  }
569  }
570  return null;
571  }

◆ getOptions()

getOptions ( )

Return a list of options that have been seen in the current argv.

Returns
array

Definition at line 542 of file Getopt.php.

543  {
544  $this->parse();
545  return array_keys($this->_options);
546  }

◆ getRemainingArgs()

getRemainingArgs ( )

Return the arguments from the command-line following all options found.

Returns
array

Definition at line 578 of file Getopt.php.

579  {
580  $this->parse();
581  return $this->_remainingArgs;
582  }

◆ getUsageMessage()

getUsageMessage ( )

Return a useful option reference, formatted for display in an error message.

Note that this usage information is provided in most Exceptions generated by this class.

Returns
string

Definition at line 593 of file Getopt.php.

594  {
595  $usage = "Usage: {$this->_progname} [ options ]\n";
596  $maxLen = 20;
597  $lines = array();
598  foreach ($this->_rules as $rule) {
599  $flags = array();
600  if (is_array($rule['alias'])) {
601  foreach ($rule['alias'] as $flag) {
602  $flags[] = (strlen($flag) == 1 ? '-' : '--') . $flag;
603  }
604  }
605  $linepart['name'] = implode('|', $flags);
606  if (isset($rule['param']) && $rule['param'] != 'none') {
607  $linepart['name'] .= ' ';
608  switch ($rule['param']) {
609  case 'optional':
610  $linepart['name'] .= "[ <{$rule['paramType']}> ]";
611  break;
612  case 'required':
613  $linepart['name'] .= "<{$rule['paramType']}>";
614  break;
615  }
616  }
617  if (strlen($linepart['name']) > $maxLen) {
618  $maxLen = strlen($linepart['name']);
619  }
620  $linepart['help'] = '';
621  if (isset($rule['help'])) {
622  $linepart['help'] .= $rule['help'];
623  }
624  $lines[] = $linepart;
625  }
626  foreach ($lines as $linepart) {
627  $usage .= sprintf("%s %s\n",
628  str_pad($linepart['name'], $maxLen),
629  $linepart['help']);
630  }
631  return $usage;
632  }

◆ parse()

parse ( )

Parse command-line arguments and find both long and short options.

Also find option parameters, and remaining arguments after all options have been parsed.

Returns
Zend_Console_Getopt|null Provides a fluent interface

Definition at line 699 of file Getopt.php.

700  {
701  if ($this->_parsed === true) {
702  return;
703  }
704  $argv = $this->_argv;
705  $this->_options = array();
706  $this->_remainingArgs = array();
707  while (count($argv) > 0) {
708  if ($argv[0] == '--') {
709  array_shift($argv);
710  if ($this->_getoptConfig[self::CONFIG_DASHDASH]) {
711  $this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
712  break;
713  }
714  }
715  if (substr($argv[0], 0, 2) == '--') {
716  $this->_parseLongOption($argv);
717  } else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) {
718  $this->_parseShortOptionCluster($argv);
719  } else if($this->_getoptConfig[self::CONFIG_PARSEALL]) {
720  $this->_remainingArgs[] = array_shift($argv);
721  } else {
722  /*
723  * We should put all other arguments in _remainingArgs and stop parsing
724  * since CONFIG_PARSEALL is false.
725  */
726  $this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
727  break;
728  }
729  }
730  $this->_parsed = true;
731  return $this;
732  }
_parseLongOption(&$argv)
Definition: Getopt.php:764
_parseShortOptionCluster(&$argv)
Definition: Getopt.php:784

◆ setAliases()

setAliases (   $aliasMap)

Define aliases for options.

The parameter $aliasMap is an associative array mapping option name (short or long) to an alias.

Parameters
array$aliasMap
Exceptions
Zend_Console_Getopt_Exception
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 644 of file Getopt.php.

645  {
646  foreach ($aliasMap as $flag => $alias)
647  {
648  if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {
649  $flag = strtolower($flag);
650  $alias = strtolower($alias);
651  }
652  if (!isset($this->_ruleMap[$flag])) {
653  continue;
654  }
655  $flag = $this->_ruleMap[$flag];
656  if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) {
657  $o = (strlen($alias) == 1 ? '-' : '--') . $alias;
658  #require_once 'Zend/Console/Getopt/Exception.php';
660  "Option \"$o\" is being defined more than once.");
661  }
662  $this->_rules[$flag]['alias'][] = $alias;
663  $this->_ruleMap[$alias] = $flag;
664  }
665  return $this;
666  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ setArguments()

setArguments (   $argv)

Define full set of command-line arguments. These replace any currently defined.

Parameters
array$argv
Exceptions
Zend_Console_Getopt_ExceptionWhen not given an array as parameter
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 370 of file Getopt.php.

371  {
372  if(!is_array($argv)) {
373  #require_once 'Zend/Console/Getopt/Exception.php';
375  "Parameter #1 to setArguments should be an array");
376  }
377  $this->_argv = $argv;
378  $this->_parsed = false;
379  return $this;
380  }

◆ setHelp()

setHelp (   $helpMap)

Define help messages for options.

The parameter $help_map is an associative array mapping option name (short or long) to the help string.

Parameters
array$helpMap
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 677 of file Getopt.php.

678  {
679  foreach ($helpMap as $flag => $help)
680  {
681  if (!isset($this->_ruleMap[$flag])) {
682  continue;
683  }
684  $flag = $this->_ruleMap[$flag];
685  $this->_rules[$flag]['help'] = $help;
686  }
687  return $this;
688  }

◆ setOption()

setOption (   $configKey,
  $configValue 
)

Define one configuration option as a key/value pair. These are not program options, but properties to configure the behavior of Zend_Console_Getopt.

Parameters
string$configKey
string$configValue
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 409 of file Getopt.php.

410  {
411  if ($configKey !== null) {
412  $this->_getoptConfig[$configKey] = $configValue;
413  }
414  return $this;
415  }

◆ setOptions()

setOptions (   $getoptConfig)

Define multiple configuration options from an associative array. These are not program options, but properties to configure the behavior of Zend_Console_Getopt.

Parameters
array$getoptConfig
Returns
Zend_Console_Getopt Provides a fluent interface

Definition at line 390 of file Getopt.php.

391  {
392  if (isset($getoptConfig)) {
393  foreach ($getoptConfig as $key => $value) {
394  $this->setOption($key, $value);
395  }
396  }
397  return $this;
398  }
$value
Definition: gender.phtml:16
setOption($configKey, $configValue)
Definition: Getopt.php:409

◆ toArray()

toArray ( )

Return the current set of options and parameters seen as an array of canonical options and parameters.

Clusters have been expanded, and option aliases have been mapped to their primary option names.

Returns
array

Definition at line 474 of file Getopt.php.

475  {
476  $this->parse();
477  $s = array();
478  foreach ($this->_options as $flag => $value) {
479  $s[] = $flag;
480  if ($value !== true) {
481  $s[] = $value;
482  }
483  }
484  return $s;
485  }
$value
Definition: gender.phtml:16

◆ toJson()

toJson ( )

Return the current set of options and parameters seen in Json format.

Returns
string
See also
Zend_Json

Definition at line 492 of file Getopt.php.

493  {
494  $this->parse();
495  $j = array();
496  foreach ($this->_options as $flag => $value) {
497  $j['options'][] = array(
498  'option' => array(
499  'flag' => $flag,
500  'parameter' => $value
501  )
502  );
503  }
504 
508  #require_once 'Zend/Json.php';
509  $json = Zend_Json::encode($j);
510 
511  return $json;
512  }
$value
Definition: gender.phtml:16
static encode($valueToEncode, $cycleCheck=false, $options=array())
Definition: Json.php:130

◆ toString()

toString ( )

Return the current set of options and parameters seen as a string.

Returns
string

Definition at line 455 of file Getopt.php.

456  {
457  $this->parse();
458  $s = array();
459  foreach ($this->_options as $flag => $value) {
460  $s[] = $flag . '=' . ($value === true ? 'true' : $value);
461  }
462  return implode(' ', $s);
463  }
$value
Definition: gender.phtml:16

◆ toXml()

toXml ( )

Return the current set of options and parameters seen in XML format.

Returns
string

Definition at line 519 of file Getopt.php.

520  {
521  $this->parse();
522  $doc = new DomDocument('1.0', 'utf-8');
523  $optionsNode = $doc->createElement('options');
524  $doc->appendChild($optionsNode);
525  foreach ($this->_options as $flag => $value) {
526  $optionNode = $doc->createElement('option');
527  $optionNode->setAttribute('flag', utf8_encode($flag));
528  if ($value !== true) {
529  $optionNode->setAttribute('parameter', utf8_encode($value));
530  }
531  $optionsNode->appendChild($optionNode);
532  }
533  $xml = $doc->saveXML();
534  return $xml;
535  }
$value
Definition: gender.phtml:16

Field Documentation

◆ $_argv

$_argv = array()
protected

Definition at line 180 of file Getopt.php.

◆ $_getoptConfig

$_getoptConfig
protected
Initial value:
= array(
self::CONFIG_RULEMODE => self::MODE_ZEND,
self::CONFIG_DASHDASH => true,
self::CONFIG_IGNORECASE => false,
self::CONFIG_PARSEALL => true,
)

Defaults for getopt configuration are: ruleMode is 'zend' format, dashDash (–) token is enabled, ignoreCase is not enabled, parseAll is enabled.

Definition at line 168 of file Getopt.php.

◆ $_options

$_options = array()
protected

Definition at line 209 of file Getopt.php.

◆ $_parsed

$_parsed = false
protected

Definition at line 223 of file Getopt.php.

◆ $_progname

$_progname = ''
protected

Definition at line 187 of file Getopt.php.

◆ $_remainingArgs

$_remainingArgs = array()
protected

Definition at line 216 of file Getopt.php.

◆ $_ruleMap

$_ruleMap = array()
protected

Definition at line 201 of file Getopt.php.

◆ $_rules

$_rules = array()
protected

Definition at line 194 of file Getopt.php.

◆ CONFIG_DASHDASH

const CONFIG_DASHDASH = 'dashDash'

Definition at line 157 of file Getopt.php.

◆ CONFIG_IGNORECASE

const CONFIG_IGNORECASE = 'ignoreCase'

Definition at line 158 of file Getopt.php.

◆ CONFIG_PARSEALL

const CONFIG_PARSEALL = 'parseAll'

Definition at line 159 of file Getopt.php.

◆ CONFIG_RULEMODE

const CONFIG_RULEMODE = 'ruleMode'

These are constants for optional behavior of this class. ruleMode is either 'zend' or 'gnu' or a user-defined mode. dashDash is true if '–' signifies the end of command-line options. ignoreCase is true if '–opt' and '–OPT' are implicitly synonyms. parseAll is true if all options on the command line should be parsed, regardless of whether an argument appears before them.

Definition at line 156 of file Getopt.php.

◆ MODE_GNU

const MODE_GNU = 'gnu'

Definition at line 136 of file Getopt.php.

◆ MODE_ZEND

const MODE_ZEND = 'zend'

The options for a given application can be in multiple formats. modeGnu is for traditional 'ab:c:' style getopt format. modeZend is for a more structured format.

Definition at line 135 of file Getopt.php.

◆ PARAM_OPTIONAL

const PARAM_OPTIONAL = '-'

Definition at line 143 of file Getopt.php.

◆ PARAM_REQUIRED

const PARAM_REQUIRED = '='

Constant tokens for various symbols used in the mode_zend rule format.

Definition at line 142 of file Getopt.php.

◆ TYPE_INTEGER

const TYPE_INTEGER = 'i'

Definition at line 146 of file Getopt.php.

◆ TYPE_STRING

const TYPE_STRING = 's'

Definition at line 144 of file Getopt.php.

◆ TYPE_WORD

const TYPE_WORD = 'w'

Definition at line 145 of file Getopt.php.


The documentation for this class was generated from the following file: