PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Adding Configuration

The third parameter to the Zend_Console_Getopt constructor is an array of configuration options that affect the behavior of the object instance returned. You can also specify configuration options using the setOptions() method, or you can set an individual option using the setOption() method.

Clarifying the Term "option"

The term "option" is used for configuration of the Zend_Console_Getopt class to match terminology used elsewhere in Zend Framework. These are not the same things as the command-line options that are parsed by the Zend_Console_Getopt class.

The currently supported options have const definitions in the class. The options, their const identifiers (with literal values in parentheses) are listed below:

  • Zend_Console_Getopt::CONFIG_DASHDASH ("dashDash"), if TRUE, enables the special flag -- to signify the end of flags. Command-line arguments following the double-dash signifier are not interpreted as options, even if the arguments start with a dash. This configuration option is TRUE by default.

  • Zend_Console_Getopt::CONFIG_IGNORECASE ("ignoreCase"), if TRUE, makes flags aliases of each other if they differ only in their case. That is, -a and -A will be considered to be synonymous flags. This configuration option is FALSE by default.

  • Zend_Console_Getopt::CONFIG_RULEMODE ("ruleMode") may have values Zend_Console_Getopt::MODE_ZEND ("zend") and Zend_Console_Getopt::MODE_GNU ("gnu"). It should not be necessary to use this option unless you extend the class with additional syntax forms. The two modes supported in the base Zend_Console_Getopt class are unambiguous. If the specifier is a string, the class assumes MODE_GNU, otherwise it assumes MODE_ZEND. But if you extend the class and add more syntax forms, you may need to specify the mode using this option.

More configuration options may be added as future enhancements of this class.

The two arguments to the setOption() method are a configuration option name and an option value.

Example 136. Using setOption()

<?php
$opts 
= new Zend_Console_Getopt('abp:');
$opts->setOption('ignoreCase'true);

The argument to the setOptions() method is an associative array. The keys of this array are the configuration option names, and the values are configuration values. This is also the array format used in the class constructor. The configuration values you specify are merged with the current configuration; you don't have to list all options.

Example 137. Using setOptions()

<?php
$opts 
= new Zend_Console_Getopt('abp:');
$opts->setOptions(
    array(
        
'ignoreCase' => true,
        
'dashDash'   => false
    
)
);

Zend Framework