⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getopt.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     * @param  string $key     * @return void     */    public function __unset($key)    {        $this->parse();        if (isset($this->_ruleMap[$key])) {            $key = $this->_ruleMap[$key];            unset($this->_options[$key]);        }    }    /**     * Define additional command-line arguments.     * These are appended to those defined when the constructor was called.     *     * @param  array $argv     * @return Zend_Console_Getopt Provides a fluent interface     */    public function addArguments($argv)    {        $this->_argv = array_merge($this->_argv, $argv);        $this->_parsed = false;        return $this;    }    /**     * Define full set of command-line arguments.     * These replace any currently defined.     *     * @param  array $argv     * @return Zend_Console_Getopt Provides a fluent interface     */    public function setArguments($argv)    {        $this->_argv = $argv;        $this->_parsed = false;        return $this;    }    /**     * Define multiple configuration options from an associative array.     * These are not program options, but properties to configure     * the behavior of Zend_Console_Getopt.     *     * @param  array $getoptConfig     * @return Zend_Console_Getopt Provides a fluent interface     */    public function setOptions($getoptConfig)    {        if (isset($getoptConfig)) {            foreach ($getoptConfig as $key => $value) {                $this->setOption($key, $value);            }        }        return $this;    }    /**     * Define one configuration option as a key/value pair.     * These are not program options, but properties to configure     * the behavior of Zend_Console_Getopt.     *     * @param  string $configKey     * @param  string $configValue     * @return Zend_Console_Getopt Provides a fluent interface     */    public function setOption($configKey, $configValue)    {        if ($configKey !== null) {            $this->_getoptConfig[$configKey] = $configValue;        }        return $this;    }    /**     * Define additional option rules.     * These are appended to the rules defined when the constructor was called.     *     * @param  array $rules     * @return Zend_Console_Getopt Provides a fluent interface     */    public function addRules($rules)    {        $ruleMode = $this->_getoptConfig['ruleMode'];        switch ($this->_getoptConfig['ruleMode']) {            case self::MODE_ZEND:                if (is_array($rules)) {                    $this->_addRulesModeZend($rules);                    break;                }                $this->_getoptConfig['ruleMode'] = self::MODE_GNU;                // intentional fallthrough            case self::MODE_GNU:                $this->_addRulesModeGnu($rules);                break;            default:                /**                 * Call addRulesModeFoo() for ruleMode 'foo'.                 * The developer should subclass Getopt and                 * provide this method.                 */                $method = '_addRulesMode' . ucfirst($ruleMode);                $this->$method($rules);        }        $this->_parsed = false;        return $this;    }    /**     * Return the current set of options and parameters seen as a string.     *     * @return string     */    public function toString()    {        $this->parse();        $s = array();        foreach ($this->_options as $flag => $value) {            $s[] = $flag . '=' . ($value === true ? 'true' : $value);        }        return implode(' ', $s);    }    /**     * 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.     *     * @return array     */    public function toArray()    {        $this->parse();        $s = array();        foreach ($this->_options as $flag => $value) {            $s[] = $flag;            if ($value !== true) {                $s[] = $value;            }        }        return $s;    }    /**     * Return the current set of options and parameters seen in Json format.     *     * @return string     */    public function toJson()    {        $this->parse();        $j = array();        foreach ($this->_options as $flag => $value) {            $j['options'][] = array(                'option' => array(                    'flag' => $flag,                    'parameter' => $value                )            );        }        /**         * @see Zend_Json         */        require_once 'Zend/Json.php';        $json = Zend_Json::encode($j);        return $json;    }    /**     * Return the current set of options and parameters seen in XML format.     *     * @return string     */    public function toXml()    {        $this->parse();        $doc = new DomDocument('1.0', 'utf-8');        $optionsNode = $doc->createElement('options');        $doc->appendChild($optionsNode);        foreach ($this->_options as $flag => $value) {            $optionNode = $doc->createElement('option');            $optionNode->setAttribute('flag', utf8_encode($flag));            if ($value !== true) {                $optionNode->setAttribute('parameter', utf8_encode($value));            }            $optionsNode->appendChild($optionNode);        }        $xml = $doc->saveXML();        return $xml;    }    /**     * Return a list of options that have been seen in the current argv.     *     * @return array     */    public function getOptions()    {        $this->parse();        return array_keys($this->_options);    }    /**     * 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 false.     *     * @param  string $flag     * @return mixed     */    public function getOption($flag)    {        $this->parse();        if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {            $flag = strtolower($flag);        }        if (isset($this->_ruleMap[$flag])) {            $flag = $this->_ruleMap[$flag];            if (isset($this->_options[$flag])) {                return $this->_options[$flag];            }        }        return null;    }    /**     * Return the arguments from the command-line following all options found.     *     * @return array     */    public function getRemainingArgs()    {        $this->parse();        return $this->_remainingArgs;    }    /**     * 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.     *     * @return string     */    public function getUsageMessage()    {        $usage = "Usage: {$this->_progname} [ options ]\n";        $maxLen = 20;        foreach ($this->_rules as $rule) {            $flags = array();            if (is_array($rule['alias'])) {                foreach ($rule['alias'] as $flag) {                    $flags[] = (strlen($flag) == 1 ? '-' : '--') . $flag;                }            }            $linepart['name'] = implode('|', $flags);            if (isset($rule['param']) && $rule['param'] != 'none') {                $linepart['name'] .= ' ';                switch ($rule['param']) {                    case 'optional':                        $linepart['name'] .= "[ <{$rule['paramType']}> ]";                        break;                    case 'required':                        $linepart['name'] .= "<{$rule['paramType']}>";                        break;                }            }            if (strlen($linepart['name']) > $maxLen) {                $maxLen = strlen($linepart['name']);            }            $linepart['help'] = '';            if (isset($rule['help'])) {                $linepart['help'] .= $rule['help'];            }            $lines[] = $linepart;        }        foreach ($lines as $linepart) {            $usage .= sprintf("%s %s\n",            str_pad($linepart['name'], $maxLen),            $linepart['help']);        }        return $usage;    }    /**     * Define aliases for options.     *     * The parameter $aliasMap is an associative array     * mapping option name (short or long) to an alias.     *     * @param  array $aliasMap     * @throws Zend_Console_Getopt_Exception     * @return Zend_Console_Getopt Provides a fluent interface     */    public function setAliases($aliasMap)    {        foreach ($aliasMap as $flag => $alias)        {            if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) {                $flag = strtolower($flag);                $alias = strtolower($alias);            }            if (!isset($this->_ruleMap[$flag])) {                continue;            }            $flag = $this->_ruleMap[$flag];            if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) {                $o = (strlen($alias) == 1 ? '-' : '--') . $alias;                /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -