From e399c2a12a6fead6f6b75ec142ae0bb70c1b299c Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 28 Apr 2009 10:23:49 +0000 Subject: [PATCH 01/98] [DOCUMENTATION] English: - fixed title tags git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15234 44c647ce-9c0f-0410-b52a-842ac1e357ba --- .coveralls.yml | 3 + .gitattributes | 6 + .gitignore | 14 + .php_cs | 43 ++ .travis.yml | 35 ++ CONTRIBUTING.md | 229 ++++++++++ LICENSE.txt | 27 ++ README.md | 7 + composer.json | 39 ++ phpunit.xml.dist | 38 ++ phpunit.xml.travis | 41 ++ src/Getopt.php | 946 +++++++++++++++++++++++++++++++++++++++ src/Getopt/Exception.php | 65 +++ test/GetoptTest.php | 573 ++++++++++++++++++++++++ test/bootstrap.php | 34 ++ 15 files changed, 2100 insertions(+) create mode 100644 .coveralls.yml create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .php_cs create mode 100644 .travis.yml create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 phpunit.xml.travis create mode 100644 src/Getopt.php create mode 100644 src/Getopt/Exception.php create mode 100644 test/GetoptTest.php create mode 100644 test/bootstrap.php diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..53bda82 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +coverage_clover: clover.xml +json_path: coveralls-upload.json +src_dir: src diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..85dc9a8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +/test export-ignore +/vendor export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +.php_cs export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cac0a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +.buildpath +.DS_Store +.idea +.project +.settings/ +.*.sw* +.*.un~ +nbproject +tmp/ + +clover.xml +coveralls-upload.json +phpunit.xml +vendor diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..bf4b799 --- /dev/null +++ b/.php_cs @@ -0,0 +1,43 @@ +notPath('TestAsset') + ->notPath('_files') + ->filter(function (SplFileInfo $file) { + if (strstr($file->getPath(), 'compatibility')) { + return false; + } + }); +$config = Symfony\CS\Config\Config::create(); +$config->level(null); +$config->fixers( + array( + 'braces', + 'duplicate_semicolon', + 'elseif', + 'empty_return', + 'encoding', + 'eof_ending', + 'function_call_space', + 'function_declaration', + 'indentation', + 'join_function', + 'line_after_namespace', + 'linefeed', + 'lowercase_keywords', + 'parenthesis', + 'multiple_use', + 'method_argument_space', + 'object_operator', + 'php_closing_tag', + 'psr0', + 'remove_lines_between_uses', + 'short_tag', + 'standardize_not_equal', + 'trailing_spaces', + 'unused_use', + 'visibility', + 'whitespacy_lines', + ) +); +$config->finder($finder); +return $config; diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fe909ec --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +sudo: false + +language: php + +matrix: + fast_finish: true + include: + - php: 5.5 + - php: 5.6 + env: + - EXECUTE_TEST_COVERALLS=true + - EXECUTE_CS_CHECK=true + - php: 7 + - php: hhvm + allow_failures: + - php: 7 + - php: hhvm + +notifications: + irc: "irc.freenode.org#zftalk.dev" + email: false + +before_install: + - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi + +install: + - composer install --no-interaction --prefer-source + +script: + - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis --coverage-clover clover.xml ; fi + - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis ; fi + - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run --config-file=.php_cs ; fi + +after_script: + - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..08c292c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,229 @@ +# CONTRIBUTING + +## RESOURCES + +If you wish to contribute to Zend Framework, please be sure to +read/subscribe to the following resources: + + - [Coding Standards](https://github.com/zendframework/zf2/wiki/Coding-Standards) + - [Contributor's Guide](http://framework.zend.com/participate/contributor-guide) + - ZF Contributor's mailing list: + Archives: http://zend-framework-community.634137.n4.nabble.com/ZF-Contributor-f680267.html + Subscribe: zf-contributors-subscribe@lists.zend.com + - ZF Contributor's IRC channel: + #zftalk.dev on Freenode.net + +If you are working on new features or refactoring [create a proposal](https://github.com/zendframework/zend-console/issues/new). + +## Reporting Potential Security Issues + +If you have encountered a potential security vulnerability, please **DO NOT** report it on the public +issue tracker: send it to us at [zf-security@zend.com](mailto:zf-security@zend.com) instead. +We will work with you to verify the vulnerability and patch it as soon as possible. + +When reporting issues, please provide the following information: + +- Component(s) affected +- A description indicating how to reproduce the issue +- A summary of the security vulnerability and impact + +We request that you contact us via the email address above and give the project +contributors a chance to resolve the vulnerability and issue a new release prior +to any public exposure; this helps protect users and provides them with a chance +to upgrade and/or update in order to protect their applications. + +For sensitive email communications, please use [our PGP key](http://framework.zend.com/zf-security-pgp-key.asc). + +## RUNNING TESTS + +> ### Note: testing versions prior to 2.4 +> +> This component originates with Zend Framework 2. During the lifetime of ZF2, +> testing infrastructure migrated from PHPUnit 3 to PHPUnit 4. In most cases, no +> changes were necessary. However, due to the migration, tests may not run on +> versions < 2.4. As such, you may need to change the PHPUnit dependency if +> attempting a fix on such a version. + +To run tests: + +- Clone the repository: + + ```console + $ git clone git@github.com:zendframework/zend-console.git + $ cd + ``` + +- Install dependencies via composer: + + ```console + $ curl -sS https://getcomposer.org/installer | php -- + $ ./composer.phar install + ``` + + If you don't have `curl` installed, you can also download `composer.phar` from https://getcomposer.org/ + +- Run the tests via `phpunit` and the provided PHPUnit config, like in this example: + + ```console + $ ./vendor/bin/phpunit + ``` + +You can turn on conditional tests with the phpunit.xml file. +To do so: + + - Copy `phpunit.xml.dist` file to `phpunit.xml` + - Edit `phpunit.xml` to enable any specific functionality you + want to test, as well as to provide test values to utilize. + +## Running Coding Standards Checks + +This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding +standards checks, and provides configuration for our selected checks. +`php-cs-fixer` is installed by default via Composer. + +To run checks only: + +```console +$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs +``` + +To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run` +flag: + +```console +$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs +``` + +If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure +they pass, and make sure you add and commit the changes after verification. + +## Recommended Workflow for Contributions + +Your first step is to establish a public repository from which we can +pull your work into the master repository. We recommend using +[GitHub](https://github.com), as that is where the component is already hosted. + +1. Setup a [GitHub account](http://github.com/), if you haven't yet +2. Fork the repository (http://github.com/zendframework/zend-console) +3. Clone the canonical repository locally and enter it. + + ```console + $ git clone git://github.com:zendframework/zend-console.git + $ cd zend-console + ``` + +4. Add a remote to your fork; substitute your GitHub username in the command + below. + + ```console + $ git remote add {username} git@github.com:{username}/zend-console.git + $ git fetch {username} + ``` + +### Keeping Up-to-Date + +Periodically, you should update your fork or personal repository to +match the canonical ZF repository. Assuming you have setup your local repository +per the instructions above, you can do the following: + + +```console +$ git checkout master +$ git fetch origin +$ git rebase origin/master +# OPTIONALLY, to keep your remote up-to-date - +$ git push {username} master:master +``` + +If you're tracking other branches -- for example, the "develop" branch, where +new feature development occurs -- you'll want to do the same operations for that +branch; simply substitute "develop" for "master". + +### Working on a patch + +We recommend you do each new feature or bugfix in a new branch. This simplifies +the task of code review as well as the task of merging your changes into the +canonical repository. + +A typical workflow will then consist of the following: + +1. Create a new local branch based off either your master or develop branch. +2. Switch to your new local branch. (This step can be combined with the + previous step with the use of `git checkout -b`.) +3. Do some work, commit, repeat as necessary. +4. Push the local branch to your remote repository. +5. Send a pull request. + +The mechanics of this process are actually quite trivial. Below, we will +create a branch for fixing an issue in the tracker. + +```console +$ git checkout -b hotfix/9295 +Switched to a new branch 'hotfix/9295' +``` + +... do some work ... + + +```console +$ git commit +``` + +... write your log message ... + + +```console +$ git push {username} hotfix/9295:hotfix/9295 +Counting objects: 38, done. +Delta compression using up to 2 threads. +Compression objects: 100% (18/18), done. +Writing objects: 100% (20/20), 8.19KiB, done. +Total 20 (delta 12), reused 0 (delta 0) +To ssh://git@github.com/{username}/zend-console.git + b5583aa..4f51698 HEAD -> master +``` + +To send a pull request, you have two options. + +If using GitHub, you can do the pull request from there. Navigate to +your repository, select the branch you just created, and then select the +"Pull Request" button in the upper right. Select the user/organization +"zendframework" as the recipient. + +If using your own repository - or even if using GitHub - you can use `git +format-patch` to create a patchset for us to apply; in fact, this is +**recommended** for security-related patches. If you use `format-patch`, please +send the patches as attachments to: + +- zf-devteam@zend.com for patches without security implications +- zf-security@zend.com for security patches + +#### What branch to issue the pull request against? + +Which branch should you issue a pull request against? + +- For fixes against the stable release, issue the pull request against the + "master" branch. +- For new features, or fixes that introduce new elements to the public API (such + as new public methods or properties), issue the pull request against the + "develop" branch. + +### Branch Cleanup + +As you might imagine, if you are a frequent contributor, you'll start to +get a ton of branches both locally and on your remote. + +Once you know that your changes have been accepted to the master +repository, we suggest doing some cleanup of these branches. + +- Local branch cleanup + + ```console + $ git branch -d + ``` + +- Remote branch removal + + ```console + $ git push {username} : + ``` diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..6eab5aa --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2005-2015, Zend Technologies USA, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..511b519 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# zend-console + +`Zend\Console` is a component to design and implement console applications in PHP. + + +- File issues at https://github.com/zendframework/zend-console/issues +- Documentation is at http://framework.zend.com/manual/current/en/index.html#zend-console diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7f1496e --- /dev/null +++ b/composer.json @@ -0,0 +1,39 @@ +{ + "name": "zendframework/zend-console", + "description": "Zend\\Console component", + "license": "BSD-3-Clause", + "keywords": [ + "zf2", + "console" + ], + "homepage": "https://github.com/zendframework/zend-console", + "autoload": { + "psr-4": { + "Zend\\Console\\": "src/" + } + }, + "require": { + "php": ">=5.3.23", + "zendframework/zend-stdlib": "self.version" + }, + "suggest": { + "zendframework/zend-validator": "To support DefaultRouteMatcher usage", + "zendframework/zend-filter": "To support DefaultRouteMatcher usage" + }, + "extra": { + "branch-alias": { + "dev-master": "2.4-dev", + "dev-develop": "2.5-dev" + } + }, + "require-dev": { + "fabpot/php-cs-fixer": "1.7.*", + "satooshi/php-coveralls": "dev-master", + "phpunit/PHPUnit": "~4.0" + }, + "autoload-dev": { + "psr-4": { + "ZendTest\\Console\\": "test/" + } + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..5f07027 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,38 @@ + + + + + ./test/ + + + + + + disable + + + + + + ./src + + + + + + + + + + + + + diff --git a/phpunit.xml.travis b/phpunit.xml.travis new file mode 100644 index 0000000..7cc7f91 --- /dev/null +++ b/phpunit.xml.travis @@ -0,0 +1,41 @@ + + + + + ./test/ + + + + + + disable + + + + + + ./src + + + + + + + + + + + + + + diff --git a/src/Getopt.php b/src/Getopt.php new file mode 100644 index 0000000..3bff496 --- /dev/null +++ b/src/Getopt.php @@ -0,0 +1,946 @@ + self::MODE_ZEND, + self::CONFIG_DASHDASH => true, + self::CONFIG_IGNORECASE => false + ); + + /** + * Stores the command-line arguments for the calling applicaion. + * + * @var array + */ + protected $_argv = array(); + + /** + * Stores the name of the calling applicaion. + * + * @var string + */ + protected $_progname = ''; + + /** + * Stores the list of legal options for this application. + * + * @var array + */ + protected $_rules = array(); + + /** + * Stores alternate spellings of legal options. + * + * @var array + */ + protected $_ruleMap = array(); + + /** + * Stores options given by the user in the current invocation + * of the application, as well as parameters given in options. + * + * @var array + */ + protected $_options = array(); + + /** + * Stores the command-line arguments other than options. + * + * @var array + */ + protected $_remainingArgs = array(); + + /** + * State of the options: parsed or not yet parsed? + * + * @var boolean + */ + protected $_parsed = false; + + /** + * 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. + * + * @param array $rules + * @param array $argv + * @param array $getoptConfig + * @return void + */ + public function __construct($rules, $argv = null, $getoptConfig = array()) + { + if (!isset($_SERVER['argv'])) { + require_once 'Zend/Console/Getopt/Exception.php'; + if(ini_get('register_argc_argv') == false) { + throw new Zend_Console_Getopt_Exception( + "argv is not available, because ini option 'register_argc_argv' is set Off" + ); + } else { + throw new Zend_Console_Getopt_Exception( + '$_SERVER["argv"] is not set, but Zend_Console_Getopt cannot work without this information.' + ); + } + } + + $this->_progname = $_SERVER['argv'][0]; + $this->setOptions($getoptConfig); + $this->addRules($rules); + if (!is_array($argv)) { + $argv = array_slice($_SERVER['argv'], 1); + } + if (isset($argv)) { + $this->addArguments((array)$argv); + } + } + + /** + * 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. + * + * @param string $key + * @return string + */ + public function __get($key) + { + return $this->getOption($key); + } + + /** + * Test whether a given option has been seen. + * + * @param string $key + * @return boolean + */ + public function __isset($key) + { + $this->parse(); + if (isset($this->_ruleMap[$key])) { + $key = $this->_ruleMap[$key]; + return isset($this->_options[$key]); + } + return false; + } + + /** + * Set the value for a given option. + * + * @param string $key + * @param string $value + * @return void + */ + public function __set($key, $value) + { + $this->parse(); + if (isset($this->_ruleMap[$key])) { + $key = $this->_ruleMap[$key]; + $this->_options[$key] = $value; + } + } + + /** + * Return the current set of options and parameters seen as a string. + * + * @return string + */ + public function __toString() + { + return $this->toString(); + } + + /** + * Unset an option. + * + * @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; + } + // 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; + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"$o\" is being defined more than once."); + } + $this->_rules[$flag]['alias'][] = $alias; + $this->_ruleMap[$alias] = $flag; + } + return $this; + } + + /** + * Define help messages for options. + * + * The parameter $help_map is an associative array + * mapping option name (short or long) to the help string. + * + * @param array $helpMap + * @return Zend_Console_Getopt Provides a fluent interface + */ + public function setHelp($helpMap) + { + foreach ($helpMap as $flag => $help) + { + if (!isset($this->_ruleMap[$flag])) { + continue; + } + $flag = $this->_ruleMap[$flag]; + $this->_rules[$flag]['help'] = $help; + } + return $this; + } + + /** + * Parse command-line arguments and find both long and short + * options. + * + * Also find option parameters, and remaining arguments after + * all options have been parsed. + * + * @return Zend_Console_Getopt|null Provides a fluent interface + */ + public function parse() + { + if ($this->_parsed === true) { + return; + } + $argv = $this->_argv; + $this->_options = array(); + $this->_remainingArgs = array(); + while (count($argv) > 0) { + if ($argv[0] == '--') { + array_shift($argv); + if ($this->_getoptConfig[self::CONFIG_DASHDASH]) { + $this->_remainingArgs = array_merge($this->_remainingArgs, $argv); + break; + } + } + if (substr($argv[0], 0, 2) == '--') { + $this->_parseLongOption($argv); + } else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) { + $this->_parseShortOptionCluster($argv); + } else { + $this->_remainingArgs[] = array_shift($argv); + } + } + $this->_parsed = true; + return $this; + } + + /** + * Parse command-line arguments for a single long option. + * A long option is preceded by a double '--' character. + * Long options may not be clustered. + * + * @param mixed &$argv + * @return void + */ + protected function _parseLongOption(&$argv) + { + $optionWithParam = ltrim(array_shift($argv), '-'); + $l = explode('=', $optionWithParam, 2); + $flag = array_shift($l); + $param = array_shift($l); + if (isset($param)) { + array_unshift($argv, $param); + } + $this->_parseSingleOption($flag, $argv); + } + + /** + * Parse command-line arguments for short options. + * Short options are those preceded by a single '-' character. + * Short options may be clustered. + * + * @param mixed &$argv + * @return void + */ + protected function _parseShortOptionCluster(&$argv) + { + $flagCluster = ltrim(array_shift($argv), '-'); + foreach (str_split($flagCluster) as $flag) { + $this->_parseSingleOption($flag, $argv); + } + } + + /** + * Parse command-line arguments for a single option. + * + * @param string $flag + * @param mixed $argv + * @throws Zend_Console_Getopt_Exception + * @return void + */ + protected function _parseSingleOption($flag, &$argv) + { + if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) { + $flag = strtolower($flag); + } + if (!isset($this->_ruleMap[$flag])) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"$flag\" is not recognized.", + $this->getUsageMessage()); + } + $realFlag = $this->_ruleMap[$flag]; + switch ($this->_rules[$realFlag]['param']) { + case 'required': + if (count($argv) > 0) { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"$flag\" requires a parameter.", + $this->getUsageMessage()); + } + break; + case 'optional': + if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { + $param = true; + } + break; + default: + $param = true; + } + $this->_options[$realFlag] = $param; + } + + /** + * Return true if the parameter is in a valid format for + * the option $flag. + * Throw an exception in most other cases. + * + * @param string $flag + * @param string $param + * @throws Zend_Console_Getopt_Exception + * @return bool + */ + protected function _checkParameterType($flag, $param) + { + $type = 'string'; + if (isset($this->_rules[$flag]['paramType'])) { + $type = $this->_rules[$flag]['paramType']; + } + switch ($type) { + case 'word': + if (preg_match('/\W/', $param)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"$flag\" requires a single-word parameter, but was given \"$param\".", + $this->getUsageMessage()); + } + break; + case 'integer': + if (preg_match('/\D/', $param)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"$flag\" requires an integer parameter, but was given \"$param\".", + $this->getUsageMessage()); + } + break; + case 'string': + default: + break; + } + return true; + } + + /** + * Define legal options using the gnu-style format. + * + * @param string $rules + * @return void + */ + protected function _addRulesModeGnu($rules) + { + $ruleArray = array(); + + /** + * 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. + */ + preg_match_all('/([a-zA-Z0-9]:?)/', $rules, $ruleArray); + foreach ($ruleArray[1] as $rule) { + $r = array(); + $flag = substr($rule, 0, 1); + if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) { + $flag = strtolower($flag); + } + $r['alias'][] = $flag; + if (substr($rule, 1, 1) == ':') { + $r['param'] = 'required'; + $r['paramType'] = 'string'; + } else { + $r['param'] = 'none'; + } + $this->_rules[$flag] = $r; + $this->_ruleMap[$flag] = $flag; + } + } + + /** + * Define legal options using the Zend-style format. + * + * @param array $rules + * @throws Zend_Console_Getopt_Exception + * @return void + */ + protected function _addRulesModeZend($rules) + { + foreach ($rules as $ruleCode => $helpMessage) + { + // this may have to translate the long parm type if there + // are any complaints that =string will not work (even though that use + // case is not documented) + if (in_array(substr($ruleCode, -2, 1), array('-', '='))) { + $flagList = substr($ruleCode, 0, -2); + $delimiter = substr($ruleCode, -2, 1); + $paramType = substr($ruleCode, -1); + } else { + $flagList = $ruleCode; + $delimiter = $paramType = null; + } + if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) { + $flagList = strtolower($flagList); + } + $flags = explode('|', $flagList); + $rule = array(); + $mainFlag = $flags[0]; + foreach ($flags as $flag) { + if (empty($flag)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Blank flag not allowed in rule \"$ruleCode\"."); + } + if (strlen($flag) == 1) { + if (isset($this->_ruleMap[$flag])) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"-$flag\" is being defined more than once."); + } + $this->_ruleMap[$flag] = $mainFlag; + $rule['alias'][] = $flag; + } else { + if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Option \"--$flag\" is being defined more than once."); + } + $this->_ruleMap[$flag] = $mainFlag; + $rule['alias'][] = $flag; + } + } + if (isset($delimiter)) { + switch ($delimiter) { + case self::PARAM_REQUIRED: + $rule['param'] = 'required'; + break; + case self::PARAM_OPTIONAL: + default: + $rule['param'] = 'optional'; + } + switch (substr($paramType, 0, 1)) { + case self::TYPE_WORD: + $rule['paramType'] = 'word'; + break; + case self::TYPE_INTEGER: + $rule['paramType'] = 'integer'; + break; + case self::TYPE_STRING: + default: + $rule['paramType'] = 'string'; + } + } else { + $rule['param'] = 'none'; + } + $rule['help'] = $helpMessage; + $this->_rules[$mainFlag] = $rule; + } + } + +} diff --git a/src/Getopt/Exception.php b/src/Getopt/Exception.php new file mode 100644 index 0000000..6e3509f --- /dev/null +++ b/src/Getopt/Exception.php @@ -0,0 +1,65 @@ +usage = $usage; + parent::__construct($message); + } + + /** + * Returns the usage + * + * @return string + */ + public function getUsageMessage() + { + return $this->usage; + } +} diff --git a/test/GetoptTest.php b/test/GetoptTest.php new file mode 100644 index 0000000..d3f556e --- /dev/null +++ b/test/GetoptTest.php @@ -0,0 +1,573 @@ +markTestSkipped("Cannot Test Zend_Console_Getopt without 'register_argc_argv' ini option true."); + } + } + + public function testGetoptShortOptionsGnuMode() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals(true, $opts->a); + $this->assertNull(@$opts->b); + $this->assertEquals($opts->p, 'p_arg'); + } + + public function testGetoptLongOptionsZendMode() + { + $opts = new Zend_Console_Getopt(array( + 'apple|a' => 'Apple option', + 'banana|b' => 'Banana option', + 'pear|p=s' => 'Pear option' + ), + array('-a', '-p', 'p_arg')); + $this->assertTrue($opts->apple); + $this->assertNull(@$opts->banana); + $this->assertEquals($opts->pear, 'p_arg'); + } + + public function testGetoptZendModeEqualsParam() + { + $opts = new Zend_Console_Getopt(array( + 'apple|a' => 'Apple option', + 'banana|b' => 'Banana option', + 'pear|p=s' => 'Pear option' + ), + array('--pear=pear.phpunit.de')); + $this->assertEquals($opts->pear, 'pear.phpunit.de'); + } + + public function testGetoptToString() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals($opts->__toString(), 'a=true p=p_arg'); + } + + public function testGetoptDumpString() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals($opts->toString(), 'a=true p=p_arg'); + } + + public function testGetoptDumpArray() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals(implode(',', $opts->toArray()), 'a,p,p_arg'); + } + + public function testGetoptDumpJson() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals($opts->toJson(), + '{"options":[{"option":{"flag":"a","parameter":true}},{"option":{"flag":"p","parameter":"p_arg"}}]}'); + + } + + public function testGetoptDumpXml() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals($opts->toXml(), + "\n\n"); + } + + public function testGetoptExceptionForMissingFlag() + { + try { + $opts = new Zend_Console_Getopt(array('|a'=>'Apple option')); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), + 'Blank flag not allowed in rule "|a".'); + } + } + + public function testGetoptExceptionForDuplicateFlag() + { + try { + $opts = new Zend_Console_Getopt( + array('apple|apple'=>'apple-option')); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), + 'Option "--apple" is being defined more than once.'); + } + + try { + $opts = new Zend_Console_Getopt( + array('a'=>'Apple option', 'apple|a'=>'Apple option')); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), + 'Option "-a" is being defined more than once.'); + } + } + + public function testGetoptAddRules() + { + $opts = new Zend_Console_Getopt( + array( + 'apple|a' => 'Apple option', + 'banana|b' => 'Banana option' + ), + array('--pear', 'pear_param')); + try { + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "pear" is not recognized.'); + } + $opts->addRules(array('pear|p=s' => 'Pear option')); + $this->assertEquals($opts->pear, 'pear_param'); + } + + public function testGetoptExceptionMissingParameter() + { + $opts = new Zend_Console_Getopt( + array( + 'apple|a=s' => 'Apple with required parameter', + 'banana|b' => 'Banana' + ), + array('--apple')); + try { + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "apple" requires a parameter.'); + } + } + + public function testGetoptOptionalParameter() + { + $opts = new Zend_Console_Getopt( + array( + 'apple|a-s' => 'Apple with optional parameter', + 'banana|b' => 'Banana' + ), + array('--apple', '--banana')); + $this->assertTrue($opts->apple); + $this->assertTrue($opts->banana); + } + + public function testGetoptIgnoreCaseGnuMode() + { + $opts = new Zend_Console_Getopt('aB', array('-A', '-b'), + array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + $this->assertEquals(true, $opts->a); + $this->assertEquals(true, $opts->B); + } + + public function testGetoptIgnoreCaseZendMode() + { + $opts = new Zend_Console_Getopt( + array( + 'apple|a' => 'Apple-option', + 'Banana|B' => 'Banana-option' + ), + array('--Apple', '--bAnaNa'), + array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + $this->assertEquals(true, $opts->apple); + $this->assertEquals(true, $opts->BANANA); + } + + public function testGetoptIsSet() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $this->assertTrue(isset($opts->a)); + $this->assertFalse(isset($opts->b)); + } + + public function testGetoptIsSetAlias() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts->setAliases(array('a' => 'apple', 'b' => 'banana')); + $this->assertTrue(isset($opts->apple)); + $this->assertFalse(isset($opts->banana)); + } + + public function testGetoptIsSetInvalid() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts->setAliases(array('a' => 'apple', 'b' => 'banana')); + $this->assertFalse(isset($opts->cumquat)); + } + + public function testGetoptSet() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $this->assertFalse(isset($opts->b)); + $opts->b = true; + $this->assertTrue(isset($opts->b)); + } + + public function testGetoptSetBeforeParse() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts->b = true; + $this->assertTrue(isset($opts->b)); + } + + public function testGetoptUnSet() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + $this->assertTrue(isset($opts->a)); + unset($opts->a); + $this->assertFalse(isset($opts->a)); + } + + public function testGetoptUnSetBeforeParse() + { + $opts = new Zend_Console_Getopt('ab', array('-a')); + unset($opts->a); + $this->assertFalse(isset($opts->a)); + } + + public function testGetoptAddArguments() + { + $opts = new Zend_Console_Getopt('abp:', array('-a')); + $this->assertNull(@$opts->p); + $opts->addArguments(array('-p', 'p_arg')); + $this->assertEquals($opts->p, 'p_arg'); + } + + public function testGetoptRemainingArgs() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '--', 'file1', 'file2')); + $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2'); + $opts = new Zend_Console_Getopt('abp:', array('-a', 'file1', 'file2')); + $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2'); + } + + public function testGetoptDashDashFalse() + { + try { + $opts = new Zend_Console_Getopt('abp:', array('-a', '--', '--fakeflag'), + array(Zend_Console_Getopt::CONFIG_DASHDASH => false)); + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "fakeflag" is not recognized.'); + } + } + + public function testGetoptGetOptions() + { + $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->assertEquals(implode(',', $opts->getOptions()), 'a,p'); + } + + public function testGetoptGetUsageMessage() + { + $opts = new Zend_Console_Getopt('abp:', array('-x')); + $message = preg_replace('/Usage: .* \[ options \]/', + 'Usage: [ options ]', + $opts->getUsageMessage()); + $message = preg_replace('/ /', '_', $message); + $this->assertEquals($message, + "Usage:__[_options_]\n-a___________________\n-b___________________\n-p___________\n"); + } + + public function testGetoptUsageMessageFromException() + { + try { + $opts = new Zend_Console_Getopt(array( + 'apple|a-s' => 'apple', + 'banana1|banana2|banana3|banana4' => 'banana', + 'pear=s' => 'pear'), + array('-x')); + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $message = preg_replace('/Usage: .* \[ options \]/', + 'Usage: [ options ]', + $e->getUsageMessage()); + $message = preg_replace('/ /', '_', $message); + $this->assertEquals($message, + "Usage:__[_options_]\n--apple|-a_[__]_________________apple\n--banana1|--banana2|--banana3|--banana4_banana\n--pear__________________________pear\n"); + + } + } + + public function testGetoptSetAliases() + { + $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $opts->setAliases(array('a' => 'apple')); + $this->assertTrue($opts->a); + } + + public function testGetoptSetAliasesIgnoreCase() + { + $opts = new Zend_Console_Getopt('abp:', array('--apple'), + array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + $opts->setAliases(array('a' => 'APPLE')); + $this->assertTrue($opts->apple); + } + + public function testGetoptSetAliasesWithNamingConflict() + { + $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $opts->setAliases(array('a' => 'apple')); + try { + $opts->setAliases(array('b' => 'apple')); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "--apple" is being defined more than once.'); + } + } + + public function testGetoptSetAliasesInvalid() + { + $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $opts->setAliases(array('c' => 'cumquat')); + $opts->setArguments(array('-c')); + try { + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals('Option "c" is not recognized.', $e->getMessage()); + } + } + + public function testGetoptSetHelp() + { + $opts = new Zend_Console_Getopt('abp:', array('-a')); + $opts->setHelp(array( + 'a' => 'apple', + 'b' => 'banana', + 'p' => 'pear')); + $message = preg_replace('/Usage: .* \[ options \]/', + 'Usage: [ options ]', + $opts->getUsageMessage()); + $message = preg_replace('/ /', '_', $message); + $this->assertEquals($message, + "Usage:__[_options_]\n-a___________________apple\n-b___________________banana\n-p___________pear\n"); + + } + + public function testGetoptSetHelpInvalid() + { + $opts = new Zend_Console_Getopt('abp:', array('-a')); + $opts->setHelp(array( + 'a' => 'apple', + 'b' => 'banana', + 'p' => 'pear', + 'c' => 'cumquat')); + $message = preg_replace('/Usage: .* \[ options \]/', + 'Usage: [ options ]', + $opts->getUsageMessage()); + $message = preg_replace('/ /', '_', $message); + $this->assertEquals($message, + "Usage:__[_options_]\n-a___________________apple\n-b___________________banana\n-p___________pear\n"); + } + + public function testGetoptCheckParameterType() + { + $opts = new Zend_Console_Getopt(array( + 'apple|a=i' => 'apple with integer', + 'banana|b=w' => 'banana with word', + 'pear|p=s' => 'pear with string', + 'orange|o-i' => 'orange with optional integer', + 'lemon|l-w' => 'lemon with optional word', + 'kumquat|k-s' => 'kumquat with optional string')); + + $opts->setArguments(array('-a', 327)); + $opts->parse(); + $this->assertEquals(327, $opts->a); + + $opts->setArguments(array('-a', 'noninteger')); + try { + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "apple" requires an integer parameter, but was given "noninteger".'); + } + + $opts->setArguments(array('-b', 'word')); + $this->assertEquals('word', $opts->b); + + $opts->setArguments(array('-b', 'two words')); + try { + $opts->parse(); + $this->fail('Expected to catch Zend_Console_Getopt_Exception'); + } catch (Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->assertEquals($e->getMessage(), 'Option "banana" requires a single-word parameter, but was given "two words".'); + } + + $opts->setArguments(array('-p', 'string')); + $this->assertEquals('string', $opts->p); + + $opts->setArguments(array('-o', 327)); + $this->assertEquals(327, $opts->o); + + $opts->setArguments(array('-o')); + $this->assertTrue($opts->o); + + $opts->setArguments(array('-l', 'word')); + $this->assertEquals('word', $opts->l); + + $opts->setArguments(array('-k', 'string')); + $this->assertEquals('string', $opts->k); + + } + + /** + * @group ZF-2295 + */ + public function testRegisterArgcArgvOffThrowsException() + { + $argv = $_SERVER['argv']; + unset($_SERVER['argv']); + + try { + $opts = new Zend_Console_GetOpt('abp:'); + $this->fail(); + } catch(Zend_Console_GetOpt_Exception $e) { + $this->assertContains('$_SERVER["argv"]', $e->getMessage()); + } + + $_SERVER['argv'] = $argv; + } + + /** + * Test to ensure that dashed long names will parse correctly + * + * @group ZF-4763 + */ + public function testDashWithinLongOptionGetsParsed() + { + $opts = new Zend_Console_Getopt( + array( // rules + 'man-bear|m-s' => 'ManBear with dash', + 'man-bear-pig|b=s' => 'ManBearPid with dash', + ), + array( // arguments + '--man-bear-pig=mbp', + '--man-bear', + 'foobar' + ) + ); + + $opts->parse(); + $this->assertEquals('foobar', $opts->getOption('man-bear')); + $this->assertEquals('mbp', $opts->getOption('man-bear-pig')); + } + + /** + * @group ZF-2064 + */ + public function testAddRulesDoesNotThrowWarnings() + { + // Fails if warning is thrown: Should not happen! + $opts = new Zend_Console_Getopt('abp:'); + $opts->addRules( + array( + 'verbose|v' => 'Print verbose output' + ) + ); + } + + /** + * @group ZF-5345 + */ + public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemainingArgument() + { + $opts = new Zend_Console_Getopt("abp:", array("-")); + $opts->parse(); + + $this->assertEquals(1, count($opts->getRemainingArgs())); + $this->assertEquals(array("-"), $opts->getRemainingArgs()); + } + + /** + * @group ZF-5345 + */ + public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException() + { + $opts = new Zend_Console_Getopt("abp:", array("-", "file1")); + try { + $opts->parse(); + $this->fail(); + } catch(Exception $e) { + $this->assertTrue($e instanceof Zend_Console_Getopt_Exception); + } + } + + /** + * @group ZF-5624 + */ + public function testEqualsCharacterInLongOptionsValue() + { + $fooValue = 'some text containing an = sign which breaks'; + + $opts = new Zend_Console_Getopt( + array('foo=s' => 'Option One (string)'), + array('--foo='.$fooValue) + ); + $this->assertEquals($fooValue, $opts->foo); + } +} diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..c09729d --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,34 @@ + Date: Mon, 11 May 2009 16:33:25 +0000 Subject: [PATCH 02/98] ZF-6610 - Supplied fix for allowing processing for unknown arguments (originally commited by wil to incubator for Zend_Build development) git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15528 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 3bff496..abdd0e1 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -126,6 +126,7 @@ */ class Zend_Console_Getopt { + /** * The options for a given application can be in multiple formats. * modeGnu is for traditional 'ab:c:' style getopt format. @@ -149,23 +150,26 @@ class Zend_Console_Getopt * 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. */ const CONFIG_RULEMODE = 'ruleMode'; const CONFIG_DASHDASH = 'dashDash'; const CONFIG_IGNORECASE = 'ignoreCase'; + const CONFIG_PARSEALL = 'parseAll'; /** * Defaults for getopt configuration are: * ruleMode is 'zend' format, * dashDash (--) token is enabled, - * ignoreCase is not enabled. - * - * @var array Config + * ignoreCase is not enabled, + * parseAll is enabled. */ protected $_getoptConfig = array( self::CONFIG_RULEMODE => self::MODE_ZEND, self::CONFIG_DASHDASH => true, - self::CONFIG_IGNORECASE => false + self::CONFIG_IGNORECASE => false, + self::CONFIG_PARSEALL => true ); /** @@ -699,8 +703,15 @@ public function parse() $this->_parseLongOption($argv); } else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) { $this->_parseShortOptionCluster($argv); - } else { + } else if($this->_getoptConfig[self::CONFIG_PARSEALL]) { $this->_remainingArgs[] = array_shift($argv); + } else { + /* + * We should put all other arguments in _remainingArgs and stop parsing + * since CONFIG_PARSEALL is false. + */ + $this->_remainingArgs = array_merge($this->_remainingArgs, $argv); + break; } } $this->_parsed = true; From 35a9b2ad64928fe5e111ede3b9588bf846b606d1 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 21 Jun 2009 18:51:15 +0000 Subject: [PATCH 03/98] [ZF-6295] Generic: - fixed license date (partitial) git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16201 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 4 ++-- src/Getopt/Exception.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index abdd0e1..f409bd4 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -15,7 +15,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: $ */ @@ -80,7 +80,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version Release: @package_version@ * @since Class available since Release 0.6.0 diff --git a/src/Getopt/Exception.php b/src/Getopt/Exception.php index 6e3509f..b6de9f5 100644 --- a/src/Getopt/Exception.php +++ b/src/Getopt/Exception.php @@ -14,7 +14,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -28,7 +28,7 @@ /** * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Console_Getopt_Exception extends Zend_Exception From 8d41bb8c52f49d3fdb12677a86f037e07d5065c1 Mon Sep 17 00:00:00 2001 From: bkarwin Date: Tue, 7 Jul 2009 06:59:03 +0000 Subject: [PATCH 04/98] ZF-507 update @copyright and other tags git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16541 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt/Exception.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Getopt/Exception.php b/src/Getopt/Exception.php index b6de9f5..053200e 100644 --- a/src/Getopt/Exception.php +++ b/src/Getopt/Exception.php @@ -16,6 +16,7 @@ * @package Zend_Console_Getopt * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ */ From fd772677fb846a5fc0a6eaa27ba6cc19bd4cdac1 Mon Sep 17 00:00:00 2001 From: matthew Date: Tue, 21 Jul 2009 20:24:35 +0000 Subject: [PATCH 05/98] [TESTS] Scrubbed test suite to ensure it can run with or without output buffering, and so that no tests fail when run as a full suite git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16933 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 4 ++-- test/GetoptTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index f409bd4..cdc6965 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -169,7 +169,7 @@ class Zend_Console_Getopt self::CONFIG_RULEMODE => self::MODE_ZEND, self::CONFIG_DASHDASH => true, self::CONFIG_IGNORECASE => false, - self::CONFIG_PARSEALL => true + self::CONFIG_PARSEALL => true, ); /** @@ -243,7 +243,7 @@ public function __construct($rules, $argv = null, $getoptConfig = array()) { if (!isset($_SERVER['argv'])) { require_once 'Zend/Console/Getopt/Exception.php'; - if(ini_get('register_argc_argv') == false) { + if (ini_get('register_argc_argv') == false) { throw new Zend_Console_Getopt_Exception( "argv is not available, because ini option 'register_argc_argv' is set Off" ); diff --git a/test/GetoptTest.php b/test/GetoptTest.php index d3f556e..0944334 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -47,6 +47,7 @@ public function setUp() if(ini_get('register_argc_argv') == false) { $this->markTestSkipped("Cannot Test Zend_Console_Getopt without 'register_argc_argv' ini option true."); } + $_SERVER['argv'] = array('getopttest'); } public function testGetoptShortOptionsGnuMode() From 6bf4f3894d6580aaf15fe676ca3a137375544a31 Mon Sep 17 00:00:00 2001 From: mikaelkael Date: Wed, 22 Jul 2009 18:05:45 +0000 Subject: [PATCH 06/98] ZF-7335: add svn:keyword Id for all files without it git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16971 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index cdc6965..0936a3e 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -17,7 +17,7 @@ * @package Zend_Console_Getopt * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: $ + * @version $Id$ */ /** From 91cb4256a7492beb767bf9a8f6b699d7c9efe90a Mon Sep 17 00:00:00 2001 From: alexander Date: Thu, 13 Aug 2009 18:01:41 +0000 Subject: [PATCH 07/98] Merge cs-17363 back to trunk. [ZF-7581] related. git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17573 44c647ce-9c0f-0410-b52a-842ac1e357ba --- test/GetoptTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 0944334..4b8e2ca 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -13,9 +13,9 @@ * to license@zend.com so we can send you a copy immediately. * * @category Zend - * @package Zend + * @package Zend_Console_Getop * @subpackage UnitTests - * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -39,6 +39,9 @@ * @category Zend * @package Zend_Console_Getopt * @subpackage UnitTests + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @group Zend_Console_Getopt */ class Zend_Console_GetoptTest extends PHPUnit_Framework_TestCase { From 0b2b6af1809c10204350d6a8c44f502b233efa66 Mon Sep 17 00:00:00 2001 From: alexander Date: Thu, 12 Nov 2009 15:37:56 +0000 Subject: [PATCH 08/98] Remove trailing whitespaces, change tab for spaces, convert CRLF to LF. ZF-7316 related. git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18950 44c647ce-9c0f-0410-b52a-842ac1e357ba --- test/GetoptTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 4b8e2ca..c3a606b 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -358,7 +358,7 @@ public function testGetoptSetAliases() public function testGetoptSetAliasesIgnoreCase() { - $opts = new Zend_Console_Getopt('abp:', array('--apple'), + $opts = new Zend_Console_Getopt('abp:', array('--apple'), array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); $opts->setAliases(array('a' => 'APPLE')); $this->assertTrue($opts->apple); @@ -404,7 +404,7 @@ public function testGetoptSetHelp() 'Usage: [ options ]', $opts->getUsageMessage()); $message = preg_replace('/ /', '_', $message); - $this->assertEquals($message, + $this->assertEquals($message, "Usage:__[_options_]\n-a___________________apple\n-b___________________banana\n-p___________pear\n"); } @@ -421,7 +421,7 @@ public function testGetoptSetHelpInvalid() 'Usage: [ options ]', $opts->getUsageMessage()); $message = preg_replace('/ /', '_', $message); - $this->assertEquals($message, + $this->assertEquals($message, "Usage:__[_options_]\n-a___________________apple\n-b___________________banana\n-p___________pear\n"); } @@ -496,10 +496,10 @@ public function testRegisterArgcArgvOffThrowsException() $_SERVER['argv'] = $argv; } - + /** * Test to ensure that dashed long names will parse correctly - * + * * @group ZF-4763 */ public function testDashWithinLongOptionGetsParsed() @@ -515,7 +515,7 @@ public function testDashWithinLongOptionGetsParsed() 'foobar' ) ); - + $opts->parse(); $this->assertEquals('foobar', $opts->getOption('man-bear')); $this->assertEquals('mbp', $opts->getOption('man-bear-pig')); @@ -560,7 +560,7 @@ public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException() $this->assertTrue($e instanceof Zend_Console_Getopt_Exception); } } - + /** * @group ZF-5624 */ From eb6e454ceb2d0848b8c728fec48a6bfa78b6ef91 Mon Sep 17 00:00:00 2001 From: mluiten Date: Fri, 18 Dec 2009 21:26:29 +0000 Subject: [PATCH 09/98] [ZF-5948] Neverending loop in ->parse(). Fixed by introducing Exception on wrong parameter. git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19764 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 12 ++++++++++++ test/GetoptTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Getopt.php b/src/Getopt.php index 0936a3e..8082159 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -344,10 +344,16 @@ public function __unset($key) * These are appended to those defined when the constructor was called. * * @param array $argv + * @throws Zend_Console_Getopt_Exception When not given an array as parameter * @return Zend_Console_Getopt Provides a fluent interface */ public function addArguments($argv) { + if(!is_array($argv)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Parameter #1 to addArguments should be an array"); + } $this->_argv = array_merge($this->_argv, $argv); $this->_parsed = false; return $this; @@ -358,10 +364,16 @@ public function addArguments($argv) * These replace any currently defined. * * @param array $argv + * @throws Zend_Console_Getopt_Exception When not given an array as parameter * @return Zend_Console_Getopt Provides a fluent interface */ public function setArguments($argv) { + if(!is_array($argv)) { + require_once 'Zend/Console/Getopt/Exception.php'; + throw new Zend_Console_Getopt_Exception( + "Parameter #1 to setArguments should be an array"); + } $this->_argv = $argv; $this->_parsed = false; return $this; diff --git a/test/GetoptTest.php b/test/GetoptTest.php index c3a606b..a7fa245 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -278,6 +278,34 @@ public function testGetoptUnSetBeforeParse() unset($opts->a); $this->assertFalse(isset($opts->a)); } + + /** + * @group ZF-5948 + */ + public function testGetoptAddSetNonArrayArguments() + { + $opts = new Zend_Console_GetOpt('abp:', array('-foo')); + try { + $opts->setArguments('-a'); + $this->fail('Expected to catch a Zend_Console_Getopt_Exception'); + } catch(Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); + $this->assertEquals("Parameter #1 to setArguments should be an array", + $e->getMessage()); + } + + try { + $opts->addArguments('-b'); + $this->fail('Expected to catch a Zend_Console_Getopt_Exception'); + } catch(Zend_Exception $e) { + $this->assertType('Zend_Console_Getopt_Exception', $e, + 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); + $this->assertEquals("Parameter #1 to addArguments should be an array", + $e->getMessage()); + } + + } public function testGetoptAddArguments() { From 82548e835c3601874b31a5a2acfea9419b0afc60 Mon Sep 17 00:00:00 2001 From: bkarwin Date: Wed, 6 Jan 2010 02:05:09 +0000 Subject: [PATCH 10/98] [ZF-8718] update copyright tags for 2010 git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20096 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 4 ++-- src/Getopt/Exception.php | 4 ++-- test/GetoptTest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 8082159..595a6f0 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -15,7 +15,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -80,7 +80,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version Release: @package_version@ * @since Class available since Release 0.6.0 diff --git a/src/Getopt/Exception.php b/src/Getopt/Exception.php index 053200e..0785600 100644 --- a/src/Getopt/Exception.php +++ b/src/Getopt/Exception.php @@ -14,7 +14,7 @@ * * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -29,7 +29,7 @@ /** * @category Zend * @package Zend_Console_Getopt - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Console_Getopt_Exception extends Zend_Exception diff --git a/test/GetoptTest.php b/test/GetoptTest.php index a7fa245..b1546b8 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -15,7 +15,7 @@ * @category Zend * @package Zend_Console_Getop * @subpackage UnitTests - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id$ */ @@ -39,7 +39,7 @@ * @category Zend * @package Zend_Console_Getopt * @subpackage UnitTests - * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Console_Getopt */ From 52a50a13abdb7ba10d2cd6b5e33f48d3e62d4200 Mon Sep 17 00:00:00 2001 From: matthew Date: Wed, 3 Mar 2010 20:46:05 +0000 Subject: [PATCH 11/98] [2.0] Stripped require_once calls (skipping Zend_Gdata, Zend_Pdf, Zend_Search, and Zend_Service components) git-svn-id: http://framework.zend.com/svn/framework/standard/branches/development-2.0@21309 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 18 ++---------------- src/Getopt/Exception.php | 8 +------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 595a6f0..70f75f9 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -123,6 +123,8 @@ * * @todo Feature request to implement callbacks. * e.g. if -a is specified, run function 'handleOptionA'(). + * @uses Zend_Console_Getopt_Exception + * @uses Zend_Json */ class Zend_Console_Getopt { @@ -242,7 +244,6 @@ class Zend_Console_Getopt public function __construct($rules, $argv = null, $getoptConfig = array()) { if (!isset($_SERVER['argv'])) { - require_once 'Zend/Console/Getopt/Exception.php'; if (ini_get('register_argc_argv') == false) { throw new Zend_Console_Getopt_Exception( "argv is not available, because ini option 'register_argc_argv' is set Off" @@ -350,7 +351,6 @@ public function __unset($key) public function addArguments($argv) { if(!is_array($argv)) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Parameter #1 to addArguments should be an array"); } @@ -370,7 +370,6 @@ public function addArguments($argv) public function setArguments($argv) { if(!is_array($argv)) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Parameter #1 to setArguments should be an array"); } @@ -502,12 +501,7 @@ public function toJson() ); } - /** - * @see Zend_Json - */ - require_once 'Zend/Json.php'; $json = Zend_Json::encode($j); - return $json; } @@ -654,7 +648,6 @@ public function setAliases($aliasMap) $flag = $this->_ruleMap[$flag]; if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) { $o = (strlen($alias) == 1 ? '-' : '--') . $alias; - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"$o\" is being defined more than once."); } @@ -780,7 +773,6 @@ protected function _parseSingleOption($flag, &$argv) $flag = strtolower($flag); } if (!isset($this->_ruleMap[$flag])) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"$flag\" is not recognized.", $this->getUsageMessage()); @@ -792,7 +784,6 @@ protected function _parseSingleOption($flag, &$argv) $param = array_shift($argv); $this->_checkParameterType($realFlag, $param); } else { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"$flag\" requires a parameter.", $this->getUsageMessage()); @@ -831,7 +822,6 @@ protected function _checkParameterType($flag, $param) switch ($type) { case 'word': if (preg_match('/\W/', $param)) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"$flag\" requires a single-word parameter, but was given \"$param\".", $this->getUsageMessage()); @@ -839,7 +829,6 @@ protected function _checkParameterType($flag, $param) break; case 'integer': if (preg_match('/\D/', $param)) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"$flag\" requires an integer parameter, but was given \"$param\".", $this->getUsageMessage()); @@ -916,13 +905,11 @@ protected function _addRulesModeZend($rules) $mainFlag = $flags[0]; foreach ($flags as $flag) { if (empty($flag)) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Blank flag not allowed in rule \"$ruleCode\"."); } if (strlen($flag) == 1) { if (isset($this->_ruleMap[$flag])) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"-$flag\" is being defined more than once."); } @@ -930,7 +917,6 @@ protected function _addRulesModeZend($rules) $rule['alias'][] = $flag; } else { if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) { - require_once 'Zend/Console/Getopt/Exception.php'; throw new Zend_Console_Getopt_Exception( "Option \"--$flag\" is being defined more than once."); } diff --git a/src/Getopt/Exception.php b/src/Getopt/Exception.php index 0785600..2cc3449 100644 --- a/src/Getopt/Exception.php +++ b/src/Getopt/Exception.php @@ -19,14 +19,8 @@ * @version $Id$ */ - -/** - * @see Zend_Console_Getopt_Exception - */ -require_once 'Zend/Exception.php'; - - /** + * @uses Zend_Exception * @category Zend * @package Zend_Console_Getopt * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) From b21f27bffe6df7f0cac21106bacc0fb4e48d0d81 Mon Sep 17 00:00:00 2001 From: matthew Date: Mon, 8 Mar 2010 20:36:57 +0000 Subject: [PATCH 12/98] [2.0] Updated test suite - Created phpunit.xml - Renamed TestHelper.php Bootstrap.php; latter now referenced in phpunit.xml - Uses autoloading - Stripped require_once calls globally (will need to run individual groups iteratively to determine if any test caes are missing necessary calls) - Controller tests now run (but 4 new errors) git-svn-id: http://framework.zend.com/svn/framework/standard/branches/development-2.0@21390 44c647ce-9c0f-0410-b52a-842ac1e357ba --- test/GetoptTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index b1546b8..f6815c5 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -23,17 +23,14 @@ /** * Test helper */ -require_once dirname(__FILE__) . '/../../TestHelper.php'; /** * Zend_Console_Getopt */ -require_once 'Zend/Console/Getopt.php'; /** * PHPUnit test case */ -require_once 'PHPUnit/Framework/TestCase.php'; /** * @category Zend From b8b5f2bb0c640fde7095aa9dd1b03d6cdfdc4147 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 26 Mar 2010 12:53:24 -0400 Subject: [PATCH 13/98] Added PHPTools submodule --- .gitmodules | 3 +++ tools/phptools | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 tools/phptools diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..21d57da --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/phptools"] + path = tools/phptools + url = git://github.com/ralphschindler/PHPTools.git diff --git a/tools/phptools b/tools/phptools new file mode 160000 index 0000000..685f0e0 --- /dev/null +++ b/tools/phptools @@ -0,0 +1 @@ +Subproject commit 685f0e09aabbc45d82d3836aefc82be1efddb513 From 2f138a77ef400fcadcdbe1d731085816cfb930c8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 26 Mar 2010 13:49:44 -0400 Subject: [PATCH 14/98] Updated PHPTools --- tools/phptools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/phptools b/tools/phptools index 685f0e0..d232cb3 160000 --- a/tools/phptools +++ b/tools/phptools @@ -1 +1 @@ -Subproject commit 685f0e09aabbc45d82d3836aefc82be1efddb513 +Subproject commit d232cb3e4f1448daccefc74882da1862cda7656f From e2d22c356844794893da0c8453f9fac28d4d6be8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 2 Apr 2010 14:20:01 -0400 Subject: [PATCH 15/98] [NS4] Migrated Zend_Console to namespaces --- src/Exception.php | 36 +++ src/Getopt.php | 72 ++--- .../Exception.php => GetoptException.php} | 9 +- test/GetoptTest.php | 252 ++++++------------ 4 files changed, 169 insertions(+), 200 deletions(-) create mode 100644 src/Exception.php rename src/{Getopt/Exception.php => GetoptException.php} (90%) diff --git a/src/Exception.php b/src/Exception.php new file mode 100644 index 0000000..bc64abe --- /dev/null +++ b/src/Exception.php @@ -0,0 +1,36 @@ +_argv = array_merge($this->_argv, $argv); @@ -364,13 +369,13 @@ public function addArguments($argv) * These replace any currently defined. * * @param array $argv - * @throws Zend_Console_Getopt_Exception When not given an array as parameter - * @return Zend_Console_Getopt Provides a fluent interface + * @throws \Zend\Console\Getopt\Exception When not given an array as parameter + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function setArguments($argv) { if(!is_array($argv)) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Parameter #1 to setArguments should be an array"); } $this->_argv = $argv; @@ -384,7 +389,7 @@ public function setArguments($argv) * the behavior of Zend_Console_Getopt. * * @param array $getoptConfig - * @return Zend_Console_Getopt Provides a fluent interface + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function setOptions($getoptConfig) { @@ -403,7 +408,7 @@ public function setOptions($getoptConfig) * * @param string $configKey * @param string $configValue - * @return Zend_Console_Getopt Provides a fluent interface + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function setOption($configKey, $configValue) { @@ -418,7 +423,7 @@ public function setOption($configKey, $configValue) * These are appended to the rules defined when the constructor was called. * * @param array $rules - * @return Zend_Console_Getopt Provides a fluent interface + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function addRules($rules) { @@ -501,7 +506,7 @@ public function toJson() ); } - $json = Zend_Json::encode($j); + $json = \Zend\Json\Json::encode($j); return $json; } @@ -513,7 +518,7 @@ public function toJson() public function toXml() { $this->parse(); - $doc = new DomDocument('1.0', 'utf-8'); + $doc = new \DomDocument('1.0', 'utf-8'); $optionsNode = $doc->createElement('options'); $doc->appendChild($optionsNode); foreach ($this->_options as $flag => $value) { @@ -631,8 +636,8 @@ public function getUsageMessage() * 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 + * @throws \Zend\Console\Getopt\Exception + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function setAliases($aliasMap) { @@ -648,7 +653,7 @@ public function setAliases($aliasMap) $flag = $this->_ruleMap[$flag]; if (isset($this->_rules[$alias]) || isset($this->_ruleMap[$alias])) { $o = (strlen($alias) == 1 ? '-' : '--') . $alias; - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"$o\" is being defined more than once."); } $this->_rules[$flag]['alias'][] = $alias; @@ -664,7 +669,7 @@ public function setAliases($aliasMap) * mapping option name (short or long) to the help string. * * @param array $helpMap - * @return Zend_Console_Getopt Provides a fluent interface + * @return \Zend\Console\Getopt\Getopt Provides a fluent interface */ public function setHelp($helpMap) { @@ -686,7 +691,7 @@ public function setHelp($helpMap) * Also find option parameters, and remaining arguments after * all options have been parsed. * - * @return Zend_Console_Getopt|null Provides a fluent interface + * @return \Zend\Console\Getopt\Getopt|null Provides a fluent interface */ public function parse() { @@ -764,7 +769,7 @@ protected function _parseShortOptionCluster(&$argv) * * @param string $flag * @param mixed $argv - * @throws Zend_Console_Getopt_Exception + * @throws \Zend\Console\Getopt\Exception * @return void */ protected function _parseSingleOption($flag, &$argv) @@ -773,7 +778,7 @@ protected function _parseSingleOption($flag, &$argv) $flag = strtolower($flag); } if (!isset($this->_ruleMap[$flag])) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"$flag\" is not recognized.", $this->getUsageMessage()); } @@ -784,7 +789,7 @@ protected function _parseSingleOption($flag, &$argv) $param = array_shift($argv); $this->_checkParameterType($realFlag, $param); } else { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"$flag\" requires a parameter.", $this->getUsageMessage()); } @@ -810,7 +815,7 @@ protected function _parseSingleOption($flag, &$argv) * * @param string $flag * @param string $param - * @throws Zend_Console_Getopt_Exception + * @throws \Zend\Console\Getopt\Exception * @return bool */ protected function _checkParameterType($flag, $param) @@ -822,14 +827,14 @@ protected function _checkParameterType($flag, $param) switch ($type) { case 'word': if (preg_match('/\W/', $param)) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"$flag\" requires a single-word parameter, but was given \"$param\".", $this->getUsageMessage()); } break; case 'integer': if (preg_match('/\D/', $param)) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"$flag\" requires an integer parameter, but was given \"$param\".", $this->getUsageMessage()); } @@ -879,7 +884,7 @@ protected function _addRulesModeGnu($rules) * Define legal options using the Zend-style format. * * @param array $rules - * @throws Zend_Console_Getopt_Exception + * @throws \Zend\Console\Getopt\Exception * @return void */ protected function _addRulesModeZend($rules) @@ -905,19 +910,19 @@ protected function _addRulesModeZend($rules) $mainFlag = $flags[0]; foreach ($flags as $flag) { if (empty($flag)) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Blank flag not allowed in rule \"$ruleCode\"."); } if (strlen($flag) == 1) { if (isset($this->_ruleMap[$flag])) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"-$flag\" is being defined more than once."); } $this->_ruleMap[$flag] = $mainFlag; $rule['alias'][] = $flag; } else { if (isset($this->_rules[$flag]) || isset($this->_ruleMap[$flag])) { - throw new Zend_Console_Getopt_Exception( + throw new GetoptException( "Option \"--$flag\" is being defined more than once."); } $this->_ruleMap[$flag] = $mainFlag; @@ -951,5 +956,4 @@ protected function _addRulesModeZend($rules) $this->_rules[$mainFlag] = $rule; } } - } diff --git a/src/Getopt/Exception.php b/src/GetoptException.php similarity index 90% rename from src/Getopt/Exception.php rename to src/GetoptException.php index 2cc3449..c8e08bb 100644 --- a/src/Getopt/Exception.php +++ b/src/GetoptException.php @@ -20,13 +20,18 @@ */ /** - * @uses Zend_Exception + * @namespace + */ +namespace Zend\Console; + +/** + * @uses \Zend\Exception * @category Zend * @package Zend_Console_Getopt * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class Zend_Console_Getopt_Exception extends Zend_Exception +class GetoptException extends \DomainException implements Exception { /** * Usage diff --git a/test/GetoptTest.php b/test/GetoptTest.php index f6815c5..8f13581 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -13,7 +13,7 @@ * to license@zend.com so we can send you a copy immediately. * * @category Zend - * @package Zend_Console_Getop + * @package Zend_Console * @subpackage UnitTests * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License @@ -21,38 +21,33 @@ */ /** - * Test helper - */ - -/** - * Zend_Console_Getopt - */ - -/** - * PHPUnit test case + * @namespace */ +namespace ZendTest\Console; +use Zend\Console\Getopt, + Zend\Console\GetoptException; /** * @category Zend - * @package Zend_Console_Getopt + * @package Zend_Console * @subpackage UnitTests * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @group Zend_Console_Getopt + * @group Zend_Console */ -class Zend_Console_GetoptTest extends PHPUnit_Framework_TestCase +class GetoptTest extends \PHPUnit_Framework_TestCase { public function setUp() { if(ini_get('register_argc_argv') == false) { - $this->markTestSkipped("Cannot Test Zend_Console_Getopt without 'register_argc_argv' ini option true."); + $this->markTestSkipped("Cannot Test Zend\\Console\\Getopt without 'register_argc_argv' ini option true."); } $_SERVER['argv'] = array('getopttest'); } public function testGetoptShortOptionsGnuMode() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals(true, $opts->a); $this->assertNull(@$opts->b); $this->assertEquals($opts->p, 'p_arg'); @@ -60,7 +55,7 @@ public function testGetoptShortOptionsGnuMode() public function testGetoptLongOptionsZendMode() { - $opts = new Zend_Console_Getopt(array( + $opts = new Getopt(array( 'apple|a' => 'Apple option', 'banana|b' => 'Banana option', 'pear|p=s' => 'Pear option' @@ -73,7 +68,7 @@ public function testGetoptLongOptionsZendMode() public function testGetoptZendModeEqualsParam() { - $opts = new Zend_Console_Getopt(array( + $opts = new Getopt(array( 'apple|a' => 'Apple option', 'banana|b' => 'Banana option', 'pear|p=s' => 'Pear option' @@ -84,25 +79,26 @@ public function testGetoptZendModeEqualsParam() public function testGetoptToString() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals($opts->__toString(), 'a=true p=p_arg'); } public function testGetoptDumpString() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals($opts->toString(), 'a=true p=p_arg'); } public function testGetoptDumpArray() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals(implode(',', $opts->toArray()), 'a,p,p_arg'); } public function testGetoptDumpJson() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $this->markTestIncomplete('INCOMPLETE due to waiting for Zend_Json migration to namespaces'); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals($opts->toJson(), '{"options":[{"option":{"flag":"a","parameter":true}},{"option":{"flag":"p","parameter":"p_arg"}}]}'); @@ -110,52 +106,34 @@ public function testGetoptDumpJson() public function testGetoptDumpXml() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals($opts->toXml(), "\n\n"); } public function testGetoptExceptionForMissingFlag() { - try { - $opts = new Zend_Console_Getopt(array('|a'=>'Apple option')); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), - 'Blank flag not allowed in rule "|a".'); - } + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'Blank flag not allowed in rule'); + $opts = new Getopt(array('|a'=>'Apple option')); } - public function testGetoptExceptionForDuplicateFlag() + public function testGetoptExceptionForKeyWithDuplicateFlagsViaOrOperator() { - try { - $opts = new Zend_Console_Getopt( - array('apple|apple'=>'apple-option')); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), - 'Option "--apple" is being defined more than once.'); - } + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'defined more than once'); + $opts = new Getopt( + array('apple|apple'=>'apple-option')); + } - try { - $opts = new Zend_Console_Getopt( - array('a'=>'Apple option', 'apple|a'=>'Apple option')); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), - 'Option "-a" is being defined more than once.'); - } + public function testGetoptExceptionForKeysThatDuplicateFlags() + { + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'defined more than once'); + $opts = new Getopt( + array('a'=>'Apple option', 'apple|a'=>'Apple option')); } public function testGetoptAddRules() { - $opts = new Zend_Console_Getopt( + $opts = new Getopt( array( 'apple|a' => 'Apple option', 'banana|b' => 'Banana option' @@ -163,10 +141,8 @@ public function testGetoptAddRules() array('--pear', 'pear_param')); try { $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->fail('Expected to catch Zend\\Console\\GetoptException'); + } catch (GetoptException $e) { $this->assertEquals($e->getMessage(), 'Option "pear" is not recognized.'); } $opts->addRules(array('pear|p=s' => 'Pear option')); @@ -175,25 +151,19 @@ public function testGetoptAddRules() public function testGetoptExceptionMissingParameter() { - $opts = new Zend_Console_Getopt( + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'requires a parameter'); + $opts = new Getopt( array( 'apple|a=s' => 'Apple with required parameter', 'banana|b' => 'Banana' ), array('--apple')); - try { - $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), 'Option "apple" requires a parameter.'); - } + $opts->parse(); } public function testGetoptOptionalParameter() { - $opts = new Zend_Console_Getopt( + $opts = new Getopt( array( 'apple|a-s' => 'Apple with optional parameter', 'banana|b' => 'Banana' @@ -205,35 +175,35 @@ public function testGetoptOptionalParameter() public function testGetoptIgnoreCaseGnuMode() { - $opts = new Zend_Console_Getopt('aB', array('-A', '-b'), - array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + $opts = new Getopt('aB', array('-A', '-b'), + array(Getopt::CONFIG_IGNORECASE => true)); $this->assertEquals(true, $opts->a); $this->assertEquals(true, $opts->B); } public function testGetoptIgnoreCaseZendMode() { - $opts = new Zend_Console_Getopt( + $opts = new Getopt( array( 'apple|a' => 'Apple-option', 'Banana|B' => 'Banana-option' ), array('--Apple', '--bAnaNa'), - array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + array(Getopt::CONFIG_IGNORECASE => true)); $this->assertEquals(true, $opts->apple); $this->assertEquals(true, $opts->BANANA); } public function testGetoptIsSet() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $this->assertTrue(isset($opts->a)); $this->assertFalse(isset($opts->b)); } public function testGetoptIsSetAlias() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $opts->setAliases(array('a' => 'apple', 'b' => 'banana')); $this->assertTrue(isset($opts->apple)); $this->assertFalse(isset($opts->banana)); @@ -241,14 +211,14 @@ public function testGetoptIsSetAlias() public function testGetoptIsSetInvalid() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $opts->setAliases(array('a' => 'apple', 'b' => 'banana')); $this->assertFalse(isset($opts->cumquat)); } public function testGetoptSet() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $this->assertFalse(isset($opts->b)); $opts->b = true; $this->assertTrue(isset($opts->b)); @@ -256,14 +226,14 @@ public function testGetoptSet() public function testGetoptSetBeforeParse() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $opts->b = true; $this->assertTrue(isset($opts->b)); } public function testGetoptUnSet() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); $this->assertTrue(isset($opts->a)); unset($opts->a); $this->assertFalse(isset($opts->a)); @@ -271,7 +241,7 @@ public function testGetoptUnSet() public function testGetoptUnSetBeforeParse() { - $opts = new Zend_Console_Getopt('ab', array('-a')); + $opts = new Getopt('ab', array('-a')); unset($opts->a); $this->assertFalse(isset($opts->a)); } @@ -281,32 +251,14 @@ public function testGetoptUnSetBeforeParse() */ public function testGetoptAddSetNonArrayArguments() { - $opts = new Zend_Console_GetOpt('abp:', array('-foo')); - try { - $opts->setArguments('-a'); - $this->fail('Expected to catch a Zend_Console_Getopt_Exception'); - } catch(Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); - $this->assertEquals("Parameter #1 to setArguments should be an array", - $e->getMessage()); - } - - try { - $opts->addArguments('-b'); - $this->fail('Expected to catch a Zend_Console_Getopt_Exception'); - } catch(Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '. get_class($e)); - $this->assertEquals("Parameter #1 to addArguments should be an array", - $e->getMessage()); - } - + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'should be an array'); + $opts = new Getopt('abp:', array('-foo')); + $opts->setArguments('-a'); } public function testGetoptAddArguments() { - $opts = new Zend_Console_Getopt('abp:', array('-a')); + $opts = new Getopt('abp:', array('-a')); $this->assertNull(@$opts->p); $opts->addArguments(array('-p', 'p_arg')); $this->assertEquals($opts->p, 'p_arg'); @@ -314,35 +266,29 @@ public function testGetoptAddArguments() public function testGetoptRemainingArgs() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '--', 'file1', 'file2')); + $opts = new Getopt('abp:', array('-a', '--', 'file1', 'file2')); $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2'); - $opts = new Zend_Console_Getopt('abp:', array('-a', 'file1', 'file2')); + $opts = new Getopt('abp:', array('-a', 'file1', 'file2')); $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2'); } public function testGetoptDashDashFalse() { - try { - $opts = new Zend_Console_Getopt('abp:', array('-a', '--', '--fakeflag'), - array(Zend_Console_Getopt::CONFIG_DASHDASH => false)); - $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), 'Option "fakeflag" is not recognized.'); - } + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'not recognized'); + $opts = new Getopt('abp:', array('-a', '--', '--fakeflag'), + array(Getopt::CONFIG_DASHDASH => false)); + $opts->parse(); } public function testGetoptGetOptions() { - $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg')); + $opts = new Getopt('abp:', array('-a', '-p', 'p_arg')); $this->assertEquals(implode(',', $opts->getOptions()), 'a,p'); } public function testGetoptGetUsageMessage() { - $opts = new Zend_Console_Getopt('abp:', array('-x')); + $opts = new Getopt('abp:', array('-x')); $message = preg_replace('/Usage: .* \[ options \]/', 'Usage: [ options ]', $opts->getUsageMessage()); @@ -354,16 +300,14 @@ public function testGetoptGetUsageMessage() public function testGetoptUsageMessageFromException() { try { - $opts = new Zend_Console_Getopt(array( + $opts = new Getopt(array( 'apple|a-s' => 'apple', 'banana1|banana2|banana3|banana4' => 'banana', 'pear=s' => 'pear'), array('-x')); $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->fail('Expected to catch Zend\\Console\\GetoptException'); + } catch (GetoptException $e) { $message = preg_replace('/Usage: .* \[ options \]/', 'Usage: [ options ]', $e->getUsageMessage()); @@ -376,51 +320,39 @@ public function testGetoptUsageMessageFromException() public function testGetoptSetAliases() { - $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $opts = new Getopt('abp:', array('--apple')); $opts->setAliases(array('a' => 'apple')); $this->assertTrue($opts->a); } public function testGetoptSetAliasesIgnoreCase() { - $opts = new Zend_Console_Getopt('abp:', array('--apple'), - array(Zend_Console_Getopt::CONFIG_IGNORECASE => true)); + $opts = new Getopt('abp:', array('--apple'), + array(Getopt::CONFIG_IGNORECASE => true)); $opts->setAliases(array('a' => 'APPLE')); $this->assertTrue($opts->apple); } public function testGetoptSetAliasesWithNamingConflict() { - $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'defined more than once'); + $opts = new Getopt('abp:', array('--apple')); $opts->setAliases(array('a' => 'apple')); - try { - $opts->setAliases(array('b' => 'apple')); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals($e->getMessage(), 'Option "--apple" is being defined more than once.'); - } + $opts->setAliases(array('b' => 'apple')); } public function testGetoptSetAliasesInvalid() { - $opts = new Zend_Console_Getopt('abp:', array('--apple')); + $this->setExpectedException('\\Zend\\Console\\GetoptException', 'not recognized'); + $opts = new Getopt('abp:', array('--apple')); $opts->setAliases(array('c' => 'cumquat')); $opts->setArguments(array('-c')); - try { - $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); - $this->assertEquals('Option "c" is not recognized.', $e->getMessage()); - } + $opts->parse(); } public function testGetoptSetHelp() { - $opts = new Zend_Console_Getopt('abp:', array('-a')); + $opts = new Getopt('abp:', array('-a')); $opts->setHelp(array( 'a' => 'apple', 'b' => 'banana', @@ -436,7 +368,7 @@ public function testGetoptSetHelp() public function testGetoptSetHelpInvalid() { - $opts = new Zend_Console_Getopt('abp:', array('-a')); + $opts = new Getopt('abp:', array('-a')); $opts->setHelp(array( 'a' => 'apple', 'b' => 'banana', @@ -452,7 +384,7 @@ public function testGetoptSetHelpInvalid() public function testGetoptCheckParameterType() { - $opts = new Zend_Console_Getopt(array( + $opts = new Getopt(array( 'apple|a=i' => 'apple with integer', 'banana|b=w' => 'banana with word', 'pear|p=s' => 'pear with string', @@ -467,10 +399,8 @@ public function testGetoptCheckParameterType() $opts->setArguments(array('-a', 'noninteger')); try { $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->fail('Expected to catch Zend\\Console\\GetoptException'); + } catch (GetoptException $e) { $this->assertEquals($e->getMessage(), 'Option "apple" requires an integer parameter, but was given "noninteger".'); } @@ -480,10 +410,8 @@ public function testGetoptCheckParameterType() $opts->setArguments(array('-b', 'two words')); try { $opts->parse(); - $this->fail('Expected to catch Zend_Console_Getopt_Exception'); - } catch (Zend_Exception $e) { - $this->assertType('Zend_Console_Getopt_Exception', $e, - 'Expected Zend_Console_Getopt_Exception, got '.get_class($e)); + $this->fail('Expected to catch Zend\\Console\\GetoptException'); + } catch (GetoptException $e) { $this->assertEquals($e->getMessage(), 'Option "banana" requires a single-word parameter, but was given "two words".'); } @@ -513,9 +441,9 @@ public function testRegisterArgcArgvOffThrowsException() unset($_SERVER['argv']); try { - $opts = new Zend_Console_GetOpt('abp:'); + $opts = new GetOpt('abp:'); $this->fail(); - } catch(Zend_Console_GetOpt_Exception $e) { + } catch(GetoptException $e) { $this->assertContains('$_SERVER["argv"]', $e->getMessage()); } @@ -529,7 +457,7 @@ public function testRegisterArgcArgvOffThrowsException() */ public function testDashWithinLongOptionGetsParsed() { - $opts = new Zend_Console_Getopt( + $opts = new Getopt( array( // rules 'man-bear|m-s' => 'ManBear with dash', 'man-bear-pig|b=s' => 'ManBearPid with dash', @@ -552,7 +480,7 @@ public function testDashWithinLongOptionGetsParsed() public function testAddRulesDoesNotThrowWarnings() { // Fails if warning is thrown: Should not happen! - $opts = new Zend_Console_Getopt('abp:'); + $opts = new Getopt('abp:'); $opts->addRules( array( 'verbose|v' => 'Print verbose output' @@ -565,7 +493,7 @@ public function testAddRulesDoesNotThrowWarnings() */ public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemainingArgument() { - $opts = new Zend_Console_Getopt("abp:", array("-")); + $opts = new Getopt("abp:", array("-")); $opts->parse(); $this->assertEquals(1, count($opts->getRemainingArgs())); @@ -577,13 +505,9 @@ public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemain */ public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException() { - $opts = new Zend_Console_Getopt("abp:", array("-", "file1")); - try { - $opts->parse(); - $this->fail(); - } catch(Exception $e) { - $this->assertTrue($e instanceof Zend_Console_Getopt_Exception); - } + $this->setExpectedException('\\Zend\\Console\\GetoptException'); + $opts = new Getopt("abp:", array("-", "file1")); + $opts->parse(); } /** @@ -593,7 +517,7 @@ public function testEqualsCharacterInLongOptionsValue() { $fooValue = 'some text containing an = sign which breaks'; - $opts = new Zend_Console_Getopt( + $opts = new Getopt( array('foo=s' => 'Option One (string)'), array('--foo='.$fooValue) ); From 019f89a9c95d4cc494972e495d5e4c0d31386bc7 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 17 May 2010 21:50:14 +0000 Subject: [PATCH 16/98] ZF-9756: "Undefined variable: lines" Zend_Console_Getopt getUsageMessage() line 623 git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22191 44c647ce-9c0f-0410-b52a-842ac1e357ba --- src/Getopt.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Getopt.php b/src/Getopt.php index 595a6f0..18c1b3b 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -594,6 +594,7 @@ public function getUsageMessage() { $usage = "Usage: {$this->_progname} [ options ]\n"; $maxLen = 20; + $lines = array(); foreach ($this->_rules as $rule) { $flags = array(); if (is_array($rule['alias'])) { From ba3f132bf2e3a4b78ba748a5673d9bb1bf1b9188 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 27 Sep 2010 11:18:10 -0500 Subject: [PATCH 17/98] Miletones/Exceptions - Refactored various tests for Application, Config, Console, Currency and Date components --- test/GetoptTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 4c4d022..3e87327 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -141,7 +141,7 @@ public function testGetoptAddRules() array('--pear', 'pear_param')); try { $opts->parse(); - $this->fail('Expected to catch Zend\\Console\\GetoptException'); + $this->fail('Expected to catch Zend\Console\Exception\RuntimeException'); } catch (\Zend\Console\Exception\RuntimeException $e) { $this->assertEquals($e->getMessage(), 'Option "pear" is not recognized.'); } From da75933f8c63f35342ce6306f5dd9904524c3aed Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:05:59 +0200 Subject: [PATCH 18/98] Test case for ignoring cumulative params by default --- test/GetoptTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index dc72ea2..eb472ee 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -525,4 +525,15 @@ public function testEqualsCharacterInLongOptionsValue() ); $this->assertEquals($fooValue, $opts->foo); } + + public function testGetoptIgnoreCumulativeParamsByDefault() + { + $opts = new Getopt( + array('colors|c' => 'Colors-option'), + array( + '--colors', 'red', + '--colors', 'green', + '--colors', 'blue')); + $this->assertEquals('blue', $opts->colors, 'Should be equal to last variable'); + } } From 96d6efbdf567616622f25462539a82cbb6a05ffb Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:07:15 +0200 Subject: [PATCH 19/98] Test case for cumulative params configuration, test works in red --- test/GetoptTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index eb472ee..b5da96f 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -536,4 +536,18 @@ public function testGetoptIgnoreCumulativeParamsByDefault() '--colors', 'blue')); $this->assertEquals('blue', $opts->colors, 'Should be equal to last variable'); } + + public function testGetoptWithCumulativeParamsOptionHandleArrayValues() + { + $opts = new Getopt( + array('colors|c' => 'Colors-option'), + array( + '--colors', 'red', + '--colors', 'green', + '--colors', 'blue' + ), + array(Getopt::CONFIG_CUMULATIVE_PARAMETERS => true)); + $this->assertType('array', $opts->colors, 'Colors value should be an array'); + $this->assertEquals('red,green,blue', implode(',', $opts->colors)); + } } From d679cbeeb214466c0b3f4ad64dec60019e98c891 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:31:59 +0200 Subject: [PATCH 20/98] Write simple code which works normaly with cumulative params, test works in green --- test/GetoptTest.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index b5da96f..eee38b9 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -529,24 +529,22 @@ public function testEqualsCharacterInLongOptionsValue() public function testGetoptIgnoreCumulativeParamsByDefault() { $opts = new Getopt( - array('colors|c' => 'Colors-option'), - array( - '--colors', 'red', - '--colors', 'green', - '--colors', 'blue')); + array('colors=s' => 'Colors-option'), + array('--colors=red', '--colors=green', '--colors=blue') + ); + + $this->assertType('string', $opts->colors); $this->assertEquals('blue', $opts->colors, 'Should be equal to last variable'); } public function testGetoptWithCumulativeParamsOptionHandleArrayValues() { $opts = new Getopt( - array('colors|c' => 'Colors-option'), - array( - '--colors', 'red', - '--colors', 'green', - '--colors', 'blue' - ), - array(Getopt::CONFIG_CUMULATIVE_PARAMETERS => true)); + array('colors=s' => 'Colors-option'), + array('--colors=red', '--colors=green', '--colors=blue'), + array(Getopt::CONFIG_CUMULATIVE_PARAMETERS => true) + ); + $this->assertType('array', $opts->colors, 'Colors value should be an array'); $this->assertEquals('red,green,blue', implode(',', $opts->colors)); } From 1e729a78007915421355a180a05a40c20ce2be9c Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:38:33 +0200 Subject: [PATCH 21/98] Move setting single option value to separated function --- src/Getopt.php | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 0fd3689..4d930c2 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -163,6 +163,7 @@ class Getopt const CONFIG_DASHDASH = 'dashDash'; const CONFIG_IGNORECASE = 'ignoreCase'; const CONFIG_PARSEALL = 'parseAll'; + const CONFIG_CUMULATIVE_PARAMETERS = 'cumulativeParameters'; /** * Defaults for getopt configuration are: @@ -172,10 +173,11 @@ class Getopt * parseAll is enabled. */ protected $_getoptConfig = array( - self::CONFIG_RULEMODE => self::MODE_ZEND, - self::CONFIG_DASHDASH => true, - self::CONFIG_IGNORECASE => false, - self::CONFIG_PARSEALL => true, + self::CONFIG_RULEMODE => self::MODE_ZEND, + self::CONFIG_DASHDASH => true, + self::CONFIG_IGNORECASE => false, + self::CONFIG_PARSEALL => true, + self::CONFIG_CUMULATIVE_PARAMETERS => false, ); /** @@ -799,7 +801,31 @@ protected function _parseSingleOption($flag, &$argv) default: $param = true; } - $this->_options[$realFlag] = $param; + + $this->_setSingleOptionValue($realFlag, $param); + } + + /** + * Add relative to options' flag value + * + * If options list already has current flag as key + * and parser should follow cumulative params by configuration, + * we should to add new param to array, not to overwrite + * + * @param string $flag + * @param string $value + * @return null + */ + protected function _setSingleOptionValue($flag, $value) + { + if (!array_key_exists($flag, $this->_options)) { + $this->_options[$flag] = $value; + } else if($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { + $this->_options[$flag] = (array)$this->_options[$flag]; + $this->_options[$flag][] = $value; + } else { + $this->_options[$flag] = $value; + } } /** From 2826108112421987118bdb472ba8c8b14936a13f Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:45:43 +0200 Subject: [PATCH 22/98] Code cleaning --- src/Getopt.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 4d930c2..4cc7f81 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -95,7 +95,7 @@ * If this config value is null or empty string, do not split values * into arrays. Default separator is comma (','). * - * @todo Handle params with multiple values specified with separate options + * @todo [Done] Handle params with multiple values specified with separate options * e.g. --colors red --colors green --colors blue should give one * option with an array(red, green, blue). * Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_PARAMETERS. @@ -821,8 +821,8 @@ protected function _setSingleOptionValue($flag, $value) if (!array_key_exists($flag, $this->_options)) { $this->_options[$flag] = $value; } else if($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { - $this->_options[$flag] = (array)$this->_options[$flag]; - $this->_options[$flag][] = $value; + $this->_options[$flag] = (array) $this->_options[$flag]; + array_push($this->_options[$flag], $value); } else { $this->_options[$flag] = $value; } From b35445af0fe547255363f4c7207fd556fa6a9529 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Thu, 20 Jan 2011 23:50:29 +0200 Subject: [PATCH 23/98] Add docblock tag info about new cumulative parameters config --- src/Getopt.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index 4cc7f81..559cd44 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -170,7 +170,9 @@ class Getopt * ruleMode is 'zend' format, * dashDash (--) token is enabled, * ignoreCase is not enabled, - * parseAll is enabled. + * parseAll is enabled, + * cumulative parameters are disabled, + * this means that subsequent options overwrite the parameter value. */ protected $_getoptConfig = array( self::CONFIG_RULEMODE => self::MODE_ZEND, From 1a18b799779f4a870ffaac91703938ec0bdbb3bc Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 19:33:57 +0200 Subject: [PATCH 24/98] Test case for default value of cumulative flag option --- src/Getopt.php | 5 ++++- test/GetoptTest.php | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index 559cd44..750587a 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -164,6 +164,7 @@ class Getopt const CONFIG_IGNORECASE = 'ignoreCase'; const CONFIG_PARSEALL = 'parseAll'; const CONFIG_CUMULATIVE_PARAMETERS = 'cumulativeParameters'; + const CONFIG_CUMULATIVE_FLAGS = 'cumulativeFlags'; /** * Defaults for getopt configuration are: @@ -172,7 +173,8 @@ class Getopt * ignoreCase is not enabled, * parseAll is enabled, * cumulative parameters are disabled, - * this means that subsequent options overwrite the parameter value. + * this means that subsequent options overwrite the parameter value, + * cumulative flags are disable. */ protected $_getoptConfig = array( self::CONFIG_RULEMODE => self::MODE_ZEND, @@ -180,6 +182,7 @@ class Getopt self::CONFIG_IGNORECASE => false, self::CONFIG_PARSEALL => true, self::CONFIG_CUMULATIVE_PARAMETERS => false, + self::CONFIG_CUMULATIVE_FLAGS => false ); /** diff --git a/test/GetoptTest.php b/test/GetoptTest.php index eee38b9..9576ebd 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -548,4 +548,15 @@ public function testGetoptWithCumulativeParamsOptionHandleArrayValues() $this->assertType('array', $opts->colors, 'Colors value should be an array'); $this->assertEquals('red,green,blue', implode(',', $opts->colors)); } + + public function testGetoptIgnoreCumulativeFlagsByDefault() + { + $opts = new Getopt( + 'v', + array('-v', '-v', '-v') + ); + + $this->assertEquals(true, $opts->v); + } + } From feeaa1b06d8f6b922f648d7d828d99d6523869fe Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 19:35:26 +0200 Subject: [PATCH 25/98] Test case for additional facility of handling cumulative flags as integer count --- test/GetoptTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 9576ebd..68cb436 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -559,4 +559,14 @@ public function testGetoptIgnoreCumulativeFlagsByDefault() $this->assertEquals(true, $opts->v); } + public function testGetoptWithCumulativeFlagsOptionHandleCountOfEqualFlags() + { + $opts = new Getopt( + 'v', + array('-v', '-v', '-v'), + array(Getopt::CONFIG_CUMULATIVE_FLAGS => true) + ); + + $this->assertEquals(3, $opts->v); + } } From f676ce5cbf12c7bce2363b1ec1ff7c4682c05d3e Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 19:49:52 +0200 Subject: [PATCH 26/98] Simple code which working normally with cumulative flags option, tests work in green line --- src/Getopt.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Getopt.php b/src/Getopt.php index 750587a..8463e60 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -823,6 +823,13 @@ protected function _parseSingleOption($flag, &$argv) */ protected function _setSingleOptionValue($flag, $value) { + if (true === $value && $this->_getoptConfig[self::CONFIG_CUMULATIVE_FLAGS]) { + $this->_options[$flag] = array_key_exists($flag, $this->_options) + ? (int) $this->_options[$flag] + 1 : true; + + return; + } + if (!array_key_exists($flag, $this->_options)) { $this->_options[$flag] = $value; } else if($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { From 3569c48b140e6d8645b8a0bd52c4153db1b22553 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 22:13:11 +0200 Subject: [PATCH 27/98] Code cleaning in test cases and getopt library --- src/Getopt.php | 20 ++++++++++++++++---- test/GetoptTest.php | 12 +++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 8463e60..f53b3c7 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -824,10 +824,8 @@ protected function _parseSingleOption($flag, &$argv) protected function _setSingleOptionValue($flag, $value) { if (true === $value && $this->_getoptConfig[self::CONFIG_CUMULATIVE_FLAGS]) { - $this->_options[$flag] = array_key_exists($flag, $this->_options) - ? (int) $this->_options[$flag] + 1 : true; - - return; + // For boolean values we have to create new flag, or increase number of flags' usage count + return $this->_setBooleanFlagValue($flag); } if (!array_key_exists($flag, $this->_options)) { @@ -840,6 +838,20 @@ protected function _setSingleOptionValue($flag, $value) } } + /** + * Set TRUE value to given flag, if this option does not exist yet + * In other case increase value to show count of flags' usage + * + * @param string $flag + * @return null + */ + protected function _setBooleanFlagValue($flag) + { + $this->_options[$flag] = array_key_exists($flag, $this->_options) + ? (int) $this->_options[$flag] + 1 + : true; + } + /** * Return true if the parameter is in a valid format for * the option $flag. diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 68cb436..29bea76 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -551,21 +551,15 @@ public function testGetoptWithCumulativeParamsOptionHandleArrayValues() public function testGetoptIgnoreCumulativeFlagsByDefault() { - $opts = new Getopt( - 'v', - array('-v', '-v', '-v') - ); + $opts = new Getopt('v', array('-v', '-v', '-v')); $this->assertEquals(true, $opts->v); } public function testGetoptWithCumulativeFlagsOptionHandleCountOfEqualFlags() { - $opts = new Getopt( - 'v', - array('-v', '-v', '-v'), - array(Getopt::CONFIG_CUMULATIVE_FLAGS => true) - ); + $opts = new Getopt('v', array('-v', '-v', '-v'), + array(Getopt::CONFIG_CUMULATIVE_FLAGS => true)); $this->assertEquals(3, $opts->v); } From 082709d0382e591b3bd57b216c36831b623eaf86 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 22:20:04 +0200 Subject: [PATCH 28/98] DONE mark for relative item in todo list --- src/Getopt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index f53b3c7..f93f5f2 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -101,7 +101,7 @@ * Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_PARAMETERS. * Default is that subsequent options overwrite the parameter value. * - * @todo Handle flags occurring multiple times, e.g. -v -v -v + * @todo [Done] Handle flags occurring multiple times, e.g. -v -v -v * Set value of the option's parameter to the integer count of instances * instead of a boolean. * Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_FLAGS. From e24277b88a671c831c57ecd513bf400202fcbb35 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 22:33:46 +0200 Subject: [PATCH 29/98] Test case for default ignorine spliting multiple values in param --- test/GetoptTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 29bea76..40515af 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -552,7 +552,7 @@ public function testGetoptWithCumulativeParamsOptionHandleArrayValues() public function testGetoptIgnoreCumulativeFlagsByDefault() { $opts = new Getopt('v', array('-v', '-v', '-v')); - + $this->assertEquals(true, $opts->v); } @@ -563,4 +563,14 @@ public function testGetoptWithCumulativeFlagsOptionHandleCountOfEqualFlags() $this->assertEquals(3, $opts->v); } -} + + public function testGetoptIgnoreParamsWithMultipleValuesByDefault() + { + $opts = new Getopt( + array('colors=s' => 'Colors-option'), + array('--colors=red,green,blue') + ); + + $this->assertEquals('red,green,blue', $opts->colors); + } +} \ No newline at end of file From f2466bc213083888d0f4e4292fcd6e888ba6022c Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 22:40:11 +0200 Subject: [PATCH 30/98] Test case for spliting multiple values by given separator --- test/GetoptTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 40515af..7010f87 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -573,4 +573,15 @@ public function testGetoptIgnoreParamsWithMultipleValuesByDefault() $this->assertEquals('red,green,blue', $opts->colors); } + + public function testGetoptWithNotEmptyParameterSeparatorSplitMultipleValues() + { + $opts = new Getopt( + array('colors=s' => 'Colors-option'), + array('--colors=red,green,blue'), + array(Getopt::CONFIG_PARAMETER_SEPARATOR => ',') + ); + + $this->assertEquals('red:green:blue', implode(':', $opt->colors)); + } } \ No newline at end of file From fcabe697766d6e73aafc9bffd05c169309260b85 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Sat, 22 Jan 2011 22:51:20 +0200 Subject: [PATCH 31/98] Handling multiple values, spliting by given separator string --- src/Getopt.php | 17 +++++++++++++++-- test/GetoptTest.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index f93f5f2..7c82389 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -89,12 +89,16 @@ * @version Release: @package_version@ * @since Class available since Release 0.6.0 * - * @todo Handle params with multiple values, e.g. --colors=red,green,blue + * @todo [Done] Handle params with multiple values, e.g. --colors=red,green,blue * Set value of parameter to the array of values. Allow user to specify * the separator with Zend_Console_Getopt::CONFIG_PARAMETER_SEPARATOR. * If this config value is null or empty string, do not split values * into arrays. Default separator is comma (','). * + * @todo Analyze what to do in case, when Getopt::CONFIG_PARAMETER_SEPARATOR not empty + * and Getopt::CONFIG_CUMULATIVE_PARAMETERS is true - do we have to return array + * of arrays, or just merge all values in one list? + * * @todo [Done] Handle params with multiple values specified with separate options * e.g. --colors red --colors green --colors blue should give one * option with an array(red, green, blue). @@ -165,6 +169,7 @@ class Getopt const CONFIG_PARSEALL = 'parseAll'; const CONFIG_CUMULATIVE_PARAMETERS = 'cumulativeParameters'; const CONFIG_CUMULATIVE_FLAGS = 'cumulativeFlags'; + const CONFIG_PARAMETER_SEPARATOR = 'parameterSeparator'; /** * Defaults for getopt configuration are: @@ -182,7 +187,8 @@ class Getopt self::CONFIG_IGNORECASE => false, self::CONFIG_PARSEALL => true, self::CONFIG_CUMULATIVE_PARAMETERS => false, - self::CONFIG_CUMULATIVE_FLAGS => false + self::CONFIG_CUMULATIVE_FLAGS => false, + self::CONFIG_PARAMETER_SEPARATOR => null ); /** @@ -828,6 +834,13 @@ protected function _setSingleOptionValue($flag, $value) return $this->_setBooleanFlagValue($flag); } + // Split multiple values, if necessary + // Filter empty values from splited array + $separator = $this->_getoptConfig[self::CONFIG_PARAMETER_SEPARATOR]; + if (is_string($value) && !empty($separator) && is_string($separator) && substr_count($value, $separator)) { + $value = array_filter(explode($separator, $value)); + } + if (!array_key_exists($flag, $this->_options)) { $this->_options[$flag] = $value; } else if($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 7010f87..77ced3c 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -582,6 +582,6 @@ public function testGetoptWithNotEmptyParameterSeparatorSplitMultipleValues() array(Getopt::CONFIG_PARAMETER_SEPARATOR => ',') ); - $this->assertEquals('red:green:blue', implode(':', $opt->colors)); + $this->assertEquals('red:green:blue', implode(':', $opts->colors)); } } \ No newline at end of file From a8569bb3f869a57e67d0c4fa12440f7e7d9bca44 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Tue, 25 Jan 2011 01:41:01 +0200 Subject: [PATCH 32/98] Test case for freeform flags handling --- test/GetoptTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 77ced3c..dd75723 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -584,4 +584,15 @@ public function testGetoptWithNotEmptyParameterSeparatorSplitMultipleValues() $this->assertEquals('red:green:blue', implode(':', $opts->colors)); } + + public function testGetoptWithFreeformFlagOptionRecognizeAllFlags() + { + $opts = new Getopt( + array('colors' => 'Colors-option'), + array('--freeform'), + array(Getopt::CONFIG_FREEFORM_FLAGS => true) + ); + + $this->assertEquals(true, $opts->freeform); + } } \ No newline at end of file From 017b9816f86c7dcd197416f89314d67e256b5c85 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Tue, 25 Jan 2011 01:54:15 +0200 Subject: [PATCH 33/98] Simple implementation of freeform flags facilities --- src/Getopt.php | 70 +++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 7c82389..ea8c563 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -170,6 +170,7 @@ class Getopt const CONFIG_CUMULATIVE_PARAMETERS = 'cumulativeParameters'; const CONFIG_CUMULATIVE_FLAGS = 'cumulativeFlags'; const CONFIG_PARAMETER_SEPARATOR = 'parameterSeparator'; + const CONFIG_FREEFORM_FLAGS = 'freeformFlags'; /** * Defaults for getopt configuration are: @@ -179,7 +180,8 @@ class Getopt * parseAll is enabled, * cumulative parameters are disabled, * this means that subsequent options overwrite the parameter value, - * cumulative flags are disable. + * cumulative flags are disable, + * freeform flags are disable. */ protected $_getoptConfig = array( self::CONFIG_RULEMODE => self::MODE_ZEND, @@ -188,7 +190,8 @@ class Getopt self::CONFIG_PARSEALL => true, self::CONFIG_CUMULATIVE_PARAMETERS => false, self::CONFIG_CUMULATIVE_FLAGS => false, - self::CONFIG_PARAMETER_SEPARATOR => null + self::CONFIG_PARAMETER_SEPARATOR => null, + self::CONFIG_FREEFORM_FLAGS => false ); /** @@ -783,34 +786,43 @@ protected function _parseSingleOption($flag, &$argv) $flag = strtolower($flag); } if (!isset($this->_ruleMap[$flag])) { - throw new Exception\RuntimeException( - "Option \"$flag\" is not recognized.", - $this->getUsageMessage() - ); - } - $realFlag = $this->_ruleMap[$flag]; - switch ($this->_rules[$realFlag]['param']) { - case 'required': - if (count($argv) > 0) { - $param = array_shift($argv); - $this->_checkParameterType($realFlag, $param); - } else { - throw new Exception\RuntimeException( - "Option \"$flag\" requires a parameter.", - $this->getUsageMessage() - ); - } - break; - case 'optional': - if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') { - $param = array_shift($argv); - $this->_checkParameterType($realFlag, $param); - } else { + // Don't throw Exception for flag-like param in case when freeform flags are allowed + if ((count($argv) > 0 && substr($argv[0], 0, 1) != '-') + || !$this->_getoptConfig[self::CONFIG_FREEFORM_FLAGS]) { + throw new Exception\RuntimeException( + "Option \"$flag\" is not recognized.", + $this->getUsageMessage() + ); + } + + // Magic methods in future will use this mark as real flag value + $this->_ruleMap[$flag] = $flag; + list($realFlag, $param) = array($flag, true); + } else { + $realFlag = $this->_ruleMap[$flag]; + switch ($this->_rules[$realFlag]['param']) { + case 'required': + if (count($argv) > 0) { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { + throw new Exception\RuntimeException( + "Option \"$flag\" requires a parameter.", + $this->getUsageMessage() + ); + } + break; + case 'optional': + if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { + $param = true; + } + break; + default: $param = true; - } - break; - default: - $param = true; + } } $this->_setSingleOptionValue($realFlag, $param); From 54719de2db5be73220fbe26aff43f4043494641f Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Tue, 25 Jan 2011 02:08:11 +0200 Subject: [PATCH 34/98] Documentation fix --- src/Getopt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index ea8c563..912cc87 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -114,7 +114,7 @@ * * @todo Handle flags that implicitly print usage message, e.g. --help * - * @todo Handle freeform options, e.g. --set-variable + * @todo [Done] Handle freeform options, e.g. --set-variable * Enable with Zend_Console_Getopt::CONFIG_FREEFORM_FLAGS * All flag-like syntax is recognized, no flag generates an exception. * From f2b5aa41e148dd7bf4c536d3c88c4eaa7a46af6d Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Tue, 25 Jan 2011 23:55:51 +0200 Subject: [PATCH 35/98] Small fixies to system of freeform flags recognition --- src/Getopt.php | 53 +++++++++++++++++++++++---------------------- test/GetoptTest.php | 11 ++++++++++ 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 912cc87..ab4c61e 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -787,8 +787,7 @@ protected function _parseSingleOption($flag, &$argv) } if (!isset($this->_ruleMap[$flag])) { // Don't throw Exception for flag-like param in case when freeform flags are allowed - if ((count($argv) > 0 && substr($argv[0], 0, 1) != '-') - || !$this->_getoptConfig[self::CONFIG_FREEFORM_FLAGS]) { + if (!$this->_getoptConfig[self::CONFIG_FREEFORM_FLAGS]) { throw new Exception\RuntimeException( "Option \"$flag\" is not recognized.", $this->getUsageMessage() @@ -796,33 +795,35 @@ protected function _parseSingleOption($flag, &$argv) } // Magic methods in future will use this mark as real flag value - $this->_ruleMap[$flag] = $flag; - list($realFlag, $param) = array($flag, true); + $this->_ruleMap[$flag] = $flag; + $realFlag = $flag; + $this->_rules[$realFlag] = array('param' => 'optional'); } else { $realFlag = $this->_ruleMap[$flag]; - switch ($this->_rules[$realFlag]['param']) { - case 'required': - if (count($argv) > 0) { - $param = array_shift($argv); - $this->_checkParameterType($realFlag, $param); - } else { - throw new Exception\RuntimeException( - "Option \"$flag\" requires a parameter.", - $this->getUsageMessage() - ); - } - break; - case 'optional': - if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') { - $param = array_shift($argv); - $this->_checkParameterType($realFlag, $param); - } else { - $param = true; - } - break; - default: + } + + switch ($this->_rules[$realFlag]['param']) { + case 'required': + if (count($argv) > 0) { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { + throw new Exception\RuntimeException( + "Option \"$flag\" requires a parameter.", + $this->getUsageMessage() + ); + } + break; + case 'optional': + if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') { + $param = array_shift($argv); + $this->_checkParameterType($realFlag, $param); + } else { $param = true; - } + } + break; + default: + $param = true; } $this->_setSingleOptionValue($realFlag, $param); diff --git a/test/GetoptTest.php b/test/GetoptTest.php index dd75723..e74c166 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -595,4 +595,15 @@ public function testGetoptWithFreeformFlagOptionRecognizeAllFlags() $this->assertEquals(true, $opts->freeform); } + + public function testGetoptWithFreeformFlagOptionRecognizeFlagsWithValue() + { + $opts = new Getopt( + array('colors' => 'Colors-option'), + array('color', '--freeform', 'test', 'zend'), + array(Getopt::CONFIG_FREEFORM_FLAGS => true) + ); + + $this->assertEquals('test', $opts->freeform); + } } \ No newline at end of file From c6a9c9c1e603f509fd0012e08074994ad21ad798 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Wed, 26 Jan 2011 00:42:38 +0200 Subject: [PATCH 36/98] Test for raising exception on numeric options by default --- test/GetoptTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index e74c166..422025b 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -606,4 +606,15 @@ public function testGetoptWithFreeformFlagOptionRecognizeFlagsWithValue() $this->assertEquals('test', $opts->freeform); } + + public function testGetoptRaiseExceptionForNumericOptionsByDefault() + { + $opts = new Getopt( + array('colors=s' => 'Colors-option'), + array('red', 'green', '-3') + ); + + $this->setExpectedException('\Zend\Console\Exception\RuntimeException', 'not recognized'); + $opts->parse(); + } } \ No newline at end of file From 002bcbad8b7d7ab5696316301983055aaa7c0e22 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Wed, 26 Jan 2011 00:47:02 +0200 Subject: [PATCH 37/98] Configuration flag for numeric options, test for numeric options recognition --- src/Getopt.php | 4 +++- test/GetoptTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index ab4c61e..651b930 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -171,6 +171,7 @@ class Getopt const CONFIG_CUMULATIVE_FLAGS = 'cumulativeFlags'; const CONFIG_PARAMETER_SEPARATOR = 'parameterSeparator'; const CONFIG_FREEFORM_FLAGS = 'freeformFlags'; + const CONFIG_NUMERIC_FLAGS = 'numericFlags'; /** * Defaults for getopt configuration are: @@ -191,7 +192,8 @@ class Getopt self::CONFIG_CUMULATIVE_PARAMETERS => false, self::CONFIG_CUMULATIVE_FLAGS => false, self::CONFIG_PARAMETER_SEPARATOR => null, - self::CONFIG_FREEFORM_FLAGS => false + self::CONFIG_FREEFORM_FLAGS => false, + self::CONFIG_NUMERIC_FLAGS => false ); /** diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 422025b..9d91348 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -617,4 +617,15 @@ public function testGetoptRaiseExceptionForNumericOptionsByDefault() $this->setExpectedException('\Zend\Console\Exception\RuntimeException', 'not recognized'); $opts->parse(); } + + public function testGetoptCanRecognizeNumericOprions() + { + $opts = new Getopt( + array('lines=#' => 'Lines-option'), + array('other', 'arguments', '-5'), + array(Getopt::CONFIG_NUMERIC_FLAGS => true) + ); + + $this->assertEquals(5, $opts->lines); + } } \ No newline at end of file From 97a3cef9652bab54669e60dffd795460caff8d75 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Wed, 26 Jan 2011 01:24:48 +0200 Subject: [PATCH 38/98] Normal system for handling numeric flags, additional tests for exception situations --- src/Getopt.php | 34 ++++++++++++++++++++++++++++++++++ test/GetoptTest.php | 14 +++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index 651b930..c6aa1ae 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -154,6 +154,7 @@ class Getopt const TYPE_STRING = 's'; const TYPE_WORD = 'w'; const TYPE_INTEGER = 'i'; + const TYPE_NUMERIC_FLAG = '#'; /** * These are constants for optional behavior of this class. @@ -787,6 +788,12 @@ protected function _parseSingleOption($flag, &$argv) if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) { $flag = strtolower($flag); } + + // Check if this option is numeric one + if (preg_match('/^\d+$/', $flag)) { + return $this->_setNumericOptionValue($flag); + } + if (!isset($this->_ruleMap[$flag])) { // Don't throw Exception for flag-like param in case when freeform flags are allowed if (!$this->_getoptConfig[self::CONFIG_FREEFORM_FLAGS]) { @@ -831,6 +838,29 @@ protected function _parseSingleOption($flag, &$argv) $this->_setSingleOptionValue($realFlag, $param); } + + /** + * Set given value as value of numeric option + * + * Throw runtime exception if this action is deny by configuration + * or no one numeric option handlers is defined + * + * @param int $value + * @return void + */ + protected function _setNumericOptionValue($value) + { + if (!$this->_getoptConfig[self::CONFIG_NUMERIC_FLAGS]) { + throw new Exception\RuntimeException("Using of numeric flags are deny by configuration"); + } + + if (empty($this->_getoptConfig['numericFlagsOption'])) { + throw new Exception\RuntimeException("Any option for handling numeric flags are specified"); + } + + return $this->_setSingleOptionValue($this->_getoptConfig['numericFlagsOption'], $value); + } + /** * Add relative to options' flag value * @@ -1016,6 +1046,10 @@ protected function _addRulesModeZend($rules) case self::TYPE_INTEGER: $rule['paramType'] = 'integer'; break; + case self::TYPE_NUMERIC_FLAG: + $rule['paramType'] = 'numericFlag'; + $this->_getoptConfig['numericFlagsOption'] = $mainFlag; + break; case self::TYPE_STRING: default: $rule['paramType'] = 'string'; diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 9d91348..5a4f4ad 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -614,7 +614,7 @@ public function testGetoptRaiseExceptionForNumericOptionsByDefault() array('red', 'green', '-3') ); - $this->setExpectedException('\Zend\Console\Exception\RuntimeException', 'not recognized'); + $this->setExpectedException('\Zend\Console\Exception\RuntimeException'); $opts->parse(); } @@ -628,4 +628,16 @@ public function testGetoptCanRecognizeNumericOprions() $this->assertEquals(5, $opts->lines); } + + public function testGetoptRaiseExceptionForNumericOptionsIfAneHandlerIsSpecified() + { + $opts = new Getopt( + array('lines=s' => 'Lines-option'), + array('other', 'arguments', '-5'), + array(Getopt::CONFIG_NUMERIC_FLAGS => true) + ); + + $this->setExpectedException('\Zend\Console\Exception\RuntimeException'); + $opts->parse(); + } } \ No newline at end of file From 6694397457830472b449cdec01cbf993c204b54d Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Wed, 26 Jan 2011 01:26:56 +0200 Subject: [PATCH 39/98] Todo documentaion notes --- src/Getopt.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index c6aa1ae..78b5111 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -118,11 +118,14 @@ * Enable with Zend_Console_Getopt::CONFIG_FREEFORM_FLAGS * All flag-like syntax is recognized, no flag generates an exception. * - * @todo Handle numeric options, e.g. -1, -2, -3, -1000 + * @todo [Done] Handle numeric options, e.g. -1, -2, -3, -1000 * Enable with Zend_Console_Getopt::CONFIG_NUMERIC_FLAGS * The rule must specify a named flag and the '#' symbol as the * parameter type. e.g., 'lines=#' * + * @todo Clerify situation when user will put several # sign. For ex., + * lines=#, limit=# (now the system will overwrite first param by last one) + * * @todo Enable user to specify header and footer content in the help message. * * @todo Feature request to handle option interdependencies. From f986c675e2ff70cd05180ff09e09110bc2d9a3d7 Mon Sep 17 00:00:00 2001 From: "Alexey S. Kachayev" Date: Mon, 7 Feb 2011 23:51:42 +0200 Subject: [PATCH 40/98] Remove unnecessary todo in class docblock --- src/Getopt.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index 78b5111..b4d6c1a 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -89,43 +89,8 @@ * @version Release: @package_version@ * @since Class available since Release 0.6.0 * - * @todo [Done] Handle params with multiple values, e.g. --colors=red,green,blue - * Set value of parameter to the array of values. Allow user to specify - * the separator with Zend_Console_Getopt::CONFIG_PARAMETER_SEPARATOR. - * If this config value is null or empty string, do not split values - * into arrays. Default separator is comma (','). - * - * @todo Analyze what to do in case, when Getopt::CONFIG_PARAMETER_SEPARATOR not empty - * and Getopt::CONFIG_CUMULATIVE_PARAMETERS is true - do we have to return array - * of arrays, or just merge all values in one list? - * - * @todo [Done] Handle params with multiple values specified with separate options - * e.g. --colors red --colors green --colors blue should give one - * option with an array(red, green, blue). - * Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_PARAMETERS. - * Default is that subsequent options overwrite the parameter value. - * - * @todo [Done] Handle flags occurring multiple times, e.g. -v -v -v - * Set value of the option's parameter to the integer count of instances - * instead of a boolean. - * Enable with Zend_Console_Getopt::CONFIG_CUMULATIVE_FLAGS. - * Default is that the value is simply boolean true regardless of - * how many instances of the flag appear. - * * @todo Handle flags that implicitly print usage message, e.g. --help * - * @todo [Done] Handle freeform options, e.g. --set-variable - * Enable with Zend_Console_Getopt::CONFIG_FREEFORM_FLAGS - * All flag-like syntax is recognized, no flag generates an exception. - * - * @todo [Done] Handle numeric options, e.g. -1, -2, -3, -1000 - * Enable with Zend_Console_Getopt::CONFIG_NUMERIC_FLAGS - * The rule must specify a named flag and the '#' symbol as the - * parameter type. e.g., 'lines=#' - * - * @todo Clerify situation when user will put several # sign. For ex., - * lines=#, limit=# (now the system will overwrite first param by last one) - * * @todo Enable user to specify header and footer content in the help message. * * @todo Feature request to handle option interdependencies. From 6ff135c829b013a61d68b2672ca00554a0c79108 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 23 Feb 2011 10:41:05 -0600 Subject: [PATCH 41/98] Updated PHPUnit assertions - Used assertInternalType instead of assertType --- test/GetoptTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index bc5d44e..55a5542 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -533,7 +533,7 @@ public function testGetoptIgnoreCumulativeParamsByDefault() array('--colors=red', '--colors=green', '--colors=blue') ); - $this->assertType('string', $opts->colors); + $this->assertInternalType('string', $opts->colors); $this->assertEquals('blue', $opts->colors, 'Should be equal to last variable'); } @@ -545,7 +545,7 @@ public function testGetoptWithCumulativeParamsOptionHandleArrayValues() array(Getopt::CONFIG_CUMULATIVE_PARAMETERS => true) ); - $this->assertType('array', $opts->colors, 'Colors value should be an array'); + $this->assertInternalType('array', $opts->colors, 'Colors value should be an array'); $this->assertEquals('red,green,blue', implode(',', $opts->colors)); } @@ -640,4 +640,4 @@ public function testGetoptRaiseExceptionForNumericOptionsIfAneHandlerIsSpecified $this->setExpectedException('\Zend\Console\Exception\RuntimeException'); $opts->parse(); } -} \ No newline at end of file +} From f463808c068b8138ec45f286a4813822408552c9 Mon Sep 17 00:00:00 2001 From: Thinkscape Date: Sun, 29 Jan 2012 20:37:47 +0100 Subject: [PATCH 42/98] Add more prompts, workaround various Windows-related quirks --- src/Adapter.php | 20 +++++- src/Adapter/AbstractAdapter.php | 32 +++++++++- src/Adapter/Posix.php | 20 ++++++ src/Adapter/Virtual.php | 8 +-- src/Adapter/Windows.php | 105 +++++++++++++++++++++++++++----- src/Adapter/WindowsAnsicon.php | 38 +++++++++++- 6 files changed, 198 insertions(+), 25 deletions(-) diff --git a/src/Adapter.php b/src/Adapter.php index 2ef77e2..efb39d4 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -40,7 +40,7 @@ public function writeText($text, $color = null, $bgColor = null); * @param null|int $color * @param null|int $bgColor */ - public function writeLine($text, $color = null, $bgColor = null); + public function writeLine($text = "", $color = null, $bgColor = null); /** * Write a piece of text at the coordinates of $x and $y @@ -278,4 +278,22 @@ public function clearLine(); * @abstract */ public function clearScreen(); + + /** + * Read a single line from the console input + * + * @abstract + * @param int $maxLength Maximum response length + * @return string + */ + public function readLine($maxLength = 2048); + + /** + * Read a single character from the console input + * + * @abstract + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null); } \ No newline at end of file diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 0bbdc41..b0d3052 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -61,7 +61,7 @@ public function writeText($text, $color = null, $bgColor = null) * @param null|int $color * @param null|int $bgColor */ - public function writeLine($text, $color = null, $bgColor = null) + public function writeLine($text = "", $color = null, $bgColor = null) { $width = $this->getStringWidth( $text ); @@ -80,7 +80,7 @@ public function writeLine($text, $color = null, $bgColor = null) */ $consoleWidth = $this->getWidth(); if ($width > $consoleWidth) { - $text = $this->stringTrim( $text, $this->getWidth() ); + $text = $this->stringTrim( $text, $consoleWidth ); echo $text; } elseif ($width == $consoleWidth) { echo $text; @@ -566,4 +566,32 @@ protected function stringTrim($string, $length) return strlen( $string ); } } + + /** + * Read a single line from the console input + * + * @param int $maxLength Maximum response length + * @return string + */ + public function readLine($maxLength = 2048){ + $f = fopen('php://stdin','r'); + $line = stream_get_line($f,2048,"\n"); + fclose($f); + return $line; + } + + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null){ + $f = fopen('php://stdin','r'); + do{ + $char = fread($f,1); + }while($mask === null || stristr($mask,$char)); + fclose($f); + return $char; + } } \ No newline at end of file diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index ec1e938..e549247 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -319,4 +319,24 @@ public function getDefaultCharset(){ } } + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null){ + do{ + $char = trim(`read -s -n1 val; echo \$val`); + }while( + !$char || + ($mask !== null && !stristr($mask,$char)) + ); + return $char; + } + + /** + * @todo Add GNU readline support + */ + } \ No newline at end of file diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index 833b04d..c1fd766 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -32,7 +32,7 @@ public function getWidth(){ * Try to read console size from "mode" command */ if($this->modeResult === null){ - $this->runModeCommand(); + $this->runProbeCommand(); } if(preg_match('/Columns\:\s+(\d+)/',$this->modeResult,$matches)){ @@ -59,7 +59,7 @@ public function getHeight(){ * Try to read console size from "mode" command */ if($this->modeResult === null){ - $this->runModeCommand(); + $this->runProbeCommand(); } if(preg_match('/Rows\:\s+(\d+)/',$this->modeResult,$matches)){ @@ -71,7 +71,7 @@ public function getHeight(){ return $height; } - protected function runModeCommand(){ + protected function runProbeCommand(){ exec('mode',$output,$return); if($return || !count($output)){ $this->modeResult = ''; @@ -90,7 +90,7 @@ public function isUtf8(){ * Try to read code page info from "mode" command */ if($this->modeResult === null){ - $this->runModeCommand(); + $this->runProbeCommand(); } if(preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)){ diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 34a041b..6f80241 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -12,7 +12,7 @@ class Windows extends Virtual implements Adapter { protected static $hasMBString; - protected $modeResult; + protected $probeResult; /** * Determine and return current console width. @@ -28,11 +28,11 @@ public function getWidth(){ /** * Try to read console size from "mode" command */ - if($this->modeResult === null){ - $this->runModeCommand(); + if($this->probeResult === null){ + $this->runProbeCommand(); } - if(preg_match('/Columns\:\s+(\d+)/',$this->modeResult,$matches)){ + if(preg_match('/^(\d+)\t/s',$this->probeResult,$matches)){ $width = $matches[1]; }else{ $width = parent::getWidth(); @@ -55,25 +55,25 @@ public function getHeight(){ /** * Try to read console size from "mode" command */ - if($this->modeResult === null){ - $this->runModeCommand(); + if($this->probeResult === null){ + $this->runProbeCommand(); } - if(preg_match('/Rows\:\s+(\d+)/',$this->modeResult,$matches)){ + if(preg_match('/^\d+\t(\d+)/s',$this->probeResult,$matches)){ $height = $matches[1]; }else{ - $height = parent::getHeight(); + $height = parent::getheight(); } return $height; } - protected function runModeCommand(){ - exec('mode',$output,$return); - if($return || !count($output)){ - $this->modeResult = ''; + protected function runProbeCommand(){ + $output = system('powershell -command "$size = $Host.ui.rawui.windowsize; write ""$($size.width)`t$($size.height)"""',$return); + if($return || !$output){ + $this->probeResult = ''; }else{ - $this->modeResult = trim(implode('',$output)); + $this->probeResult = trim($output); } } @@ -86,11 +86,11 @@ public function isUtf8(){ /** * Try to read code page info from "mode" command */ - if($this->modeResult === null){ - $this->runModeCommand(); + if($this->probeResult === null){ + $this->runProbeCommand(); } - if(preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)){ + if(preg_match('/Code page\:\s+(\d+)/',$this->probeResult,$matches)){ return (int)$matches[1] == 65001; }else{ return false; @@ -155,4 +155,77 @@ public function getDefaultCharset(){ protected function switchToUtf8(){ `mode con cp select=65001`; } + + /** + * Clear console screen + */ + public function clear() + { + echo str_repeat("\r\n",$this->getHeight()); + } + + /** + * Clear line at cursor position + */ + public function clearLine() + { + echo "\r".str_repeat(' ',$this->getWidth())."\r"; + } + + + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null){ + /** + * Decide if we can use `choice` tool + */ + $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]*$/',$mask); + + do{ + if($useChoice){ + /** + * Use the `choice` tool available since windows 2000 + */ + system('choice /n /cs /c '.escapeshellarg($mask).' >NUL',$return); + if($return == 255 || $return < 1 || $return > strlen($mask)){ + throw new \RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); + }else{ + /** + * Fetch the char from mask + */ + $char = substr($mask,$return-1,1); + } + }else{ + /** + * Use a fallback method + */ + $char = $this->readLine(1); + if(!$char){ + $char = "\n"; // user pressed [enter] + } + } + }while( + ($mask !== null && !stristr($mask,$char)) + ); + return $char; + } + + /** + * Read a single line from the console input. + * + * @param int $maxLength Maximum response length + * @return string + */ + public function readLine($maxLength = 2048){ + $f = fopen('php://stdin','r'); + $line = trim(fread($f,$maxLength)); + fclose($f); + return $line; + } + + } \ No newline at end of file diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 1b48e3d..af17151 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -62,8 +62,8 @@ public function getHeight(){ } /** - * Try to read console size from ANSICON env var - */ + * Try to read console size from ANSICON env var + */ if(preg_match('/\(\d+x(\d+)/',getenv('ANSICON'),$matches)){ $height = $matches[1]; }else{ @@ -164,4 +164,38 @@ public function getCharset(){ public function getDefaultCharset(){ return new Charset\AsciiExtended(); } + + /** + * Read a single character from the console input + * + * @param string|null $mask A list of allowed chars + * @return string + */ + public function readChar($mask = null){ + /** + * Decide if we can use `choice` tool + */ + $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]$',$mask); + + do{ + if($useChoice){ + system('choice /n /cs /c '.$mask,$return); + if($return == 255 || $return < 1 || $return > strlen($mask)){ + throw new \RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); + }else{ + /** + * Fetch the char from mask + */ + $char = substr($mask,$return-1,1); + } + }else{ + $char = parent::readChar($mask); + } + }while( + !$char || + ($mask !== null && !stristr($mask,$char)) + ); + return $char; + } + } \ No newline at end of file From 319fd7325e341ba7908888753a9218dc8a5bfeed Mon Sep 17 00:00:00 2001 From: Thinkscape Date: Wed, 1 Feb 2012 13:06:16 +0100 Subject: [PATCH 43/98] More work towards functional Cli --- src/Getopt.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Getopt.php b/src/Getopt.php index 585f8b9..9308d9c 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -559,6 +559,14 @@ public function getRemainingArgs() return $this->_remainingArgs; } + public function getArguments(){ + $result = $this->getRemainingArgs(); + foreach($this->getOptions() as $option){ + $result[$option] = $this->getOption($option); + } + return $result; + } + /** * Return a useful option reference, formatted for display in an * error message. From fb02b238a578eca27a159ab990b8195bf8f0ccff Mon Sep 17 00:00:00 2001 From: Joust Date: Sat, 18 Feb 2012 16:42:01 +0100 Subject: [PATCH 44/98] Fix clear screen under posix --- src/Adapter/Posix.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index e549247..3d5c23f 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -335,6 +335,14 @@ public function readChar($mask = null){ return $char; } + /** + * Reset color to console default. + */ + public function clear(){ + echo chr(27).'[2J'; // reset bg color + $this->setPos(1,1); // reset cursor position + } + /** * @todo Add GNU readline support */ From ae8888a6faf6c247be0d72659ba1d16b1382ca58 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 20 Feb 2012 17:43:24 +0100 Subject: [PATCH 45/98] Refactor Cli to Console, add route matching test stub --- src/Prompt.php | 40 +++++++ src/Prompt/AbstractPrompt.php | 54 +++++++++ src/Prompt/Char.php | 200 ++++++++++++++++++++++++++++++++++ src/Prompt/Confirm.php | 102 +++++++++++++++++ src/Prompt/Line.php | 108 ++++++++++++++++++ src/Prompt/Number.php | 199 +++++++++++++++++++++++++++++++++ src/Prompt/Select.php | 118 ++++++++++++++++++++ src/Request.php | 181 ++++++++++++++++++++++++++++++ 8 files changed, 1002 insertions(+) create mode 100644 src/Prompt.php create mode 100644 src/Prompt/AbstractPrompt.php create mode 100644 src/Prompt/Char.php create mode 100644 src/Prompt/Confirm.php create mode 100644 src/Prompt/Line.php create mode 100644 src/Prompt/Number.php create mode 100644 src/Prompt/Select.php create mode 100644 src/Request.php diff --git a/src/Prompt.php b/src/Prompt.php new file mode 100644 index 0000000..bc8b87a --- /dev/null +++ b/src/Prompt.php @@ -0,0 +1,40 @@ +lastResponse; + } + + /** + * Return console adapter to use when showing prompt. + * + * @return \Zend\Console\Adapter + */ + public function getConsole(){ + if(!$this->console){ + $this->console = Console::getInstance(); + } + + return $this->console; + } + + /** + * Set console adapter to use when showing prompt. + * + * @param \Zend\Console\Adapter $adapter + */ + public function setConsole(ConsoleAdapter $adapter){ + $this->console = $adapter; + } + +} \ No newline at end of file diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php new file mode 100644 index 0000000..9e4d50d --- /dev/null +++ b/src/Prompt/Char.php @@ -0,0 +1,200 @@ +setPromptText($promptText); + } + + if($allowEmpty !== null){ + $this->setAllowEmpty($allowEmpty); + } + + if($ignoreCase !== null){ + $this->setIgnoreCase($ignoreCase); + } + + if($allowedChars !== null){ + if($this->ignoreCase){ + $this->setAllowedChars(strtolower($allowedChars)); + }else{ + $this->setAllowedChars($allowedChars); + } + } + + if($echo !== null){ + $this->setEcho($echo); + } + } + + /** + * Show the prompt to user and return a single char. + * + * @return string + */ + public function show() + { + $this->getConsole()->write($this->promptText); + $mask = $this->getAllowedChars(); + + /** + * Normalize the mask if case is irrelevant + */ + if($this->ignoreCase){ + $mask = strtolower($mask); // lowercase all + $mask .= strtoupper($mask); // uppercase and append + $mask = str_split($mask); // convert to array + $mask = array_unique($mask); // remove duplicates + $mask = implode("",$mask); // convert back to string + } + + do{ + /** + * Read char from console + */ + $char = $this->getConsole()->readChar($mask); + + /** + * Lowercase the response if case is irrelevant + */ + if($this->ignoreCase){ + $char = strtolower($char); + } + + /** + * Check if it is an allowed char + */ + if(stristr($this->allowedChars,$char)){ + if($this->echo){ + echo trim($char)."\n"; + }else{ + echo "\n"; + } + break; + } + }while(true); + + return $this->lastResponse = $char; + } + + /** + * @param boolean $allowEmpty + */ + public function setAllowEmpty($allowEmpty) + { + $this->allowEmpty = $allowEmpty; + } + + /** + * @return boolean + */ + public function getAllowEmpty() + { + return $this->allowEmpty; + } + + /** + * @param string $promptText + */ + public function setPromptText($promptText) + { + $this->promptText = $promptText; + } + + /** + * @return string + */ + public function getPromptText() + { + return $this->promptText; + } + + /** + * @param string $allowedChars + */ + public function setAllowedChars($allowedChars) + { + $this->allowedChars = $allowedChars; + } + + /** + * @return string + */ + public function getAllowedChars() + { + return $this->allowedChars; + } + + /** + * @param boolean $ignoreCase + */ + public function setIgnoreCase($ignoreCase) + { + $this->ignoreCase = $ignoreCase; + } + + /** + * @return boolean + */ + public function getIgnoreCase() + { + return $this->ignoreCase; + } + + /** + * @param boolean $echo + */ + public function setEcho($echo) + { + $this->echo = $echo; + } + + /** + * @return boolean + */ + public function getEcho() + { + return $this->echo; + } + +} \ No newline at end of file diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php new file mode 100644 index 0000000..50b606c --- /dev/null +++ b/src/Prompt/Confirm.php @@ -0,0 +1,102 @@ +setPromptText($promptText); + } + + if($yesChar !== null){ + $this->setYesChar($yesChar); + } + + if($noChar !== null){ + $this->setNoChar($noChar); + } + } + + /** + * Show the confirmation message and return result. + * + * @return bool + */ + public function show() + { + $response = parent::show() === $this->yesChar; + return $this->lastResponse = $response; + } + + + /** + * @param string $noChar + */ + public function setNoChar($noChar) + { + $this->noChar = $noChar; + $this->setAllowedChars($this->yesChar.$this->noChar); + } + + /** + * @return string + */ + public function getNoChar() + { + return $this->noChar; + } + + /** + * @param string $yesChar + */ + public function setYesChar($yesChar) + { + $this->yesChar = $yesChar; + $this->setAllowedChars($this->yesChar.$this->noChar); + } + + /** + * @return string + */ + public function getYesChar() + { + return $this->yesChar; + } + +} \ No newline at end of file diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php new file mode 100644 index 0000000..3cf37c9 --- /dev/null +++ b/src/Prompt/Line.php @@ -0,0 +1,108 @@ +setPromptText($promptText); + } + + if($allowEmpty !== null){ + $this->setAllowEmpty($allowEmpty); + } + + if($maxLength !== null){ + $this->setMaxLength($maxLength); + } + } + + /** + * Show the prompt to user and return the answer. + * + * @return mixed + */ + public function show() + { + do{ + $this->getConsole()->write($this->promptText); + $line = $this->getConsole()->readLine($this->maxLength); + }while(!$this->allowEmpty && !$line); + + return $this->lastResponse = $line; + } + + /** + * @param boolean $allowEmpty + */ + public function setAllowEmpty($allowEmpty) + { + $this->allowEmpty = $allowEmpty; + } + + /** + * @return boolean + */ + public function getAllowEmpty() + { + return $this->allowEmpty; + } + + /** + * @param int $maxLength + */ + public function setMaxLength($maxLength) + { + $this->maxLength = $maxLength; + } + + /** + * @return int + */ + public function getMaxLength() + { + return $this->maxLength; + } + + /** + * @param string $promptText + */ + public function setPromptText($promptText) + { + $this->promptText = $promptText; + } + + /** + * @return string + */ + public function getPromptText() + { + return $this->promptText; + } + +} \ No newline at end of file diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php new file mode 100644 index 0000000..8440290 --- /dev/null +++ b/src/Prompt/Number.php @@ -0,0 +1,199 @@ +setPromptText($promptText); + } + + if($allowEmpty !== null){ + $this->setAllowEmpty($allowEmpty); + } + + if($min !== null){ + $this->setMin($min); + } + + if($max !== null){ + $this->setMax($max); + } + + if($allowFloat !== null){ + $this->setAllowFloat($allowFloat); + } + } + + /** + * Show the prompt to user and return the answer. + * + * @return mixed + */ + public function show() + { + /** + * Ask for a number and validate it. + */ + do{ + $valid = true; + $number = parent::show(); + if($number === "" && !$this->allowEmpty){ + $valid = false; + }elseif($number === ""){ + $number = null; + }elseif(!is_numeric($number)){ + $this->getConsole()->writeLine("$number is not a number\n"); + $valid = false; + }elseif(!$this->allowFloat && (round($number) != $number) ){ + $this->getConsole()->writeLine("Please enter a non-floating number, i.e. ".round($number)."\n"); + $valid = false; + }elseif($this->max !== null && $number > $this->max){ + $this->getConsole()->writeLine("Please enter a number not greater than ".$this->max."\n"); + $valid = false; + }elseif($this->min !== null && $number < $this->min){ + $this->getConsole()->writeLine("Please enter a number not smaller than ".$this->min."\n"); + $valid = false; + } + }while(!$valid); + + /** + * Cast proper type + */ + if($number !== null){ + $number = $this->allowFloat ? (double)$number : (int)$number; + } + + return $this->lastResponse = $number; + } + + /** + * @param boolean $allowEmpty + */ + public function setAllowEmpty($allowEmpty) + { + $this->allowEmpty = $allowEmpty; + } + + /** + * @return boolean + */ + public function getAllowEmpty() + { + return $this->allowEmpty; + } + + /** + * @param int $maxLength + */ + public function setMaxLength($maxLength) + { + $this->maxLength = $maxLength; + } + + /** + * @return int + */ + public function getMaxLength() + { + return $this->maxLength; + } + + /** + * @param string $promptText + */ + public function setPromptText($promptText) + { + $this->promptText = $promptText; + } + + /** + * @return string + */ + public function getPromptText() + { + return $this->promptText; + } + + /** + * @param int $max + */ + public function setMax($max) + { + $this->max = $max; + } + + /** + * @return int + */ + public function getMax() + { + return $this->max; + } + + /** + * @param int $min + */ + public function setMin($min) + { + $this->min = $min; + } + + /** + * @return int + */ + public function getMin() + { + return $this->min; + } + + /** + * @param boolean $allowFloat + */ + public function setAllowFloat($allowFloat) + { + $this->allowFloat = $allowFloat; + } + + /** + * @return boolean + */ + public function getAllowFloat() + { + return $this->allowFloat; + } + +} \ No newline at end of file diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php new file mode 100644 index 0000000..408cbc6 --- /dev/null +++ b/src/Prompt/Select.php @@ -0,0 +1,118 @@ +setPromptText($promptText); + } + + if(!count($options)){ + throw new \BadMethodCallException( + 'Cannot construct a "select" prompt without any options' + ); + } + + $this->setOptions($options); + + if($allowEmpty !== null){ + $this->setAllowEmpty($allowEmpty); + } + + if($echo !== null){ + $this->setEcho($echo); + } + + } + + /** + * Show a list of options and prompt the user to select one of them. + * + * @return string Selected option + */ + public function show() + { + /** + * Show prompt text and available options + */ + $console = $this->getConsole(); + $console->writeLine($this->promptText); + foreach($this->options as $k=>$v){ + $console->writeLine(' '.$k.') '.$v); + } + + /** + * Ask for selection + */ + $mask = implode("",array_keys($this->options)); + if($this->allowEmpty){ + $mask .= "\r\n"; + } + $this->setAllowedChars($mask); + $oldPrompt = $this->promptText; + $this->promptText = 'Pick one option: '; + $response = parent::show(); + $this->promptText = $oldPrompt; + + return $response; + } + + /** + * Set allowed options + * + * @param array|Traversable $options + */ + public function setOptions($options) + { + if(!is_array($options) && !$options instanceof \Traversable){ + throw new \BadMethodCallException( + 'Please specify an array or Traversable object as options' + ); + } + + if(!is_array($options)){ + $this->options = array(); + foreach($options as $k => $v){ + $this->options[$k] = $v; + } + }else{ + $this->options = $options; + } + } + + /** + * @return array + */ + public function getOptions() + { + return $this->options; + } +} \ No newline at end of file diff --git a/src/Request.php b/src/Request.php new file mode 100644 index 0000000..d5d656b --- /dev/null +++ b/src/Request.php @@ -0,0 +1,181 @@ + 0){ + $this->setScriptName(array_shift($args)); + } + + /** + * Store runtime params + */ + $this->params()->fromArray($args); + + /** + * Store environment data + */ + $this->env()->fromArray($env); + } + + /** + * Exchange parameters object + * + * @param \Zend\Stdlib\ParametersDescription $params + * @return Request + */ + public function setParams(ParametersDescription $params) + { + $this->params = $params; + return $this; + } + + /** + * Return the container responsible for parameters + * + * @return \Zend\Stdlib\ParametersDescription + */ + public function getParams() + { + if ($this->params === null) { + $this->params = new Parameters(); + } + + return $this->params; + } + + /** + * Return a single parameter. + * Shortcut for $request->params()->get() + * + * @param string $name Parameter name + * @param string $default (optional) default value in case the parameter does not exist + * @return mixed + */ + public function getParam($name, $default = null) + { + return $this->params()->get($name, $default); + } + + /** + * Return the container responsible for parameters + * + * @return \Zend\Stdlib\ParametersDescription + */ + public function params() + { + if ($this->params === null) { + $this->params = new Parameters(); + } + + return $this->params; + } + + /** + * Provide an alternate Parameter Container implementation for env parameters in this object, (this is NOT the + * primary API for value setting, for that see env()) + * + * @param \Zend\Stdlib\ParametersDescription $env + * @return \Zend\Console\Request + */ + public function setEnv(ParametersDescription $env) + { + $this->envParams = $env; + return $this; + } + + /** + * Return the parameter container responsible for env parameters + * + * @return \Zend\Stdlib\ParametersDescription + */ + public function env() + { + if ($this->envParams === null) { + $this->envParams = new Parameters(); + } + + return $this->envParams; + } + + /** + * @return string + */ + public function toString() + { + return trim(implode(' ',$this->params()->toArray())); + } + + /** + * Allow PHP casting of this object + * + * @return string + */ + public function __toString() + { + return $this->toString(); + } + + /** + * @param string $scriptName + */ + public function setScriptName($scriptName) + { + $this->scriptName = $scriptName; + } + + /** + * @return string + */ + public function getScriptName() + { + return $this->scriptName; + } + +} From 93e070106328894fd4165806c6232b613bc09d4d Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Sun, 18 Mar 2012 17:18:55 +0100 Subject: [PATCH 46/98] Add support for Console MVC applications. - Revert Mvc/Bootstrap.php - Add Mvc\ConsoleBootstrap, extending standard (http) Bootstrap, for bootstrapping application when inside a Console enviroment. - Add Mvc\Router\Console\Catchall, a route that always matches with a Console request. - Add Mvc\View\CreateViewModelListener::createViewModelFromString() that allows controllers to return a "string" that will be output to console. - Add Mvc\View\InjectRoutematchParamsStrategy.php that copies matched parameters and their values from Routematch to Request. - Add View\Model\ConsoleModel describing data returned from a console MVC action. - Add View\Renderer\ConsoleRenderer that prepares Console output to be echoed. - Add View\Renderer\ConsoleStrategy which responsible for selecting ConsoleRenderer and outputing the result to the console. --- src/Adapter/Posix.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 3d5c23f..7a43896 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -161,14 +161,14 @@ public function isUtf8(){ * Show console cursor */ public function showCursor(){ - echo chr(27).'[?25h'; + echo "\x1b[?25h"; } /** * Hide console cursor */ public function hideCursor(){ - echo chr(27).'[?25l'; + echo "\x1b[?25l"; } /** @@ -177,7 +177,7 @@ public function hideCursor(){ * @param int $y */ public function setPos($x, $y){ - echo chr(27).'['.$y.';'.$x.'f'; + echo "\x1b[".$y.';'.$x.'f'; } /** @@ -213,10 +213,10 @@ public function colorize($string, $color = null, $bgColor = null) } return - ($color !== null ? chr(27).'['.$color.'m' : ''). - ($bgColor !== null ? chr(27).'['.$bgColor.'m' : ''). + ($color !== null ? "\x1b[".$color.'m' : ''). + ($bgColor !== null ? "\x1b[".$bgColor.'m' : ''). $string. - chr(27).'[22;39m'.chr(27).'[0;49m' + "\x1b[22;39m\x1b[0;49m" ; } @@ -240,7 +240,7 @@ public function setColor($color) } } - echo chr(27).'['.$color.'m'; + echo "\x1b[".$color.'m'; } /** @@ -262,7 +262,7 @@ public function setBgColor($bgColor) $bgColor = static::$ansiColorMap['bg'][$bgColor]; } } - echo chr(27).'['.($bgColor).'m'; + echo "\x1b[".($bgColor).'m'; } /** @@ -270,10 +270,10 @@ public function setBgColor($bgColor) */ public function resetColor() { - echo chr(27).'[0;49m'; // reset bg color - echo chr(27).'[22;39m'; // reset fg bold, bright and faint - echo chr(27).'[25;39m'; // reset fg blink - echo chr(27).'[24;39m'; // reset fg underline + echo "\x1b[0;49m"; // reset bg color + echo "\x1b[22;39m"; // reset fg bold, bright and faint + echo "\x1b[25;39m"; // reset fg blink + echo "\x1b[24;39m"; // reset fg underline } /** @@ -339,7 +339,7 @@ public function readChar($mask = null){ * Reset color to console default. */ public function clear(){ - echo chr(27).'[2J'; // reset bg color + echo "\x1b[2J"; // reset bg color $this->setPos(1,1); // reset cursor position } From 7687a7f64081756d72ef00a9a99403d5225e6d3d Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 19 Mar 2012 19:12:38 +0100 Subject: [PATCH 47/98] Fix Adapter\Posix::readChar(), fix colors with writeLine(), fix optional value params in Console Route. --- src/Adapter/AbstractAdapter.php | 6 ++-- src/Adapter/Posix.php | 51 +++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index b0d3052..6cc0250 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -81,11 +81,11 @@ public function writeLine($text = "", $color = null, $bgColor = null) $consoleWidth = $this->getWidth(); if ($width > $consoleWidth) { $text = $this->stringTrim( $text, $consoleWidth ); - echo $text; + $this->write($text, $color, $bgColor); } elseif ($width == $consoleWidth) { - echo $text; + $this->write($text, $color, $bgColor); } else { - echo $text . "\n"; + $this->write($text. "\n", $color, $bgColor);; } } diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 7a43896..08a89c5 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -72,6 +72,13 @@ class Posix extends AbstractAdapter implements Adapter ), ); + /** + * Last fetched TTY mode + * + * @var string|null + */ + protected $lastTTYMode = null; + /** * Determine and return current console width. * @@ -156,7 +163,6 @@ public function isUtf8(){ return false; } - /** * Show console cursor */ @@ -325,13 +331,20 @@ public function getDefaultCharset(){ * @param string|null $mask A list of allowed chars * @return string */ - public function readChar($mask = null){ + public function readChar($mask = null) + { + $this->setTTYMode('-icanon -echo'); + + $stream = fopen('php://stdin','rb'); do{ - $char = trim(`read -s -n1 val; echo \$val`); + $char = fgetc($stream); }while( !$char || ($mask !== null && !stristr($mask,$char)) ); + fclose($stream); + + $this->restoreTTYMode(); return $char; } @@ -343,6 +356,38 @@ public function clear(){ $this->setPos(1,1); // reset cursor position } + /** + * Restore TTY (Console) mode to previous value. + * + * @return mixed + */ + protected function restoreTTYMode(){ + if($this->lastTTYMode === null) + return; + + shell_exec('stty '.escapeshellarg($this->lastTTYMode)); + + } + + /** + * Change TTY (Console) mode + * + * @link http://en.wikipedia.org/wiki/Stty + * @param $mode + */ + protected function setTTYMode($mode) + { + /** + * Store last mode + */ + $this->lastTTYMode = trim(`stty -g`); + + /** + * Set new mode + */ + shell_exec('stty '.escapeshellcmd($mode)); + } + /** * @todo Add GNU readline support */ From 32e7783189cf7502be77aa92d6ac845738a673b5 Mon Sep 17 00:00:00 2001 From: Thinkscape Date: Mon, 19 Mar 2012 19:48:03 +0100 Subject: [PATCH 48/98] Fix some console info leaking in Console\Adapter\Windows --- src/Adapter/Windows.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 6f80241..22825a6 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -69,7 +69,11 @@ public function getHeight(){ } protected function runProbeCommand(){ - $output = system('powershell -command "$size = $Host.ui.rawui.windowsize; write ""$($size.width)`t$($size.height)"""',$return); + exec( + 'powershell -command "$size = $Host.ui.rawui.windowsize; write ""$($size.width)`t$($size.height)"""', + $output, + $return + ); if($return || !$output){ $this->probeResult = ''; }else{ From 432b84e96f71ed988b01fbe2d1d6a0a8c0bc64d7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:27:17 +0200 Subject: [PATCH 49/98] Adding shell script to run tests It iterates over tested components and runs phpunit for each of them --- .travis/run-tests.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis/run-tests.sh diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh new file mode 100644 index 0000000..47d0c4a --- /dev/null +++ b/.travis/run-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash +travisdir=$(dirname $(readlink /proc/$$/fd/255)) +testdir="$travisdir/../tests" +testedcomponents=(`cat "$travisdir/tested-components"`) + +for tested in "${testedcomponents[@]}" + do phpunit -c $testdir/phpunit.xml $testdir/$tested +done From 65b26d32e11f3c2f086555f051f10d85385f3600 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:29:10 +0200 Subject: [PATCH 50/98] Adding script used to configure the test suite --- .travis/TestConfiguration.php | 825 ++++++++++++++++++++++++++++++++++ 1 file changed, 825 insertions(+) create mode 100644 .travis/TestConfiguration.php diff --git a/.travis/TestConfiguration.php b/.travis/TestConfiguration.php new file mode 100644 index 0000000..fd89470 --- /dev/null +++ b/.travis/TestConfiguration.php @@ -0,0 +1,825 @@ + test disabling output buffering in + * dispatcher + */ +defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || define('TESTS_ZEND_CONTROLLER_DISPATCHER_OB', false); + +/** + * Zend_Crypt related constantes + * + * TESTS_ZEND_CRYPT_OPENSSL_CONF => location of an openssl.cnf file for use + * with RSA encryption + */ +defined('TESTS_ZEND_CRYPT_OPENSSL_CONF') || define('TESTS_ZEND_CRYPT_OPENSSL_CONF', false); + +/** + * Zend_Db_Adapter_Pdo_Mysql and Zend_Db_Adapter_Mysqli + * + * There are separate properties to enable tests for the PDO_MYSQL adapter and + * the native Mysqli adapters, but the other properties are shared between the + * two MySQL-related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE', 'test'); +defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT', 3306); + +/** + * Zend_Db_Adapter_Pdo_Sqlite + * + * Username and password are irrelevant for SQLite. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE', ':memory:'); + +/** + * Zend_Db_Adapter_Pdo_Mssql + * + * Note that you need to patch your ntwdblib.dll, the one that + * comes with PHP does not work. See user comments at + * http://us2.php.net/manual/en/ref.mssql.php + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE', 'test'); + +/** + * Zend_Db_Adapter_Pdo_Pgsql + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE', 'postgres'); + +/** + * Zend_Db_Adapter_Oracle and Zend_Db_Adapter_Pdo_Oci + * + * There are separate properties to enable tests for the PDO_OCI adapter and + * the native Oracle adapter, but the other properties are shared between the + * two Oracle-related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_ORACLE_SID') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_SID', 'xe'); + +/** + * Zend_Db_Adapter_Db2 and Zend_Db_Adapter_Pdo_Ibm + * There are separate properties to enable tests for the PDO_IBM adapter and + * the native DB2 adapter, but the other properties are shared between the + * two related Zend_Db adapters. + */ +defined('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME', '127.0.0.1'); +defined('TESTS_ZEND_DB_ADAPTER_DB2_PORT') || define('TESTS_ZEND_DB_ADAPTER_DB2_PORT', 50000); +defined('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE', 'sample'); + +/** + * Zend_Db_Adapter_Sqlsrv + * Note: Make sure that you create the "test" database and set a + * username and password + * + */ +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED', false); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME', 'localhost\SQLEXPRESS'); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME', null); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD', null); +defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE', 'test'); + +/** + * Zend_Feed_Reader tests + * + * If the ONLINE_ENABLED property is false, only tests that can be executed + * without network connectivity are run; when enabled, all tests will run. + */ +defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED') || define('TESTS_ZEND_FEED_READER_ONLINE_ENABLED', false); + +/** + * Zend_Gdata tests + * + * If the ONLINE_ENABLED property is false, only tests that can be executed with + * a mock HTTP client are run. No request is sent to the Google Gdata servers. + * If ONLINE_ENABLED is true, some tests may make requests to the remote + * servers. This does not work if you are running tests on a disconnected + * client host. Also, the tests may show as failures if the Google servers + * cannot be reached or if they do not respond for another reason. + * + * If the CLIENTLOGIN_ENABLED property below is false, the authenticated + * tests are reported Skipped in the test run. Set this property to true + * to enable tests that require ClientLogin authentication. Enter your + * Google login credentials in the EMAIL and PASSWORD properties below. + * + * Edit TestConfiguration.php, not TestConfiguration.php.dist. + * Never commit plaintext passwords to the source code repository. + * + * Note: the GData tests currently require that the TZID env variable + * be set or the timezone otherwise configured. You'll see errors from the + * tests if this is not the case. + */ +defined('TESTS_ZEND_GDATA_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED', false); + +/* + * The credentials provided here should be only for a TEST account. + * Data for various services in this account may be added to, updated, + * or deleted based upon the actions of these test accounts. + */ +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL', 'example@example.com'); +defined('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD', 'password'); + +/* + * This is the ID of a blank blog. There is no need to have + * any content in this blog. Also, blogs can only be used + * several times for the purpose of these test cases before + * they must be deleted and recreated. Otherwise, the tests + * will start failing, as posts to Blogger will return a 201 Created + * response even though the entry was not posted to the blog. + * This problem is being investigated. + */ +defined('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_BLOG_ID') || define('TESTS_ZEND_GDATA_BLOG_ID', '1111111111111111111'); + +/* + * This is the key for a spreadsheet with data only in the first row of + * the spreadsheet. The strings 'a1', 'b1', 'c1', 'd1' should be in the + * corresponding cell locations. + */ +defined('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY') || define('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY', 'o01111111111111111111.1111111111111111111'); +defined('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID') || define('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID', 'default'); + +/* + * This indicates that online tests for the Google Calendar API should + * be performed. The default calendar will be used. + */ +defined('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED', false); + +/* + * This is the fully-qualified domain name for a domiain hosted using + * Google Apps. This domain must be registered with Google Apps and + * have API access enabled. This should be a TEST domain only. + */ +defined('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED', false); +defined('TESTS_ZEND_GDATA_GAPPS_DOMAIN') || define('TESTS_ZEND_GDATA_GAPPS_DOMAIN', 'example.com.invalid'); +defined('TESTS_ZEND_GDATA_GAPPS_EMAIL') || define('TESTS_ZEND_GDATA_GAPPS_EMAIL', 'example@example.com'); +defined('TESTS_ZEND_GDATA_GAPPS_PASSWORD') || define('TESTS_ZEND_GDATA_GAPPS_PASSWORD', 'password'); + +/* + * This is the ONLINE_ENABLED property for Google Base. + */ +defined('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the Books Search data API + * should be performed. + */ +defined('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the YouTube data API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED', false); + +/* + * This is the username to use for retrieving subscriptions, etc + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT') || define('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT', 'zfgdata'); + +/* + * This is the developer key to access the YouTube API + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY') || define('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY', 'your_developer_key_here'); + +/* + * This is the client ID to access the YouTube API + */ +defined('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID') || define('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID', 'ZF_UnitTests_unknown'); + +/* + * This indicates that online tests for the Google Documents API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the GData Photos API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED', false); + +/* + * This indicates that online tests for the Google Health API should + * be performed. + */ +defined('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED', false); + +/** + * Zend_Http_Client tests + * + * To enable the dynamic Zend_Http_Client tests, you will need to symbolically + * link or copy the files in tests/Zend/Http/Client/_files to a directory + * under your web server(s) document root and set this constant to point to the + * URL of this directory. + */ +defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') || define('TESTS_ZEND_HTTP_CLIENT_BASEURI', false); + +/** + * Zend_Http_Client_Proxy tests + * + * HTTP proxy to be used for testing the Proxy adapter. Set to a string of + * the form 'host:port'. Set to null to skip HTTP proxy tests. + */ +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY', false); +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER', ''); +defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS', ''); + +/** + * Zend_Loader_Autoloader multi-version support tests + * + * ENABLED: whether or not to run the multi-version tests + * PATH: path to a directory containing multiple ZF version installs + * LATEST: most recent ZF version in the PATH + * e.g., "1.9.2" + * LATEST_MAJOR: most recent ZF major version in the PATH to test against + * e.g., "1.9.2" + * LATEST_MINOR: most recent ZF minor version in the PATH to test against + * e.g., "1.8.4PL1" + * SPECIFIC: specific ZF version in the PATH to test against + * e.g., "1.7.6" + * As an example, consider the following tree: + * ZendFramework/ + * |-- 1.9.2 + * |-- ZendFramework-1.9.1-minimal + * |-- 1.8.4PL1 + * |-- 1.8.4 + * |-- ZendFramework-1.8.3 + * |-- 1.7.8 + * |-- 1.7.7 + * |-- 1.7.6 + * You would then set the value of "LATEST" and "LATEST_MAJOR" to "1.9.2", and + * could choose between "1.9.2", "1.8.4PL1", and "1.7.8" for "LATEST_MINOR", + * and any version number for "SPECIFIC". "PATH" would point to the parent + * "ZendFramework" directory. + */ +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR', false); +defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC', false); + +/** + * Zend_Ldap online tests + */ +defined('TESTS_ZEND_LDAP_ONLINE_ENABLED') || define('TESTS_ZEND_LDAP_ONLINE_ENABLED', false); + +/* These largely map to the options described in the Zend_Ldap and + * Zend_Auth_Adapter_Ldap documentation. + * + * Example Configuration for Active Directory: + * HOST: dc1.w.net + * USE_START_TLS: true + * USE_SSL: false + * USERNAME: CN=User 1,CN=Users,DC=w,DC=net + * PRINCIPAL_NAME: user1@w.net + * LDAP_PASSWORD: pass1 + * BASE_DN: CN=Users,DC=w,DC=net + * DOMAIN_NAME: w.net + * ACCOUNT_DOMAIN_NAME_SHORT: W + * ALT_USERNAME: user2 + * ALT_DN: CN=User 2,CN=Users,DC=w,DC=net + * ALT_PASSWORD: pass2 + * + * Example Configuration for OpenLDAP + * HOST: s0.foo.net + * USERNAME: CN=user1,DC=foo,DC=net + * PRINCIPAL_NAME: user1@foo.net + * LDAP_PASSWORD: pass1 + * BIND_REQUIRES_DN: true + * BASE_DN: OU=Sales,DC=w,DC=net + * DOMAIN_NAME: foo.net + * ACCOUNT_DOMAIN_NAME_SHORT: FOO + * ALT_USERNAME: abaker + * ALT_DN: CN=Alice Baker,OU=Sales,DC=foo,DC=net + * ALT_PASSWORD: apass + */ +defined('TESTS_ZEND_LDAP_HOST') || define('TESTS_ZEND_LDAP_HOST', 'localhost'); +//defined('TESTS_ZEND_LDAP_PORT') || define('TESTS_ZEND_LDAP_PORT', 389); +defined('TESTS_ZEND_LDAP_USE_START_TLS') || define('TESTS_ZEND_LDAP_USE_START_TLS', true); +//defined('TESTS_ZEND_LDAP_USE_SSL') || define('TESTS_ZEND_LDAP_USE_SSL', false); +defined('TESTS_ZEND_LDAP_USERNAME') || define('TESTS_ZEND_LDAP_USERNAME', 'CN=someUser,DC=example,DC=com'); +defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', 'someUser@example.com'); +defined('TESTS_ZEND_LDAP_PASSWORD') || define('TESTS_ZEND_LDAP_PASSWORD', null); +defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN') || define('TESTS_ZEND_LDAP_BIND_REQUIRES_DN', true); +defined('TESTS_ZEND_LDAP_BASE_DN') || define('TESTS_ZEND_LDAP_BASE_DN', 'OU=Sales,DC=example,DC=com'); +//defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT') || define('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT', '(&(objectClass=posixAccount)(uid=%s))'); +defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME', 'example.com'); +defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT', 'EXAMPLE'); +defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser'); +defined('TESTS_ZEND_LDAP_ALT_DN') || define('TESTS_ZEND_LDAP_ALT_DN', 'CN=Another User,OU=Sales,DC=example,DC=com'); +defined('TESTS_ZEND_LDAP_ALT_PASSWORD') || define('TESTS_ZEND_LDAP_ALT_PASSWORD', null); // Used in Zend_Auth_Adapter_Ldap tests +//(defined('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE') || define('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE', 'OU=Test,OU=Sales,DC=example,DC=com'); + +/** + * Zend_Locale tests + * + * If the TESTS_ZEND_LOCALE_FORMAT_SETLOCALE property below is a valid, + * locally recognized locale (try "locale -a"), then all tests in + * tests/Zend/Locale/ test suites will execute *after* + * setlocale(LC_ALL, TESTS_ZEND_LOCALE_FORMAT_SETLOCALE); + * Primarily, this switches certain PHP functions to emit "localized" output, + * including the built-in "to string" for integer and float conversions. + * Thus, a locale of 'fr_FR' yields number-to-string conversions in a + * localized form with the decimal place separator chosen via: + * setlocale(LC_ALL, 'fr_FR@euro'); + */ +//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr'); +//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr_FR@euro'); +defined('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE') || define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', false); + +/** + * Zend_Date tests + * + * If the BCMATH_ENABLED property below is false, all arithmetic + * operations will use ordinary PHP math operators and functions. + * Otherwise, the bcmath functions will be used for unlimited precision. + * + * If the EXTENDED_COVERAGE property below is false, most of the I18N + * unit tests will not be computed... this speeds tests up to 80 minutes + * when doing reports. * + * Edit TestConfiguration.php, not TestConfiguration.php.dist. + */ +defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') || define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', true); +defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || define('TESTS_ZEND_I18N_EXTENDED_COVERAGE', true); + +/** + * Zend_Mail_Storage tests + * + * TESTS_ZEND_MAIL_SERVER_TESTDIR and TESTS_ZEND_MAIL_SERVER_FORMAT are used for POP3 and IMAP tests. + * TESTS_ZEND_MAIL_SERVER_FORMAT is the format your test mail server uses: 'mbox' or 'maildir'. The mail + * storage for the user specified in your POP3 or IMAP tests should be TESTS_ZEND_MAIL_SERVER_TESTDIR. Be + * careful: it's cleared before copying the files. If you want to copy the files manually set the dir + * to null (or anything == null). + * + * TESTS_ZEND_MAIL_TEMPDIR is used for testing write operations in local storages. If not set (== null) + * tempnam() is used. + */ +defined('TESTS_ZEND_MAIL_SERVER_TESTDIR') || define('TESTS_ZEND_MAIL_SERVER_TESTDIR', null); +defined('TESTS_ZEND_MAIL_SERVER_FORMAT') || define('TESTS_ZEND_MAIL_SERVER_FORMAT', 'mbox'); +defined('TESTS_ZEND_MAIL_TEMPDIR') || define('TESTS_ZEND_MAIL_TEMPDIR', null); + +/** + * Zend_Mail_Storage_Pop3 / Zend_Mail_Transport_Pop3 + * + * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail + * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR + */ +defined('TESTS_ZEND_MAIL_POP3_ENABLED') || define('TESTS_ZEND_MAIL_POP3_ENABLED', false); +defined('TESTS_ZEND_MAIL_POP3_HOST') || define('TESTS_ZEND_MAIL_POP3_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_POP3_USER') || define('TESTS_ZEND_MAIL_POP3_USER', 'test'); +defined('TESTS_ZEND_MAIL_POP3_PASSWORD') || define('TESTS_ZEND_MAIL_POP3_PASSWORD', ''); +// test SSL connections if enabled in your test server +defined('TESTS_ZEND_MAIL_POP3_SSL') || define('TESTS_ZEND_MAIL_POP3_SSL', true); +defined('TESTS_ZEND_MAIL_POP3_TLS') || define('TESTS_ZEND_MAIL_POP3_TLS', true); +// WRONG_PORT should be an existing server port, +// INVALID_PORT should be a non existing (each on defined host) +defined('TESTS_ZEND_MAIL_POP3_WRONG_PORT') || define('TESTS_ZEND_MAIL_POP3_WRONG_PORT', 80); +defined('TESTS_ZEND_MAIL_POP3_INVALID_PORT') || define('TESTS_ZEND_MAIL_POP3_INVALID_PORT', 3141); + +/** + * Zend_Mail_Storage_Imap / Zend_Mail_Transport_Imap + * + * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail + * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR + */ +defined('TESTS_ZEND_MAIL_IMAP_ENABLED') || define('TESTS_ZEND_MAIL_IMAP_ENABLED', false); +defined('TESTS_ZEND_MAIL_IMAP_HOST') || define('TESTS_ZEND_MAIL_IMAP_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_IMAP_USER') || define('TESTS_ZEND_MAIL_IMAP_USER', 'test'); +defined('TESTS_ZEND_MAIL_IMAP_PASSWORD') || define('TESTS_ZEND_MAIL_IMAP_PASSWORD', ''); +// test SSL connections if enabled in your test server +defined('TESTS_ZEND_MAIL_IMAP_SSL') || define('TESTS_ZEND_MAIL_IMAP_SSL', true); +defined('TESTS_ZEND_MAIL_IMAP_TLS') || define('TESTS_ZEND_MAIL_IMAP_TLS', true); +// WRONG_PORT should be an existing server port, +// INVALID_PORT should be a non-existing (each on defined host) +defined('TESTS_ZEND_MAIL_IMAP_WRONG_PORT') || define('TESTS_ZEND_MAIL_IMAP_WRONG_PORT', 80); +defined('TESTS_ZEND_MAIL_IMAP_INVALID_PORT') || define('TESTS_ZEND_MAIL_IMAP_INVALID_PORT', 3141); + + +/** + * Zend_Mail_Storage_Maildir test + * + * Before enabling this test you have to unpack messages.tar in + * Zend/Mail/_files/test.maildir/cur/ and remove the tar for this test to work. + * That's because the messages files have a colon in the filename and that's a + * forbidden character on Windows. + */ +defined('TESTS_ZEND_MAIL_MAILDIR_ENABLED') || define('TESTS_ZEND_MAIL_MAILDIR_ENABLED', false); + +/** + * Zend_Mail_Transport_Smtp + * + * @todo TO be implemented + */ +defined('TESTS_ZEND_MAIL_SMTP_ENABLED') || define('TESTS_ZEND_MAIL_SMTP_ENABLED', false); +defined('TESTS_ZEND_MAIL_SMTP_HOST') || define('TESTS_ZEND_MAIL_SMTP_HOST', 'localhost'); +defined('TESTS_ZEND_MAIL_SMTP_PORT') || define('TESTS_ZEND_MAIL_SMTP_PORT', 25); +defined('TESTS_ZEND_MAIL_SMTP_USER') || define('TESTS_ZEND_MAIL_SMTP_USER', 'testuser'); +defined('TESTS_ZEND_MAIL_SMTP_PASSWORD') || define('TESTS_ZEND_MAIL_SMTP_PASSWORD', 'testpassword'); +defined('TESTS_ZEND_MAIL_SMTP_AUTH') || define('TESTS_ZEND_MAIL_SMTP_AUTH', false); +// AUTH can be set to false or a string of AUTH method (e.g. LOGIN, PLAIN, CRAMMD5 or DIGESTMD5) + +/** + * Zend_Queue Test Configuration constants + * + * The Zend_Queue_Adapter_Db constant should be a JSON-encoded string + * representing a configuration object for Zend_Db::factory(). For example: + * { + * type: "pdo_mysql", + * host: "127.0.0.1", + * port: 3306, + * username: "queue", + * password: "queue", + * dbname: "queue" + * } + * + * The PlatformJobQueue adapter expects two parameters, the host and password. + * The HOST string should include both the host and port (typically 10003): + * 127.0.0.1:10003 + * When running tests against PlatformJobQueue, it's best to do so where + * Platform is installed on localhost and has maximum workers set to 20 + * (default is 5); do so with this zend.ini setting: + * zend_jq.max_num_of_request_workers=20 + * + * Selectively define the below in order to run tests for them. + */ +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST', false); +defined('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT', false); +defined('TESTS_ZEND_QUEUE_DB_ENABLED') || define('TESTS_ZEND_QUEUE_DB_ENABLED', false); +defined('TESTS_ZEND_QUEUE_DB') || define('TESTS_ZEND_QUEUE_DB', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST', false); +defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST', false); +defined('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS', false); + + +/** + * Zend\Service\AgileZen online tests + */ +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_ENABLED',false); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_APIKEY','insert the API key'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_PROJECT_ID','insert the project id'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_STORY_ID','insert the story id'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_EMAIL','insert email for invitation'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_ROLE_ID','insert role id for invitation'); +define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_MEMBER_NAME','insert the member name to add to the project'); + + +/** + * Zend_Service_Amazon online tests + */ +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID', 'Enter AWSAccessKeyId here'); +defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY', 'Enter AWSSecretKey here'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID', 'zftestamazonimageid'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE', 'us-east-1'); +defined('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP', 'default'); +defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET') || define('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET', 'zftestamazons3bucket'); +defined('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE') || define('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE', 'zftestamazonsqsqueuename'); + +/** + * Zend_Service_Delicious tests + */ +defined('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED') || define('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED', false); + +/** + * Zend_Service_DeveloperGarden tests + * Setup your Username and Password to test this Service + */ +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'ZF_Username'); +defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'ZF_Password'); + +/** + * Zend_Service_Flickr online tests + */ +defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY', 'Enter API key here'); + +/** + * Zend_Service_GoGrid offline tests + */ + +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY','insert key here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET','insert secret here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME','test-zf'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE','insert image name here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM','insert ram name here'); +defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP','insert ip here'); + +/** + * Zend\Service\LiveDocx configuration + * + * Define username and password in order to run unit tests for LiveDocx web services. + * + * phpunit/phpunit will typically work. + */ +defined('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false); + +/** + * Zend\Service\LiveDocx premium configuration + * + * Define username, password, WSDL in order to run unit tests for premium LiveDocx web services. + */ +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD', false); +defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL', false); + +/** + * Zend_Service_Rackspace tests + */ +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER', 'Enter key here'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY', 'Enter secret here'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION', 'USA'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME', 'zf-unit-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME','zf-object-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME', 'zf-unit-test'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID', '49'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID', '49'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID', '1'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME', 'ZFunitTestImage'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME', 'ZFgroupIP'); +defined('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT') || define('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT', 60); + +/** + * Zend_Service_ReCaptcha tests + */ +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY', 'public key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY', 'private key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY', 'public mailhide key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY', 'private mailhide key'); + +/** + * Zend_Service_Simpy tests + */ +defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') || define('TESTS_ZEND_SERVICE_SIMPY_ENABLED', false); +defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME') || define('TESTS_ZEND_SERVICE_SIMPY_USERNAME', 'syapizend'); +defined('TESTS_ZEND_SERVICE_SIMPY_PASSWORD') || define('TESTS_ZEND_SERVICE_SIMPY_PASSWORD', 'mgt37ge'); + +/** + * Zend_Service_SlideShare tests + */ +defined('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME') || define('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD') || define('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET', ''); +defined('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY') || define('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY', ''); + +// The slide show ID to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID', 0); + +// The tag to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_TAG') || define('TESTS_ZEND_SERVICE_SLIDESHARE_TAG', 'zend'); + +// The group to retrieve during tests +defined('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP') || define('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP', ''); + +/** + * Zend_Service_Twitter tests + * + * ONLINE_ENABLED indicates whether or not to run tests requiring a network + * connection. + * + * TWITTER_USER and TWITTER_PASS are valid Twitter credentials you wish to use + * when testing. + */ +defined('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_TWITTER_USER') || define('TESTS_ZEND_SERVICE_TWITTER_USER', 'zftestuser'); +defined('TESTS_ZEND_SERVICE_TWITTER_PASS') || define('TESTS_ZEND_SERVICE_TWITTER_PASS', 'zftestuser'); + +/** + * Zend_Service_WindowsAzure tests + */ + +/** + * Online + */ + +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTNAME',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTKEY',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_TABLE_HOST',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_HOST',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_PORT',''); +define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_CREDENTIALS',''); + +/** + * Proxy settings + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY', ''); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT', '8080'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS', ''); + +/** + * Azure hosts + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV', '127.0.0.1:10000'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV', '127.0.0.1:10001'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV', '127.0.0.1:10002'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD', 'blob.core.windows.net'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD', 'queue.core.windows.net'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD', 'table.core.windows.net'); + +/** + * Credentials + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV', 'devstoreaccount1'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD', 'phpazure'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD', 'I+ebYPcIDB6BsmfAe6pJSpOw8oXA6jMBZv1BEZcSPRqTpldt44refCl65YpKJqcBOiD21Lxsj8d6Ah8Oc2/gKA=='); + +/** + * Blob storage tests + */ +// Enable this tests only when you have a working account +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB', true); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX', 'phpazuretestblob'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX', 'phpazureteststream'); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX', 'phpazuretestshared'); + +/** + * Table storage tests + */ +// Enable this tests only when you have a working account +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX', 'phpazuretesttable'); + +/** + * Queue storage tests + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX', 'phpazuretestqueue'); + +/** + * SessionHandler tests + */ +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD', false); +defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX', 'phpazuretestsession'); + +/** + * Zend_Service_Yahoo online tests + */ +defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID', 'Enter APPID here'); + +/** + * Zend_Soap_AutoDiscover scenario tests for complex objects and wsdl generation + * + * Copy all the files of zf/tests/Zend/Soap/_files/fulltests into a directory + * that can be reached by webserver and enter the base uri to this directory + * into the variable. The test "Zend_Soap_AutoDiscover_OnlineTest" makes use + * of the servers and AutoDiscover feature. + * + * NOTE: Make sure the servers are using the correct Zend Framework copy, + * when having more than one version installed and include paths are changing. + */ +defined('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI') || define('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI', false); + +/** + * Zend_Uri tests + * + * Setting CRASH_TEST_ENABLED to true will enable some tests that may + * potentially crash PHP on some systems, due to very deep-nesting regular + * expressions. + * + * Only do this if you know what you are doing! + */ +defined('TESTS_ZEND_URI_CRASH_TEST_ENABLED') || define('TESTS_ZEND_URI_CRASH_TEST_ENABLED', false); + +/** + * Zend_Validate tests + * + * Set ONLINE_ENABLED if you wish to run validators that require network + * connectivity. + */ +defined('TESTS_ZEND_VALIDATE_ONLINE_ENABLED') || define('TESTS_ZEND_VALIDATE_ONLINE_ENABLED', false); + +/** + * PHPUnit Code Coverage / Test Report + */ +defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false); +defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target'); + From 42147d4655e2e7f15494e266604e217800f2ce58 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 00:32:21 +0200 Subject: [PATCH 51/98] Making the run-tests.sh script executable --- .travis/run-tests.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .travis/run-tests.sh diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh old mode 100644 new mode 100755 From ab276d6454f6ddf033c24f3e6fe9cd57f6fa905f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 20:56:26 +0200 Subject: [PATCH 52/98] Moving travis test configuration This way it is more obvious to the committer changing test configuration that also travis config should be changed --- .travis/TestConfiguration.php | 825 ---------------------------------- 1 file changed, 825 deletions(-) delete mode 100644 .travis/TestConfiguration.php diff --git a/.travis/TestConfiguration.php b/.travis/TestConfiguration.php deleted file mode 100644 index fd89470..0000000 --- a/.travis/TestConfiguration.php +++ /dev/null @@ -1,825 +0,0 @@ - test disabling output buffering in - * dispatcher - */ -defined('TESTS_ZEND_CONTROLLER_DISPATCHER_OB') || define('TESTS_ZEND_CONTROLLER_DISPATCHER_OB', false); - -/** - * Zend_Crypt related constantes - * - * TESTS_ZEND_CRYPT_OPENSSL_CONF => location of an openssl.cnf file for use - * with RSA encryption - */ -defined('TESTS_ZEND_CRYPT_OPENSSL_CONF') || define('TESTS_ZEND_CRYPT_OPENSSL_CONF', false); - -/** - * Zend_Db_Adapter_Pdo_Mysql and Zend_Db_Adapter_Mysqli - * - * There are separate properties to enable tests for the PDO_MYSQL adapter and - * the native Mysqli adapters, but the other properties are shared between the - * two MySQL-related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_MYSQLI_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE', 'test'); -defined('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT') || define('TESTS_ZEND_DB_ADAPTER_MYSQL_PORT', 3306); - -/** - * Zend_Db_Adapter_Pdo_Sqlite - * - * Username and password are irrelevant for SQLite. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_SQLITE_DATABASE', ':memory:'); - -/** - * Zend_Db_Adapter_Pdo_Mssql - * - * Note that you need to patch your ntwdblib.dll, the one that - * comes with PHP does not work. See user comments at - * http://us2.php.net/manual/en/ref.mssql.php - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_MSSQL_DATABASE', 'test'); - -/** - * Zend_Db_Adapter_Pdo_Pgsql - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_PDO_PGSQL_DATABASE', 'postgres'); - -/** - * Zend_Db_Adapter_Oracle and Zend_Db_Adapter_Pdo_Oci - * - * There are separate properties to enable tests for the PDO_OCI adapter and - * the native Oracle adapter, but the other properties are shared between the - * two Oracle-related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_OCI_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_ORACLE_SID') || define('TESTS_ZEND_DB_ADAPTER_ORACLE_SID', 'xe'); - -/** - * Zend_Db_Adapter_Db2 and Zend_Db_Adapter_Pdo_Ibm - * There are separate properties to enable tests for the PDO_IBM adapter and - * the native DB2 adapter, but the other properties are shared between the - * two related Zend_Db adapters. - */ -defined('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_PDO_IBM_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_DB2_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_HOSTNAME', '127.0.0.1'); -defined('TESTS_ZEND_DB_ADAPTER_DB2_PORT') || define('TESTS_ZEND_DB_ADAPTER_DB2_PORT', 50000); -defined('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_DB2_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_DB2_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_DB2_DATABASE', 'sample'); - -/** - * Zend_Db_Adapter_Sqlsrv - * Note: Make sure that you create the "test" database and set a - * username and password - * - */ -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_ENABLED', false); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_HOSTNAME', 'localhost\SQLEXPRESS'); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_USERNAME', null); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_PASSWORD', null); -defined('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE') || define('TESTS_ZEND_DB_ADAPTER_SQLSRV_DATABASE', 'test'); - -/** - * Zend_Feed_Reader tests - * - * If the ONLINE_ENABLED property is false, only tests that can be executed - * without network connectivity are run; when enabled, all tests will run. - */ -defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED') || define('TESTS_ZEND_FEED_READER_ONLINE_ENABLED', false); - -/** - * Zend_Gdata tests - * - * If the ONLINE_ENABLED property is false, only tests that can be executed with - * a mock HTTP client are run. No request is sent to the Google Gdata servers. - * If ONLINE_ENABLED is true, some tests may make requests to the remote - * servers. This does not work if you are running tests on a disconnected - * client host. Also, the tests may show as failures if the Google servers - * cannot be reached or if they do not respond for another reason. - * - * If the CLIENTLOGIN_ENABLED property below is false, the authenticated - * tests are reported Skipped in the test run. Set this property to true - * to enable tests that require ClientLogin authentication. Enter your - * Google login credentials in the EMAIL and PASSWORD properties below. - * - * Edit TestConfiguration.php, not TestConfiguration.php.dist. - * Never commit plaintext passwords to the source code repository. - * - * Note: the GData tests currently require that the TZID env variable - * be set or the timezone otherwise configured. You'll see errors from the - * tests if this is not the case. - */ -defined('TESTS_ZEND_GDATA_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_ENABLED', false); - -/* - * The credentials provided here should be only for a TEST account. - * Data for various services in this account may be added to, updated, - * or deleted based upon the actions of these test accounts. - */ -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL', 'example@example.com'); -defined('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD') || define('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD', 'password'); - -/* - * This is the ID of a blank blog. There is no need to have - * any content in this blog. Also, blogs can only be used - * several times for the purpose of these test cases before - * they must be deleted and recreated. Otherwise, the tests - * will start failing, as posts to Blogger will return a 201 Created - * response even though the entry was not posted to the blog. - * This problem is being investigated. - */ -defined('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BLOGGER_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_BLOG_ID') || define('TESTS_ZEND_GDATA_BLOG_ID', '1111111111111111111'); - -/* - * This is the key for a spreadsheet with data only in the first row of - * the spreadsheet. The strings 'a1', 'b1', 'c1', 'd1' should be in the - * corresponding cell locations. - */ -defined('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_SPREADSHEETS_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY') || define('TESTS_ZEND_GDATA_SPREADSHEETS_SPREADSHEETKEY', 'o01111111111111111111.1111111111111111111'); -defined('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID') || define('TESTS_ZEND_GDATA_SPREADSHEETS_WORKSHEETID', 'default'); - -/* - * This indicates that online tests for the Google Calendar API should - * be performed. The default calendar will be used. - */ -defined('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_CALENDAR_ONLINE_ENABLED', false); - -/* - * This is the fully-qualified domain name for a domiain hosted using - * Google Apps. This domain must be registered with Google Apps and - * have API access enabled. This should be a TEST domain only. - */ -defined('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GAPPS_ONLINE_ENABLED', false); -defined('TESTS_ZEND_GDATA_GAPPS_DOMAIN') || define('TESTS_ZEND_GDATA_GAPPS_DOMAIN', 'example.com.invalid'); -defined('TESTS_ZEND_GDATA_GAPPS_EMAIL') || define('TESTS_ZEND_GDATA_GAPPS_EMAIL', 'example@example.com'); -defined('TESTS_ZEND_GDATA_GAPPS_PASSWORD') || define('TESTS_ZEND_GDATA_GAPPS_PASSWORD', 'password'); - -/* - * This is the ONLINE_ENABLED property for Google Base. - */ -defined('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_GBASE_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the Books Search data API - * should be performed. - */ -defined('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_BOOKS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the YouTube data API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_YOUTUBE_ONLINE_ENABLED', false); - -/* - * This is the username to use for retrieving subscriptions, etc - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT') || define('TESTS_ZEND_GDATA_YOUTUBE_ACCOUNT', 'zfgdata'); - -/* - * This is the developer key to access the YouTube API - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY') || define('TESTS_ZEND_GDATA_YOUTUBE_DEVELOPER_KEY', 'your_developer_key_here'); - -/* - * This is the client ID to access the YouTube API - */ -defined('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID') || define('TESTS_ZEND_GDATA_YOUTUBE_CLIENT_ID', 'ZF_UnitTests_unknown'); - -/* - * This indicates that online tests for the Google Documents API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_DOCS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the GData Photos API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_PHOTOS_ONLINE_ENABLED', false); - -/* - * This indicates that online tests for the Google Health API should - * be performed. - */ -defined('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED') || define('TESTS_ZEND_GDATA_HEALTH_ONLINE_ENABLED', false); - -/** - * Zend_Http_Client tests - * - * To enable the dynamic Zend_Http_Client tests, you will need to symbolically - * link or copy the files in tests/Zend/Http/Client/_files to a directory - * under your web server(s) document root and set this constant to point to the - * URL of this directory. - */ -defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') || define('TESTS_ZEND_HTTP_CLIENT_BASEURI', false); - -/** - * Zend_Http_Client_Proxy tests - * - * HTTP proxy to be used for testing the Proxy adapter. Set to a string of - * the form 'host:port'. Set to null to skip HTTP proxy tests. - */ -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY', false); -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_USER', ''); -defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS') || define('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY_PASS', ''); - -/** - * Zend_Loader_Autoloader multi-version support tests - * - * ENABLED: whether or not to run the multi-version tests - * PATH: path to a directory containing multiple ZF version installs - * LATEST: most recent ZF version in the PATH - * e.g., "1.9.2" - * LATEST_MAJOR: most recent ZF major version in the PATH to test against - * e.g., "1.9.2" - * LATEST_MINOR: most recent ZF minor version in the PATH to test against - * e.g., "1.8.4PL1" - * SPECIFIC: specific ZF version in the PATH to test against - * e.g., "1.7.6" - * As an example, consider the following tree: - * ZendFramework/ - * |-- 1.9.2 - * |-- ZendFramework-1.9.1-minimal - * |-- 1.8.4PL1 - * |-- 1.8.4 - * |-- ZendFramework-1.8.3 - * |-- 1.7.8 - * |-- 1.7.7 - * |-- 1.7.6 - * You would then set the value of "LATEST" and "LATEST_MAJOR" to "1.9.2", and - * could choose between "1.9.2", "1.8.4PL1", and "1.7.8" for "LATEST_MINOR", - * and any version number for "SPECIFIC". "PATH" would point to the parent - * "ZendFramework" directory. - */ -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_ENABLED', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_PATH', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MAJOR', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_LATEST_MINOR', false); -defined('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC') || define('TESTS_ZEND_LOADER_AUTOLOADER_MULTIVERSION_SPECIFIC', false); - -/** - * Zend_Ldap online tests - */ -defined('TESTS_ZEND_LDAP_ONLINE_ENABLED') || define('TESTS_ZEND_LDAP_ONLINE_ENABLED', false); - -/* These largely map to the options described in the Zend_Ldap and - * Zend_Auth_Adapter_Ldap documentation. - * - * Example Configuration for Active Directory: - * HOST: dc1.w.net - * USE_START_TLS: true - * USE_SSL: false - * USERNAME: CN=User 1,CN=Users,DC=w,DC=net - * PRINCIPAL_NAME: user1@w.net - * LDAP_PASSWORD: pass1 - * BASE_DN: CN=Users,DC=w,DC=net - * DOMAIN_NAME: w.net - * ACCOUNT_DOMAIN_NAME_SHORT: W - * ALT_USERNAME: user2 - * ALT_DN: CN=User 2,CN=Users,DC=w,DC=net - * ALT_PASSWORD: pass2 - * - * Example Configuration for OpenLDAP - * HOST: s0.foo.net - * USERNAME: CN=user1,DC=foo,DC=net - * PRINCIPAL_NAME: user1@foo.net - * LDAP_PASSWORD: pass1 - * BIND_REQUIRES_DN: true - * BASE_DN: OU=Sales,DC=w,DC=net - * DOMAIN_NAME: foo.net - * ACCOUNT_DOMAIN_NAME_SHORT: FOO - * ALT_USERNAME: abaker - * ALT_DN: CN=Alice Baker,OU=Sales,DC=foo,DC=net - * ALT_PASSWORD: apass - */ -defined('TESTS_ZEND_LDAP_HOST') || define('TESTS_ZEND_LDAP_HOST', 'localhost'); -//defined('TESTS_ZEND_LDAP_PORT') || define('TESTS_ZEND_LDAP_PORT', 389); -defined('TESTS_ZEND_LDAP_USE_START_TLS') || define('TESTS_ZEND_LDAP_USE_START_TLS', true); -//defined('TESTS_ZEND_LDAP_USE_SSL') || define('TESTS_ZEND_LDAP_USE_SSL', false); -defined('TESTS_ZEND_LDAP_USERNAME') || define('TESTS_ZEND_LDAP_USERNAME', 'CN=someUser,DC=example,DC=com'); -defined('TESTS_ZEND_LDAP_PRINCIPAL_NAME') || define('TESTS_ZEND_LDAP_PRINCIPAL_NAME', 'someUser@example.com'); -defined('TESTS_ZEND_LDAP_PASSWORD') || define('TESTS_ZEND_LDAP_PASSWORD', null); -defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN') || define('TESTS_ZEND_LDAP_BIND_REQUIRES_DN', true); -defined('TESTS_ZEND_LDAP_BASE_DN') || define('TESTS_ZEND_LDAP_BASE_DN', 'OU=Sales,DC=example,DC=com'); -//defined('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT') || define('TESTS_ZEND_LDAP_ACCOUNT_FILTER_FORMAT', '(&(objectClass=posixAccount)(uid=%s))'); -defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME', 'example.com'); -defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT') || define('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT', 'EXAMPLE'); -defined('TESTS_ZEND_LDAP_ALT_USERNAME') || define('TESTS_ZEND_LDAP_ALT_USERNAME', 'anotherUser'); -defined('TESTS_ZEND_LDAP_ALT_DN') || define('TESTS_ZEND_LDAP_ALT_DN', 'CN=Another User,OU=Sales,DC=example,DC=com'); -defined('TESTS_ZEND_LDAP_ALT_PASSWORD') || define('TESTS_ZEND_LDAP_ALT_PASSWORD', null); // Used in Zend_Auth_Adapter_Ldap tests -//(defined('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE') || define('TESTS_ZEND_LDAP_WRITEABLE_SUBTREE', 'OU=Test,OU=Sales,DC=example,DC=com'); - -/** - * Zend_Locale tests - * - * If the TESTS_ZEND_LOCALE_FORMAT_SETLOCALE property below is a valid, - * locally recognized locale (try "locale -a"), then all tests in - * tests/Zend/Locale/ test suites will execute *after* - * setlocale(LC_ALL, TESTS_ZEND_LOCALE_FORMAT_SETLOCALE); - * Primarily, this switches certain PHP functions to emit "localized" output, - * including the built-in "to string" for integer and float conversions. - * Thus, a locale of 'fr_FR' yields number-to-string conversions in a - * localized form with the decimal place separator chosen via: - * setlocale(LC_ALL, 'fr_FR@euro'); - */ -//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr'); -//define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', 'fr_FR@euro'); -defined('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE') || define('TESTS_ZEND_LOCALE_FORMAT_SETLOCALE', false); - -/** - * Zend_Date tests - * - * If the BCMATH_ENABLED property below is false, all arithmetic - * operations will use ordinary PHP math operators and functions. - * Otherwise, the bcmath functions will be used for unlimited precision. - * - * If the EXTENDED_COVERAGE property below is false, most of the I18N - * unit tests will not be computed... this speeds tests up to 80 minutes - * when doing reports. * - * Edit TestConfiguration.php, not TestConfiguration.php.dist. - */ -defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED') || define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', true); -defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || define('TESTS_ZEND_I18N_EXTENDED_COVERAGE', true); - -/** - * Zend_Mail_Storage tests - * - * TESTS_ZEND_MAIL_SERVER_TESTDIR and TESTS_ZEND_MAIL_SERVER_FORMAT are used for POP3 and IMAP tests. - * TESTS_ZEND_MAIL_SERVER_FORMAT is the format your test mail server uses: 'mbox' or 'maildir'. The mail - * storage for the user specified in your POP3 or IMAP tests should be TESTS_ZEND_MAIL_SERVER_TESTDIR. Be - * careful: it's cleared before copying the files. If you want to copy the files manually set the dir - * to null (or anything == null). - * - * TESTS_ZEND_MAIL_TEMPDIR is used for testing write operations in local storages. If not set (== null) - * tempnam() is used. - */ -defined('TESTS_ZEND_MAIL_SERVER_TESTDIR') || define('TESTS_ZEND_MAIL_SERVER_TESTDIR', null); -defined('TESTS_ZEND_MAIL_SERVER_FORMAT') || define('TESTS_ZEND_MAIL_SERVER_FORMAT', 'mbox'); -defined('TESTS_ZEND_MAIL_TEMPDIR') || define('TESTS_ZEND_MAIL_TEMPDIR', null); - -/** - * Zend_Mail_Storage_Pop3 / Zend_Mail_Transport_Pop3 - * - * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail - * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR - */ -defined('TESTS_ZEND_MAIL_POP3_ENABLED') || define('TESTS_ZEND_MAIL_POP3_ENABLED', false); -defined('TESTS_ZEND_MAIL_POP3_HOST') || define('TESTS_ZEND_MAIL_POP3_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_POP3_USER') || define('TESTS_ZEND_MAIL_POP3_USER', 'test'); -defined('TESTS_ZEND_MAIL_POP3_PASSWORD') || define('TESTS_ZEND_MAIL_POP3_PASSWORD', ''); -// test SSL connections if enabled in your test server -defined('TESTS_ZEND_MAIL_POP3_SSL') || define('TESTS_ZEND_MAIL_POP3_SSL', true); -defined('TESTS_ZEND_MAIL_POP3_TLS') || define('TESTS_ZEND_MAIL_POP3_TLS', true); -// WRONG_PORT should be an existing server port, -// INVALID_PORT should be a non existing (each on defined host) -defined('TESTS_ZEND_MAIL_POP3_WRONG_PORT') || define('TESTS_ZEND_MAIL_POP3_WRONG_PORT', 80); -defined('TESTS_ZEND_MAIL_POP3_INVALID_PORT') || define('TESTS_ZEND_MAIL_POP3_INVALID_PORT', 3141); - -/** - * Zend_Mail_Storage_Imap / Zend_Mail_Transport_Imap - * - * IMPORTANT: you need to copy tests/Zend/Mail/_files/test.mbox to your mail - * if you haven't set TESTS_ZEND_MAIL_SERVER_TESTDIR - */ -defined('TESTS_ZEND_MAIL_IMAP_ENABLED') || define('TESTS_ZEND_MAIL_IMAP_ENABLED', false); -defined('TESTS_ZEND_MAIL_IMAP_HOST') || define('TESTS_ZEND_MAIL_IMAP_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_IMAP_USER') || define('TESTS_ZEND_MAIL_IMAP_USER', 'test'); -defined('TESTS_ZEND_MAIL_IMAP_PASSWORD') || define('TESTS_ZEND_MAIL_IMAP_PASSWORD', ''); -// test SSL connections if enabled in your test server -defined('TESTS_ZEND_MAIL_IMAP_SSL') || define('TESTS_ZEND_MAIL_IMAP_SSL', true); -defined('TESTS_ZEND_MAIL_IMAP_TLS') || define('TESTS_ZEND_MAIL_IMAP_TLS', true); -// WRONG_PORT should be an existing server port, -// INVALID_PORT should be a non-existing (each on defined host) -defined('TESTS_ZEND_MAIL_IMAP_WRONG_PORT') || define('TESTS_ZEND_MAIL_IMAP_WRONG_PORT', 80); -defined('TESTS_ZEND_MAIL_IMAP_INVALID_PORT') || define('TESTS_ZEND_MAIL_IMAP_INVALID_PORT', 3141); - - -/** - * Zend_Mail_Storage_Maildir test - * - * Before enabling this test you have to unpack messages.tar in - * Zend/Mail/_files/test.maildir/cur/ and remove the tar for this test to work. - * That's because the messages files have a colon in the filename and that's a - * forbidden character on Windows. - */ -defined('TESTS_ZEND_MAIL_MAILDIR_ENABLED') || define('TESTS_ZEND_MAIL_MAILDIR_ENABLED', false); - -/** - * Zend_Mail_Transport_Smtp - * - * @todo TO be implemented - */ -defined('TESTS_ZEND_MAIL_SMTP_ENABLED') || define('TESTS_ZEND_MAIL_SMTP_ENABLED', false); -defined('TESTS_ZEND_MAIL_SMTP_HOST') || define('TESTS_ZEND_MAIL_SMTP_HOST', 'localhost'); -defined('TESTS_ZEND_MAIL_SMTP_PORT') || define('TESTS_ZEND_MAIL_SMTP_PORT', 25); -defined('TESTS_ZEND_MAIL_SMTP_USER') || define('TESTS_ZEND_MAIL_SMTP_USER', 'testuser'); -defined('TESTS_ZEND_MAIL_SMTP_PASSWORD') || define('TESTS_ZEND_MAIL_SMTP_PASSWORD', 'testpassword'); -defined('TESTS_ZEND_MAIL_SMTP_AUTH') || define('TESTS_ZEND_MAIL_SMTP_AUTH', false); -// AUTH can be set to false or a string of AUTH method (e.g. LOGIN, PLAIN, CRAMMD5 or DIGESTMD5) - -/** - * Zend_Queue Test Configuration constants - * - * The Zend_Queue_Adapter_Db constant should be a JSON-encoded string - * representing a configuration object for Zend_Db::factory(). For example: - * { - * type: "pdo_mysql", - * host: "127.0.0.1", - * port: 3306, - * username: "queue", - * password: "queue", - * dbname: "queue" - * } - * - * The PlatformJobQueue adapter expects two parameters, the host and password. - * The HOST string should include both the host and port (typically 10003): - * 127.0.0.1:10003 - * When running tests against PlatformJobQueue, it's best to do so where - * Platform is installed on localhost and has maximum workers set to 20 - * (default is 5); do so with this zend.ini setting: - * zend_jq.max_num_of_request_workers=20 - * - * Selectively define the below in order to run tests for them. - */ -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_SCHEME', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_HOST', false); -defined('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT') || define('TESTS_ZEND_QUEUE_ACTIVEMQ_PORT', false); -defined('TESTS_ZEND_QUEUE_DB_ENABLED') || define('TESTS_ZEND_QUEUE_DB_ENABLED', false); -defined('TESTS_ZEND_QUEUE_DB') || define('TESTS_ZEND_QUEUE_DB', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST', false); -defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT') || define('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_ENABLED', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_HOST', false); -defined('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS') || define('TESTS_ZEND_QUEUE_PLATFORMJQ_PASS', false); - - -/** - * Zend\Service\AgileZen online tests - */ -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_ENABLED',false); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_APIKEY','insert the API key'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_PROJECT_ID','insert the project id'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_STORY_ID','insert the story id'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_EMAIL','insert email for invitation'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_INVITE_ROLE_ID','insert role id for invitation'); -define('TESTS_ZEND_SERVICE_AGILEZEN_ONLINE_MEMBER_NAME','insert the member name to add to the project'); - - -/** - * Zend_Service_Amazon online tests - */ -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID', 'Enter AWSAccessKeyId here'); -defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY') || define('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY', 'Enter AWSSecretKey here'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_IMAGE_ID', 'zftestamazonimageid'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_ZONE', 'us-east-1'); -defined('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP') || define('TESTS_ZEND_SERVICE_AMAZON_EC2_SECURITY_GROUP', 'default'); -defined('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET') || define('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET', 'zftestamazons3bucket'); -defined('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE') || define('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE', 'zftestamazonsqsqueuename'); - -/** - * Zend_Service_Delicious tests - */ -defined('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED') || define('TESTS_ZEND_SERVICE_DELICIOUS_ENABLED', false); - -/** - * Zend_Service_DeveloperGarden tests - * Setup your Username and Password to test this Service - */ -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'ZF_Username'); -defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD') || define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'ZF_Password'); - -/** - * Zend_Service_Flickr online tests - */ -defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY') || define('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY', 'Enter API key here'); - -/** - * Zend_Service_GoGrid offline tests - */ - -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_KEY','insert key here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SECRET','insert secret here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_NAME','test-zf'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IMAGE','insert image name here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_RAM','insert ram name here'); -defined('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP') || define('TESTS_ZEND_SERVICE_GOGRID_ONLINE_SERVER_IP','insert ip here'); - -/** - * Zend\Service\LiveDocx configuration - * - * Define username and password in order to run unit tests for LiveDocx web services. - * - * phpunit/phpunit will typically work. - */ -defined('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_USERNAME', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PASSWORD', false); - -/** - * Zend\Service\LiveDocx premium configuration - * - * Define username, password, WSDL in order to run unit tests for premium LiveDocx web services. - */ -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_USERNAME', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_PASSWORD', false); -defined('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL') || define('TESTS_ZEND_SERVICE_LIVEDOCX_PREMIUM_WSDL', false); - -/** - * Zend_Service_Rackspace tests - */ -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_USER', 'Enter key here'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_KEY', 'Enter secret here'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION') || define('TESTS_ZEND_SERVICE_RACKSPACE_ONLINE_REGION', 'USA'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_CONTAINER_NAME', 'zf-unit-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_OBJECT_NAME','zf-object-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NAME', 'zf-unit-test'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGEID', '49'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_NEW_IMAGEID', '49'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_FLAVORID', '1'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_IMAGE_NAME', 'ZFunitTestImage'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME') || define('TESTS_ZEND_SERVICE_RACKSPACE_SERVER_SHARED_IP_GROUP_NAME', 'ZFgroupIP'); -defined('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT') || define('TESTS_ZEND_SERVICE_RACKSPACE_TIMEOUT', 60); - -/** - * Zend_Service_ReCaptcha tests - */ -defined('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY', 'public key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY', 'private key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY', 'public mailhide key'); -defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY', 'private mailhide key'); - -/** - * Zend_Service_Simpy tests - */ -defined('TESTS_ZEND_SERVICE_SIMPY_ENABLED') || define('TESTS_ZEND_SERVICE_SIMPY_ENABLED', false); -defined('TESTS_ZEND_SERVICE_SIMPY_USERNAME') || define('TESTS_ZEND_SERVICE_SIMPY_USERNAME', 'syapizend'); -defined('TESTS_ZEND_SERVICE_SIMPY_PASSWORD') || define('TESTS_ZEND_SERVICE_SIMPY_PASSWORD', 'mgt37ge'); - -/** - * Zend_Service_SlideShare tests - */ -defined('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME') || define('TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD') || define('TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET', ''); -defined('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY') || define('TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY', ''); - -// The slide show ID to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID') || define('TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID', 0); - -// The tag to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_TAG') || define('TESTS_ZEND_SERVICE_SLIDESHARE_TAG', 'zend'); - -// The group to retrieve during tests -defined('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP') || define('TESTS_ZEND_SERVICE_SLIDESHARE_GROUP', ''); - -/** - * Zend_Service_Twitter tests - * - * ONLINE_ENABLED indicates whether or not to run tests requiring a network - * connection. - * - * TWITTER_USER and TWITTER_PASS are valid Twitter credentials you wish to use - * when testing. - */ -defined('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_TWITTER_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_TWITTER_USER') || define('TESTS_ZEND_SERVICE_TWITTER_USER', 'zftestuser'); -defined('TESTS_ZEND_SERVICE_TWITTER_PASS') || define('TESTS_ZEND_SERVICE_TWITTER_PASS', 'zftestuser'); - -/** - * Zend_Service_WindowsAzure tests - */ - -/** - * Online - */ - -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTNAME',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_ACCOUNTKEY',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_TABLE_HOST',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_HOST',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_PORT',''); -define('TESTS_ZEND_SERVICE_WINDOWSAZURE_ONLINE_STORAGE_PROXY_CREDENTIALS',''); - -/** - * Proxy settings - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_USEPROXY', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY', ''); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_PORT', '8080'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_PROXY_CREDENTIALS', ''); - -/** - * Azure hosts - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_DEV', '127.0.0.1:10000'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_DEV', '127.0.0.1:10001'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_DEV', '127.0.0.1:10002'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_HOST_PROD', 'blob.core.windows.net'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_HOST_PROD', 'queue.core.windows.net'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_HOST_PROD', 'table.core.windows.net'); - -/** - * Credentials - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_DEV', 'devstoreaccount1'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_DEV', 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=='); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_ACCOUNT_PROD', 'phpazure'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_STORAGE_KEY_PROD', 'I+ebYPcIDB6BsmfAe6pJSpOw8oXA6jMBZv1BEZcSPRqTpldt44refCl65YpKJqcBOiD21Lxsj8d6Ah8Oc2/gKA=='); - -/** - * Blob storage tests - */ -// Enable this tests only when you have a working account -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_RUNLARGEBLOB', true); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOB_CONTAINER_PREFIX', 'phpazuretestblob'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSTREAM_CONTAINER_PREFIX', 'phpazureteststream'); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_BLOBSA_CONTAINER_PREFIX', 'phpazuretestshared'); - -/** - * Table storage tests - */ -// Enable this tests only when you have a working account -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_TABLE_TABLENAME_PREFIX', 'phpazuretesttable'); - -/** - * Queue storage tests - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_QUEUE_PREFIX', 'phpazuretestqueue'); - -/** - * SessionHandler tests - */ -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNTESTS', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_RUNONPROD', false); -defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX') || define('TESTS_ZEND_SERVICE_WINDOWSAZURE_SESSIONHANDLER_TABLENAME_PREFIX', 'phpazuretestsession'); - -/** - * Zend_Service_Yahoo online tests - */ -defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_ENABLED', false); -defined('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID') || define('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID', 'Enter APPID here'); - -/** - * Zend_Soap_AutoDiscover scenario tests for complex objects and wsdl generation - * - * Copy all the files of zf/tests/Zend/Soap/_files/fulltests into a directory - * that can be reached by webserver and enter the base uri to this directory - * into the variable. The test "Zend_Soap_AutoDiscover_OnlineTest" makes use - * of the servers and AutoDiscover feature. - * - * NOTE: Make sure the servers are using the correct Zend Framework copy, - * when having more than one version installed and include paths are changing. - */ -defined('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI') || define('TESTS_ZEND_SOAP_AUTODISCOVER_ONLINE_SERVER_BASEURI', false); - -/** - * Zend_Uri tests - * - * Setting CRASH_TEST_ENABLED to true will enable some tests that may - * potentially crash PHP on some systems, due to very deep-nesting regular - * expressions. - * - * Only do this if you know what you are doing! - */ -defined('TESTS_ZEND_URI_CRASH_TEST_ENABLED') || define('TESTS_ZEND_URI_CRASH_TEST_ENABLED', false); - -/** - * Zend_Validate tests - * - * Set ONLINE_ENABLED if you wish to run validators that require network - * connectivity. - */ -defined('TESTS_ZEND_VALIDATE_ONLINE_ENABLED') || define('TESTS_ZEND_VALIDATE_ONLINE_ENABLED', false); - -/** - * PHPUnit Code Coverage / Test Report - */ -defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false); -defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target'); - From 28edaa8079b43ab501779b3074374c890ff4df10 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 21:28:23 +0200 Subject: [PATCH 53/98] Re-enabling components as of @weierophinney suggestions --- .travis/skipped-components | 16 ---------------- .travis/tested-components | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 7d38e2d..6ccd1be 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,27 +1,11 @@ Zend/Amf Zend/Barcode -Zend/Cache -Zend/Code Zend/Date -Zend/Docbook Zend/Feed -Zend/File -Zend/Filter -Zend/GData -Zend/Json -Zend/Locale -Zend/Mail -Zend/Mime -Zend/Navigation -Zend/OpenId Zend/Paginator Zend/Queue -Zend/RegistryTest.php Zend/Service Zend/Session -Zend/Soap Zend/Test Zend/Translator -Zend/Validator Zend/Wildfire -Zend/XmlRpc diff --git a/.travis/tested-components b/.travis/tested-components index 34047ab..da5b101 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -1,40 +1,54 @@ -Zend/Mvc -Zend/View Zend/Acl Zend/Authentication +Zend/Cache Zend/Captcha Zend/Cloud +Zend/Code Zend/Config Zend/Console Zend/Crypt Zend/Currency Zend/Db Zend/Di +Zend/Docbook Zend/Dojo Zend/Dom Zend/EventManager +Zend/File +Zend/Filter Zend/Form +Zend/GData Zend/Http Zend/InfoCard +Zend/Json Zend/Ldap Zend/Loader +Zend/Locale Zend/Log +Zend/Mail Zend/Markup Zend/Measure Zend/Memory +Zend/Mime Zend/Module Zend/Mvc +Zend/Navigation Zend/OAuth +Zend/OpenId Zend/Pdf Zend/ProgressBar +Zend/RegistryTest.php Zend/Rest Zend/Search Zend/Serializer Zend/Server +Zend/Soap Zend/Stdlib Zend/Tag Zend/Text Zend/TimeSync Zend/Uri +Zend/Validator Zend/VersionTest.php Zend/View +Zend/XmlRpc From 21f8e23578f20e3e78a50af5c058802015603373 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 4 Apr 2012 22:16:58 +0200 Subject: [PATCH 54/98] Fixing exit code and output of test runner The test-runner will run all test suites and display their names anyway, then use an appropriate exit code in case of failures. Using the list of components to be tested (was using the skipped components list to be sure that the exit code of the test runner were correct). --- .travis/run-tests.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 47d0c4a..11d98cd 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -2,7 +2,13 @@ travisdir=$(dirname $(readlink /proc/$$/fd/255)) testdir="$travisdir/../tests" testedcomponents=(`cat "$travisdir/tested-components"`) +result=0 for tested in "${testedcomponents[@]}" - do phpunit -c $testdir/phpunit.xml $testdir/$tested + do + echo "$tested:" + phpunit -c $testdir/phpunit.xml $testdir/$tested + let "result = $result || $?" done + +exit $result \ No newline at end of file From 4b5ea1e819e43c3d1debaef23df1b7d43c1371e1 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 9 Apr 2012 11:28:58 -0500 Subject: [PATCH 55/98] [zendframework/zf2#1008] Updated test lists - Moved Session, Paginator to tested-components - Added Zend/Feed/Reader, Writer to tested-components --- .travis/skipped-components | 2 -- .travis/tested-components | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 6ccd1be..6847359 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -2,10 +2,8 @@ Zend/Amf Zend/Barcode Zend/Date Zend/Feed -Zend/Paginator Zend/Queue Zend/Service -Zend/Session Zend/Test Zend/Translator Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components index da5b101..330e5f1 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -14,6 +14,8 @@ Zend/Docbook Zend/Dojo Zend/Dom Zend/EventManager +Zend/Feed/Reader +Zend/Feed/Writer Zend/File Zend/Filter Zend/Form @@ -35,6 +37,7 @@ Zend/Mvc Zend/Navigation Zend/OAuth Zend/OpenId +Zend/Paginator Zend/Pdf Zend/ProgressBar Zend/RegistryTest.php @@ -42,6 +45,7 @@ Zend/Rest Zend/Search Zend/Serializer Zend/Server +Zend/Session Zend/Soap Zend/Stdlib Zend/Tag From 8a71cb0fcc3960f9737c5fa4f2cf83253797f381 Mon Sep 17 00:00:00 2001 From: Gabriel Baker Date: Tue, 24 Apr 2012 21:37:43 +0100 Subject: [PATCH 56/98] Reworked for all the CS stuff --- src/Getopt.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Getopt.php b/src/Getopt.php index b87bb94..7771c0b 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -328,8 +328,8 @@ public function __unset($key) * These are appended to those defined when the constructor was called. * * @param array $argv - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface When not given an array as parameter - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @throws \Zend\Console\Exception\ExceptionInterface When not given an array as parameter + * @return \Zend\Console\Getopt Provides a fluent interface */ public function addArguments($argv) { @@ -346,8 +346,8 @@ public function addArguments($argv) * These replace any currently defined. * * @param array $argv - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface When not given an array as parameter - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @throws \Zend\Console\Exception\ExceptionInterface When not given an array as parameter + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setArguments($argv) { @@ -365,7 +365,7 @@ public function setArguments($argv) * the behavior of Zend_Console_Getopt. * * @param array $getoptConfig - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setOptions($getoptConfig) { @@ -384,7 +384,7 @@ public function setOptions($getoptConfig) * * @param string $configKey * @param string $configValue - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setOption($configKey, $configValue) { @@ -399,7 +399,7 @@ public function setOption($configKey, $configValue) * These are appended to the rules defined when the constructor was called. * * @param array $rules - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function addRules($rules) { @@ -613,8 +613,8 @@ public function getUsageMessage() * mapping option name (short or long) to an alias. * * @param array $aliasMap - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @throws \Zend\Console\Exception\ExceptionInterface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setAliases($aliasMap) { @@ -645,7 +645,7 @@ public function setAliases($aliasMap) * mapping option name (short or long) to the help string. * * @param array $helpMap - * @return \Zend\Console\Getopt\Getopt Provides a fluent interface + * @return \Zend\Console\Getopt Provides a fluent interface */ public function setHelp($helpMap) { @@ -667,7 +667,7 @@ public function setHelp($helpMap) * Also find option parameters, and remaining arguments after * all options have been parsed. * - * @return \Zend\Console\Getopt\Getopt|null Provides a fluent interface + * @return \Zend\Console\Getopt|null Provides a fluent interface */ public function parse() { @@ -745,7 +745,7 @@ protected function _parseShortOptionCluster(&$argv) * * @param string $flag * @param mixed $argv - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface + * @throws \Zend\Console\Exception\ExceptionInterface * @return void */ protected function _parseSingleOption($flag, &$argv) @@ -882,7 +882,7 @@ protected function _setBooleanFlagValue($flag) * * @param string $flag * @param string $param - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface + * @throws \Zend\Console\Exception\ExceptionInterface * @return bool */ protected function _checkParameterType($flag, $param) @@ -951,7 +951,7 @@ protected function _addRulesModeGnu($rules) * Define legal options using the Zend-style format. * * @param array $rules - * @throws \Zend\Console\Getopt\Exception\ExceptionInterface + * @throws \Zend\Console\Exception\ExceptionInterface * @return void */ protected function _addRulesModeZend($rules) From 40b8ac3ff44950b3fdd5ec5886bab9987fda62f5 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 9 May 2012 11:28:05 -0500 Subject: [PATCH 57/98] Remove --stderr switch from Travis test runner - Appears that it may not be necessary --- .travis/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 1ba31be..9334e95 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -7,7 +7,7 @@ result=0 for tested in "${testedcomponents[@]}" do echo "$tested:" - phpunit -c $testdir/phpunit.xml --stderr $testdir/$tested + phpunit -c $testdir/phpunit.xml $testdir/$tested result=$(($result || $?)) done From cffe7d49fcb113b219e7d81c5f1a4e798d004cda Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 11 May 2012 11:06:08 +0200 Subject: [PATCH 58/98] [Tests] Update Travis script --- .travis/run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh index 9334e95..7e1baa3 100755 --- a/.travis/run-tests.sh +++ b/.travis/run-tests.sh @@ -7,7 +7,7 @@ result=0 for tested in "${testedcomponents[@]}" do echo "$tested:" - phpunit -c $testdir/phpunit.xml $testdir/$tested + phpunit -c $testdir/phpunit.xml.dist $testdir/$tested result=$(($result || $?)) done From b129c6e817e59daa067f1c891dec5542449532bb Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 11:41:23 -0500 Subject: [PATCH 59/98] [zen-27][zendframework/zf2#1198] travis update - Remove Zend\Feed from skipped components list --- .travis/skipped-components | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index 6847359..0790ed2 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,7 +1,6 @@ Zend/Amf Zend/Barcode Zend/Date -Zend/Feed Zend/Queue Zend/Service Zend/Test From 1c712e6cd43e204e486dd95253240f0ed6df47fc Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 12:18:48 -0500 Subject: [PATCH 60/98] [zen-27][zendframework/zf2#1199] Fix Translator tests - Fixes log setup and usage in tests and code for Translator - Re-enabled Translator tests, as they now appear to work --- .travis/skipped-components | 1 - .travis/tested-components | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/skipped-components b/.travis/skipped-components index c4cd706..31bcaa8 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -3,5 +3,4 @@ Zend/Date Zend/Queue Zend/Service Zend/Test -Zend/Translator Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components index d1d7133..b1f4a79 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -51,6 +51,7 @@ Zend/Stdlib Zend/Tag Zend/Text Zend/TimeSync +Zend/Translator Zend/Uri Zend/Validator Zend/VersionTest.php From 4ed7535c75da8984c3593881f6078fb136e5dfb1 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 11 May 2012 08:17:31 -0500 Subject: [PATCH 61/98] [zen-12] Removed Dojo from test suite - Dojo integration largely relied on integration with Zend\Form; removing from testing for now, as it has not been refactored to work with the new Zend\Form code. --- .travis/skipped-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/skipped-components b/.travis/skipped-components index 31bcaa8..171dfe9 100644 --- a/.travis/skipped-components +++ b/.travis/skipped-components @@ -1,5 +1,6 @@ Zend/Amf Zend/Date +Zend/Dojo Zend/Queue Zend/Service Zend/Test From 5c5ee17488a31a55f4c39c638ef609b32e23960d Mon Sep 17 00:00:00 2001 From: Maks3w Date: Fri, 18 May 2012 00:22:37 +0200 Subject: [PATCH 62/98] [Travis] Enable Zend\Math tests --- .travis/tested-components | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis/tested-components b/.travis/tested-components index b1f4a79..9b33820 100644 --- a/.travis/tested-components +++ b/.travis/tested-components @@ -29,6 +29,7 @@ Zend/Locale Zend/Log Zend/Mail Zend/Markup +Zend/Math Zend/Measure Zend/Memory Zend/Mime From aabf95ed00109566dce0f799705a87c042b0ca76 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:19:42 +0200 Subject: [PATCH 63/98] [CS][Library] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:34:21 +0200 Subject: [PATCH 64/98] [CS][test] Remove @copyright & @license for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@copyright/d' $fl.old > $fl; rm -f $fl.old; done; for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@license/d' $fl.old > $fl; rm -f $fl.old; done; --- test/GetoptTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index ed9a175..b34188b 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Console * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Console; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Console * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Console */ class GetoptTest extends \PHPUnit_Framework_TestCase From 8937961843815787eb3a0a535c7f201b7fa459f0 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:41:27 +0200 Subject: [PATCH 65/98] [CS][Tests] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Wed, 11 Jul 2012 22:20:59 +0200 Subject: [PATCH 66/98] Add blank lines around the use block --- test/GetoptTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 5b3500e..cb58c06 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -9,6 +9,7 @@ */ namespace ZendTest\Console; + use Zend\Console\Getopt; use Zend\Console\GetoptException; From e53a2678042acd02daacfaa48d3ca87e0042d4aa Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 67/98] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/Exception/InvalidArgumentException.php | 4 ++-- src/Getopt.php | 17 +++++++---------- test/GetoptTest.php | 12 ++++++------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index abd21dd..a00add4 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -14,5 +14,5 @@ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { - -} + +} diff --git a/src/Getopt.php b/src/Getopt.php index 2113acb..22aa8f1 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -603,8 +603,7 @@ public function getUsageMessage() */ public function setAliases($aliasMap) { - foreach ($aliasMap as $flag => $alias) - { + foreach ($aliasMap as $flag => $alias) { if ($this->_getoptConfig[self::CONFIG_IGNORECASE]) { $flag = strtolower($flag); $alias = strtolower($alias); @@ -634,8 +633,7 @@ public function setAliases($aliasMap) */ public function setHelp($helpMap) { - foreach ($helpMap as $flag => $help) - { + foreach ($helpMap as $flag => $help) { if (!isset($this->_ruleMap[$flag])) { continue; } @@ -672,7 +670,7 @@ public function parse() } if (substr($argv[0], 0, 2) == '--') { $this->_parseLongOption($argv); - } else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) { + } elseif (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) { $this->_parseShortOptionCluster($argv); } else if($this->_getoptConfig[self::CONFIG_PARSEALL]) { $this->_remainingArgs[] = array_shift($argv); @@ -760,7 +758,7 @@ protected function _parseSingleOption($flag, &$argv) } else { $realFlag = $this->_ruleMap[$flag]; } - + switch ($this->_rules[$realFlag]['param']) { case 'required': if (count($argv) > 0) { @@ -810,10 +808,10 @@ protected function _setNumericOptionValue($value) return $this->_setSingleOptionValue($this->_getoptConfig['numericFlagsOption'], $value); } - + /** * Add relative to options' flag value - * + * * If options list already has current flag as key * and parser should follow cumulative params by configuration, * we should to add new param to array, not to overwrite @@ -941,8 +939,7 @@ protected function _addRulesModeGnu($rules) */ protected function _addRulesModeZend($rules) { - foreach ($rules as $ruleCode => $helpMessage) - { + foreach ($rules as $ruleCode => $helpMessage) { // this may have to translate the long parm type if there // are any complaints that =string will not work (even though that use // case is not documented) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index cb58c06..3ef5cba 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -227,7 +227,7 @@ public function testGetoptUnSetBeforeParse() unset($opts->a); $this->assertFalse(isset($opts->a)); } - + /** * @group ZF-5948 */ @@ -319,7 +319,7 @@ public function testGetoptSetAliasesWithNamingConflict() { $opts = new Getopt('abp:', array('--apple')); $opts->setAliases(array('a' => 'apple')); - + $this->setExpectedException('\Zend\Console\Exception\InvalidArgumentException', 'defined more than once'); $opts->setAliases(array('b' => 'apple')); } @@ -329,7 +329,7 @@ public function testGetoptSetAliasesInvalid() $opts = new Getopt('abp:', array('--apple')); $opts->setAliases(array('c' => 'cumquat')); $opts->setArguments(array('-c')); - + $this->setExpectedException('\Zend\Console\Exception\RuntimeException', 'not recognized'); $opts->parse(); } @@ -490,7 +490,7 @@ public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemain public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException() { $opts = new Getopt("abp:", array("-", "file1")); - + $this->setExpectedException('\Zend\Console\Exception\RuntimeException'); $opts->parse(); } @@ -515,7 +515,7 @@ public function testGetoptIgnoreCumulativeParamsByDefault() array('colors=s' => 'Colors-option'), array('--colors=red', '--colors=green', '--colors=blue') ); - + $this->assertInternalType('string', $opts->colors); $this->assertEquals('blue', $opts->colors, 'Should be equal to last variable'); } @@ -535,7 +535,7 @@ public function testGetoptWithCumulativeParamsOptionHandleArrayValues() public function testGetoptIgnoreCumulativeFlagsByDefault() { $opts = new Getopt('v', array('-v', '-v', '-v')); - + $this->assertEquals(true, $opts->v); } From 98864c07dd38366aa72e80bcd6280037d7d68fec Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Sun, 15 Jul 2012 13:14:25 +0200 Subject: [PATCH 68/98] Refactor to latest zf2 master, prepare for Console-specific bootstrapping and dispatch. - WIP, unstable! - Refactor to use ArrayUtils. - Refactor to new class and interface names after zf2 beta4. - Move all strategies from Zend\Mvc\View\* to Zend\Mvc\View\Http. This allows for separation of behavior for rendering Http content as opposed to Console content. - Request, Response and ViewManager services in SM are now created via factories, which choose Http/Console classes depending on current environment. - Console adapter and charset is now created by a SM factory. It is auto-detected by default, but can be forced to a specific class (or instantiated by custom factory) by setting config variables "console.adapter" and "console.charset". If not in an Console environment, the factory will return dummy stdClass thus preventing any potentially unsafe console operations. - Zend\View\Model\ConsoleModel errorLevel is now stored as an option, thus allowing to be set using standard methods. - Zend\Console\Console::detectBestAdapter() now properly returns an adapter, or null if not in a console env. --- src/Console.php | 23 ++++++++++++++++------- src/Request.php | 29 ++++++++++++++--------------- src/Response.php | 6 +++--- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Console.php b/src/Console.php index 3b668a8..4b3e8e7 100644 --- a/src/Console.php +++ b/src/Console.php @@ -75,7 +75,6 @@ static public function getInstance($forceAdapter = null, $forceCharset = null){ */ static::$instance->setCharset(new $className()); } - } return static::$instance; @@ -113,18 +112,28 @@ static public function isConsole(){ /** * @static - * @return \Zend\Console\Adapter + * @return \Zend\Console\Adapter|null */ - static protected function detectBestAdapter(){ + static public function detectBestAdapter(){ + // Check if we are in a console environment + if(!static::isConsole()){ + return null; + } + + // Check if we're on windows if(static::isWindows()){ if(static::isAnsicon()){ - return __NAMESPACE__.'\Adapter\WindowsAnsicon'; + $className = __NAMESPACE__.'\Adapter\WindowsAnsicon'; }else{ - return __NAMESPACE__.'\Adapter\Windows'; + $className = __NAMESPACE__.'\Adapter\Windows'; } - }else{ - return __NAMESPACE__.'\Adapter\Posix'; + + return new $className(); } + + // Default is a Posix console + $className = __NAMESPACE__.'\Adapter\Posix'; + return new $className(); } /** diff --git a/src/Request.php b/src/Request.php index 5b8eba0..4ed3fc8 100644 --- a/src/Request.php +++ b/src/Request.php @@ -2,21 +2,20 @@ namespace Zend\Console; -use Zend\Stdlib\RequestDescription, - Zend\Stdlib\Message, - Zend\Stdlib\ParametersDescription, - Zend\Stdlib\Parameters -; +use Zend\Stdlib\Message; +use Zend\Stdlib\Parameters; +use Zend\Stdlib\ParametersInterface; +use Zend\Stdlib\RequestInterface; -class Request extends Message implements RequestDescription +class Request extends Message implements RequestInterface { /** - * @var \Zend\Stdlib\ParametersDescription + * @var \Zend\Stdlib\Parameters */ protected $params = null; /** - * @var \Zend\Stdlib\ParametersDescription + * @var \Zend\Stdlib\Parameters */ protected $envParams = null; @@ -68,10 +67,10 @@ public function __construct(array $args = null, array $env = null) /** * Exchange parameters object * - * @param \Zend\Stdlib\ParametersDescription $params + * @param \Zend\Stdlib\Parameters $params * @return Request */ - public function setParams(ParametersDescription $params) + public function setParams(Parameters $params) { $this->params = $params; $this->setContent($params); @@ -81,7 +80,7 @@ public function setParams(ParametersDescription $params) /** * Return the container responsible for parameters * - * @return \Zend\Stdlib\ParametersDescription + * @return \Zend\Stdlib\Parameters */ public function getParams() { @@ -108,7 +107,7 @@ public function getParam($name, $default = null) /** * Return the container responsible for parameters * - * @return \Zend\Stdlib\ParametersDescription + * @return \Zend\Stdlib\Parameters */ public function params() { @@ -123,10 +122,10 @@ public function params() * Provide an alternate Parameter Container implementation for env parameters in this object, (this is NOT the * primary API for value setting, for that see env()) * - * @param \Zend\Stdlib\ParametersDescription $env + * @param \Zend\Stdlib\Parameters $env * @return \Zend\Console\Request */ - public function setEnv(ParametersDescription $env) + public function setEnv(Parameters $env) { $this->envParams = $env; return $this; @@ -135,7 +134,7 @@ public function setEnv(ParametersDescription $env) /** * Return the parameter container responsible for env parameters * - * @return \Zend\Stdlib\ParametersDescription + * @return \Zend\Stdlib\Parameters */ public function env() { diff --git a/src/Response.php b/src/Response.php index 0ff1676..76df74e 100644 --- a/src/Response.php +++ b/src/Response.php @@ -2,9 +2,9 @@ namespace Zend\Console; -use Zend\Stdlib\Message, - Zend\Stdlib\ResponseDescription; +use Zend\Stdlib\Message; +use Zend\Stdlib\ResponseInterface; -class Response extends Message implements ResponseDescription +class Response extends Message implements ResponseInterface { } From 118a13652f4ab32e506125c520e515692de1bb1f Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Sun, 15 Jul 2012 19:30:22 +0200 Subject: [PATCH 69/98] [WIP] Introduce Console rendering strategies and more incremental changes. - Console\Response now supports setting and getting errorLevel (stored as metadata). - Console\Response now properly supports send()ing, including exiting the application with an error level. - Add Mvc\View\Console\DefaultRenderingStrategy for building console response from plain-text action controller responses. - Currently, the default console rendering strategy does NOT use Zend\View nor Rendering to produce responses (it just concatenates plain-text responses from controllers and puts them into console response object) - Remove View\Strategy\ConsoleStrategy because of its bad design. --- src/Response.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Response.php b/src/Response.php index 76df74e..0c8ff6d 100644 --- a/src/Response.php +++ b/src/Response.php @@ -7,4 +7,47 @@ class Response extends Message implements ResponseInterface { + protected $contentSent = false; + + public function contentSent() + { + return $this->contentSent; + } + + /** + * Set the error level that will be returned to shell. + * + * @param integer $errorLevel + * @return Response + */ + public function setErrorLevel($errorLevel){ + $this->setMetadata('errorLevel', $errorLevel); + return $this; + } + + /** + * Get response error level that will be returned to shell. + * + * @return integer|0 + */ + public function getErrorLevel(){ + return $this->getMetadata('errorLevel', 0); + } + + public function sendContent() + { + if ($this->contentSent()) { + return $this; + } + echo $this->getContent(); + $this->contentSent = true; + return $this; + } + + public function send() + { + $this->sendContent(); + $errorLevel = (int)$this->getMetadata('errorLevel',0); + exit($errorLevel); + } } From 5ad0d0ce82b8f910b10ce50a26ced0410c8aea45 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Mon, 16 Jul 2012 14:52:31 +0200 Subject: [PATCH 70/98] [WIP] Fix Console view model rendering (outputing) - fix collection of textual results from view models and appending them to the final response. - remove createViewModelFromString() from previous Mvc\View\Http\CreateviewModelListener. - add View\Model\ModelInterface::getVariable() for fetching a single variable. - fix probe command result parsing in Console\Adapter\Windows. --- src/Adapter/Windows.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 22825a6..5a91a27 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -74,10 +74,10 @@ protected function runProbeCommand(){ $output, $return ); - if($return || !$output){ + if($return || empty($output)){ $this->probeResult = ''; }else{ - $this->probeResult = trim($output); + $this->probeResult = trim(join("\n",$output)); } } From b37eb8411a8f5df0cf9dc3aa566a90cfc8b75978 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Thu, 19 Jul 2012 21:48:18 +0200 Subject: [PATCH 71/98] Fix Console\Adapter\Windows getWidth() and getHeight() causing hangs. In some scenarios a call to getWidth() or getHeight() might have hanged the application, because Powershell was creating a subthread for the command. A new way of calling Powershell resolved this issue. --- src/Adapter/Windows.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 5a91a27..a48b742 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -32,8 +32,8 @@ public function getWidth(){ $this->runProbeCommand(); } - if(preg_match('/^(\d+)\t/s',$this->probeResult,$matches)){ - $width = $matches[1]; + if(count($this->probeResult) && (int)$this->probeResult[0]){ + $width = (int)$this->probeResult[0]; }else{ $width = parent::getWidth(); } @@ -59,8 +59,8 @@ public function getHeight(){ $this->runProbeCommand(); } - if(preg_match('/^\d+\t(\d+)/s',$this->probeResult,$matches)){ - $height = $matches[1]; + if(count($this->probeResult) && (int)$this->probeResult[1]){ + $height = (int)$this->probeResult[1]; }else{ $height = parent::getheight(); } @@ -69,15 +69,20 @@ public function getHeight(){ } protected function runProbeCommand(){ + /** + * Run a Windows Powershell command that determines parameters of console window. The command is fed through + * standard input (with echo) to prevent Powershell from creating a sub-thread and hanging PHP when run through + * a debugger/IDE. + */ exec( - 'powershell -command "$size = $Host.ui.rawui.windowsize; write ""$($size.width)`t$($size.height)"""', + 'echo $size = $Host.ui.rawui.windowsize; write $($size.width) $($size.height) | powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command -', $output, $return ); if($return || empty($output)){ $this->probeResult = ''; }else{ - $this->probeResult = trim(join("\n",$output)); + $this->probeResult = $output; } } From 4675c00453a344d547edad350dcc8320cdb78c0a Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 22 Jul 2012 09:26:46 +0200 Subject: [PATCH 72/98] Expand use statements to multi-line --- src/Adapter/AbstractAdapter.php | 12 +++++------- src/Adapter/Posix.php | 11 +++++------ src/Adapter/Virtual.php | 12 +++++------- src/Adapter/Windows.php | 12 +++++------- src/Adapter/WindowsAnsicon.php | 11 +++++------ src/Prompt/AbstractPrompt.php | 9 ++++----- 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 6cc0250..ef1e01d 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -1,12 +1,10 @@ console = $adapter; } -} \ No newline at end of file +} From b142aeb7ccc214643e39ee3e39eb6b25e11be0ae Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 22 Jul 2012 09:30:16 +0200 Subject: [PATCH 73/98] Remove @abstract statements from Zend\Console --- src/Adapter.php | 38 +------------------------------------- src/Console.php | 1 - src/Prompt.php | 4 ---- 3 files changed, 1 insertion(+), 42 deletions(-) diff --git a/src/Adapter.php b/src/Adapter.php index efb39d4..55510a3 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -35,7 +35,6 @@ public function writeText($text, $color = null, $bgColor = null); * Write a single line of text to console and advance cursor to the next line. * If the text is longer than console width it will be truncated. * - * @abstract * @param string $text * @param null|int $color * @param null|int $bgColor @@ -45,7 +44,6 @@ public function writeLine($text = "", $color = null, $bgColor = null); /** * Write a piece of text at the coordinates of $x and $y * - * @abstract * @param string $text Text to write * @param int $x Console X coordinate (column) * @param int $y Console Y coordinate (row) @@ -59,7 +57,6 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null); * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge * of the console (respectively). * - * @abstract * @param int $x1 Top-left corner X coordinate (column) * @param int $y1 Top-left corner Y coordinate (row) * @param int $x2 Bottom-right corner X coordinate (column) @@ -82,7 +79,6 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * @abstract * @param string $text Text to write * @param int $width Maximum block width. Negative value means distance from right edge. * @param int|null $height Maximum block height. Negative value means distance from bottom edge. @@ -101,7 +97,6 @@ public function writeTextBlock( /** * Determine and return current console width. * - * @abstract * @return int */ public function getWidth(); @@ -109,7 +104,6 @@ public function getWidth(); /** * Determine and return current console height. * - * @abstract * @return int */ public function getHeight(); @@ -117,7 +111,6 @@ public function getHeight(); /** * Determine and return current console width and height. * - * @abstract * @return array array($width, $height) */ public function getSize(); @@ -125,7 +118,6 @@ public function getSize(); /** * Check if console is UTF-8 compatible * - * @abstract * @return bool */ public function isUtf8(); @@ -134,7 +126,6 @@ public function isUtf8(); // /** // * Return current cursor position - array($x, $y) // * -// * @abstract // * @return array array($x, $y); // */ // public function getPos(); @@ -142,7 +133,6 @@ public function isUtf8(); // /** // * Return current cursor X coordinate (column) // * -// * @abstract // * @return false|int Integer or false if failed to determine. // */ // public function getX(); @@ -150,7 +140,6 @@ public function isUtf8(); // /** // * Return current cursor Y coordinate (row) // * -// * @abstract // * @return false|int Integer or false if failed to determine. // */ // public function getY(); @@ -158,7 +147,6 @@ public function isUtf8(); /** * Set cursor position * - * @abstract * @param int $x * @param int $y */ @@ -166,22 +154,17 @@ public function setPos($x, $y); /** * Hide console cursor - * - * @abstract */ public function hideCursor(); /** * Show console cursor - * - * @abstract */ public function showCursor(); /** * Return current console window title. * - * @abstract * @return string */ public function getTitle(); @@ -189,15 +172,12 @@ public function getTitle(); /** * Set console window title * - * @abstract * @param $title */ public function setTitle($title); /** * Reset console window title to previous value. - * - * @abstract */ public function resetTitle(); @@ -205,7 +185,6 @@ public function resetTitle(); /** * Prepare a string that will be rendered in color. * - * @abstract * @param string $string * @param null|int $color Foreground color * @param null|int $bgColor Background color @@ -215,7 +194,6 @@ public function colorize($string, $color = null, $bgColor = null); /** * Change current drawing color. * - * @abstract * @param int $color */ public function setColor($color); @@ -223,15 +201,12 @@ public function setColor($color); /** * Change current drawing background color * - * @abstract * @param int $color */ public function setBgColor($color); /** * Reset color to console default. - * - * @abstract */ public function resetColor(); @@ -239,7 +214,6 @@ public function resetColor(); /** * Set Console charset to use. * - * @abstract * @param \Zend\Console\Charset $charset */ public function setCharset(Charset $charset); @@ -247,42 +221,33 @@ public function setCharset(Charset $charset); /** * Get charset currently in use by this adapter. * - * @abstract * @return \Zend\Console\Charset $charset */ public function getCharset(); /** - * @abstract * @return \Zend\Console\Charset */ public function getDefaultCharset(); /** * Clear console screen - * - * @abstract */ public function clear(); /** * Clear line at cursor position - * - * @abstract */ public function clearLine(); /** * Clear console screen - * - * @abstract */ public function clearScreen(); /** * Read a single line from the console input * - * @abstract * @param int $maxLength Maximum response length * @return string */ @@ -291,9 +256,8 @@ public function readLine($maxLength = 2048); /** * Read a single character from the console input * - * @abstract * @param string|null $mask A list of allowed chars * @return string */ public function readChar($mask = null); -} \ No newline at end of file +} diff --git a/src/Console.php b/src/Console.php index 4b3e8e7..f774c10 100644 --- a/src/Console.php +++ b/src/Console.php @@ -5,7 +5,6 @@ * An static, utility class for interacting with Console enviromen. * Declared abstract to prevent from instantiating. * - * @abstract */ abstract class Console { diff --git a/src/Prompt.php b/src/Prompt.php index bc8b87a..fc06607 100644 --- a/src/Prompt.php +++ b/src/Prompt.php @@ -8,7 +8,6 @@ interface Prompt { /** * Show the prompt to user and return the answer. * - * @abstract * @return mixed */ public function show(); @@ -16,7 +15,6 @@ public function show(); /** * Return last answer to this prompt. * - * @abstract * @return mixed */ public function getLastResponse(); @@ -24,7 +22,6 @@ public function getLastResponse(); /** * Return console adapter to use when showing prompt. * - * @abstract * @return \Zend\Console\Adapter */ public function getConsole(); @@ -32,7 +29,6 @@ public function getConsole(); /** * Set console adapter to use when showing prompt. * - * @abstract * @param \Zend\Console\Adapter $adapter */ public function setConsole(ConsoleAdapter $adapter); From 7a69dda2af67b537384ad785fedadbc4f49e7ca3 Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 22 Jul 2012 09:48:58 +0200 Subject: [PATCH 74/98] Add suffix Interface to all interfaces --- src/Adapter/AbstractAdapter.php | 18 +++++++++--------- src/Adapter/Posix.php | 18 +++++++++--------- src/Adapter/Virtual.php | 16 ++++++++-------- src/Adapter/Windows.php | 16 ++++++++-------- src/Adapter/WindowsAnsicon.php | 16 ++++++++-------- src/{Adapter.php => AdapterInterface.php} | 2 +- src/Charset/Ascii.php | 6 +++--- src/Charset/AsciiExtended.php | 6 +++--- src/Charset/DECSG.php | 6 +++--- src/Charset/Utf8.php | 6 +++--- src/{Charset.php => CharsetInterface.php} | 4 ++-- src/{Color.php => ColorInterface.php} | 4 ++-- src/Prompt/AbstractPrompt.php | 12 ++++++------ src/Prompt/Char.php | 6 +++--- src/Prompt/Confirm.php | 6 +++--- src/Prompt/Line.php | 6 +++--- src/Prompt/Number.php | 6 +++--- src/Prompt/Select.php | 6 +++--- src/{Prompt.php => PromptInterface.php} | 2 +- 19 files changed, 81 insertions(+), 81 deletions(-) rename src/{Adapter.php => AdapterInterface.php} (99%) rename src/{Charset.php => CharsetInterface.php} (50%) rename src/{Color.php => ColorInterface.php} (94%) rename src/{Prompt.php => PromptInterface.php} (95%) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index ef1e01d..340cec7 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -1,17 +1,17 @@ charset = $charset; } @@ -481,7 +481,7 @@ public function setCharset(Charset $charset) /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset() { @@ -493,7 +493,7 @@ public function getCharset() } /** - * @return \Zend\Console\Charset + * @return \Zend\Console\Charset\Utf8 */ public function getDefaultCharset() { diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 0224c36..e50f573 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -1,20 +1,20 @@ charset = $charset; } /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset(){ if($this->charset === null){ diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index f5b937f..f2d1e7e 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -1,15 +1,15 @@ charset = $charset; } /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset(){ if($this->charset === null){ @@ -147,7 +147,7 @@ public function getCharset(){ } /** - * @return \Zend\Console\Charset + * @return \Zend\Console\Charset\AsciiExtended */ public function getDefaultCharset(){ return new Charset\AsciiExtended; diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 2924f5b..b5a1715 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -1,12 +1,12 @@ charset = $charset; } /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset(){ if($this->charset === null){ @@ -153,7 +153,7 @@ public function getCharset(){ } /** - * @return \Zend\Console\Charset + * @return \Zend\Console\Charset\AsciiExtended */ public function getDefaultCharset(){ return new Charset\AsciiExtended; diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index b13e5e2..d91eedf 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -1,9 +1,9 @@ charset = $charset; } @@ -147,7 +147,7 @@ public function setCharset(Charset $charset){ * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset(){ if($this->charset === null){ @@ -158,7 +158,7 @@ public function getCharset(){ } /** - * @return \Zend\Console\Charset + * @return \Zend\Console\Charset\AsciiExtended */ public function getDefaultCharset(){ return new Charset\AsciiExtended(); diff --git a/src/Adapter.php b/src/AdapterInterface.php similarity index 99% rename from src/Adapter.php rename to src/AdapterInterface.php index 55510a3..29fd627 100644 --- a/src/Adapter.php +++ b/src/AdapterInterface.php @@ -1,7 +1,7 @@ console){ @@ -44,7 +44,7 @@ public function getConsole(){ /** * Set console adapter to use when showing prompt. * - * @param \Zend\Console\Adapter $adapter + * @param \Zend\Console\AdapterInterface $adapter */ public function setConsole(ConsoleAdapter $adapter){ $this->console = $adapter; diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 9e4d50d..faa8366 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -1,9 +1,9 @@ echo; } -} \ No newline at end of file +} diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 50b606c..d41f354 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -1,9 +1,9 @@ yesChar; } -} \ No newline at end of file +} diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 3cf37c9..60896f0 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -1,9 +1,9 @@ promptText; } -} \ No newline at end of file +} diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index 8440290..da505b5 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -1,9 +1,9 @@ allowFloat; } -} \ No newline at end of file +} diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 408cbc6..a651827 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -1,9 +1,9 @@ options; } -} \ No newline at end of file +} diff --git a/src/Prompt.php b/src/PromptInterface.php similarity index 95% rename from src/Prompt.php rename to src/PromptInterface.php index fc06607..f817928 100644 --- a/src/Prompt.php +++ b/src/PromptInterface.php @@ -3,7 +3,7 @@ use Zend\Console\Adapter as ConsoleAdapter; -interface Prompt { +interface PromptInterface { /** * Show the prompt to user and return the answer. From d6ae3491ca45d91cf370dbc382b91de6caa8f64e Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 22 Jul 2012 14:15:02 +0200 Subject: [PATCH 75/98] Use Zend\Console\Exception\* instead of SPL --- src/Adapter/AbstractAdapter.php | 3 ++- src/Adapter/Posix.php | 9 +++++---- src/Adapter/Windows.php | 3 ++- src/Adapter/WindowsAnsicon.php | 3 ++- src/Console.php | 6 ++++-- src/Prompt/Select.php | 5 +++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 340cec7..ba38302 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -4,6 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; +use Zend\Console\Exception\BadMethodCallException; use Zend\Console; abstract class AbstractAdapter implements AdapterInterface @@ -155,7 +156,7 @@ public function writeBox( $x2 < $x1 || $y2 < $y1 ) { - throw new \BadMethodCallException('Supplied X,Y coordinates are invalid.'); + throw new BadMethodCallException('Supplied X,Y coordinates are invalid.'); } /** diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index e50f573..6d1cc35 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -4,6 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface as Color; use Zend\Console\CharsetInterface; +use Zend\Console\Exception\BadMethodCallException; use Zend\Console; /** @@ -200,7 +201,7 @@ public function colorize($string, $color = null, $bgColor = null) */ if($color !== null){ if(!isset(static::$ansiColorMap['fg'][$color])){ - throw new \BadMethodCallException( + throw new BadMethodCallException( 'Unknown color "'.$color.'". Please use one of Zend\Console\Color constants.' ); }else{ @@ -209,7 +210,7 @@ public function colorize($string, $color = null, $bgColor = null) } if($bgColor !== null){ if(!isset(static::$ansiColorMap['bg'][$bgColor])){ - throw new \BadMethodCallException( + throw new BadMethodCallException( 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\Color constants.' ); }else{ @@ -237,7 +238,7 @@ public function setColor($color) */ if($color !== null){ if(!isset(static::$ansiColorMap['fg'][$color])){ - throw new \BadMethodCallException( + throw new BadMethodCallException( 'Unknown color "'.$color.'". Please use one of Zend\Console\Color constants.' ); }else{ @@ -260,7 +261,7 @@ public function setBgColor($bgColor) */ if($bgColor !== null){ if(!isset(static::$ansiColorMap['bg'][$bgColor])){ - throw new \BadMethodCallException( + throw new BadMethodCallException( 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\Color constants.' ); }else{ diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index b5a1715..38371d3 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -4,6 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; +use Zend\Console\Exception\BadMethodCallException; use Zend\Console; class Windows extends Virtual implements AdapterInterface @@ -199,7 +200,7 @@ public function readChar($mask = null){ */ system('choice /n /cs /c '.escapeshellarg($mask).' >NUL',$return); if($return == 255 || $return < 1 || $return > strlen($mask)){ - throw new \RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); + throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); }else{ /** * Fetch the char from mask diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index d91eedf..771b512 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -4,6 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; +use Zend\Console\Exception\BadMethodCallException; use Zend\Console; /** @@ -180,7 +181,7 @@ public function readChar($mask = null){ if($useChoice){ system('choice /n /cs /c '.$mask,$return); if($return == 255 || $return < 1 || $return > strlen($mask)){ - throw new \RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); + throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); }else{ /** * Fetch the char from mask diff --git a/src/Console.php b/src/Console.php index f774c10..4f5b647 100644 --- a/src/Console.php +++ b/src/Console.php @@ -1,6 +1,8 @@ Date: Sun, 22 Jul 2012 14:20:14 +0200 Subject: [PATCH 76/98] Add BadMethodCallException & fix Exception imports --- src/Adapter/Windows.php | 2 +- src/Adapter/WindowsAnsicon.php | 2 +- src/Exception/BadMethodCallException.php | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/Exception/BadMethodCallException.php diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 38371d3..c74ece2 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -4,7 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; -use Zend\Console\Exception\BadMethodCallException; +use Zend\Console\Exception\RuntimeException; use Zend\Console; class Windows extends Virtual implements AdapterInterface diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 771b512..e2b1a81 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -4,7 +4,7 @@ use Zend\Console\AdapterInterface; use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; -use Zend\Console\Exception\BadMethodCallException; +use Zend\Console\Exception\RuntimeException; use Zend\Console; /** diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php new file mode 100644 index 0000000..b8184ee --- /dev/null +++ b/src/Exception/BadMethodCallException.php @@ -0,0 +1,18 @@ + Date: Sun, 22 Jul 2012 20:49:16 +0200 Subject: [PATCH 77/98] Fix AdapterInterface to latest interface name changes --- src/AdapterInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AdapterInterface.php b/src/AdapterInterface.php index 29fd627..a75917f 100644 --- a/src/AdapterInterface.php +++ b/src/AdapterInterface.php @@ -214,9 +214,9 @@ public function resetColor(); /** * Set Console charset to use. * - * @param \Zend\Console\Charset $charset + * @param \Zend\Console\CharsetInterface $charset */ - public function setCharset(Charset $charset); + public function setCharset(CharsetInterface $charset); /** * Get charset currently in use by this adapter. From 1bdbf92d1daa6bbf675ed71f6980ab85ca00b7f4 Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Sun, 22 Jul 2012 21:44:23 +0200 Subject: [PATCH 78/98] Fix missed interface renaming imports or type hints --- src/Adapter/Posix.php | 10 +++++----- src/AdapterInterface.php | 4 ++-- src/PromptInterface.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 6d1cc35..79ffc85 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -38,7 +38,7 @@ class Posix extends AbstractAdapter implements AdapterInterface Color::MAGENTA => '0;35', Color::CYAN => '0;36', Color::WHITE => '0;37', - + Color::GRAY => '1;30', Color::LIGHT_RED => '1;31', Color::LIGHT_GREEN => '1;32', @@ -202,7 +202,7 @@ public function colorize($string, $color = null, $bgColor = null) if($color !== null){ if(!isset(static::$ansiColorMap['fg'][$color])){ throw new BadMethodCallException( - 'Unknown color "'.$color.'". Please use one of Zend\Console\Color constants.' + 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' ); }else{ $color = static::$ansiColorMap['fg'][$color]; @@ -211,7 +211,7 @@ public function colorize($string, $color = null, $bgColor = null) if($bgColor !== null){ if(!isset(static::$ansiColorMap['bg'][$bgColor])){ throw new BadMethodCallException( - 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\Color constants.' + 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' ); }else{ $bgColor = static::$ansiColorMap['bg'][$bgColor]; @@ -239,7 +239,7 @@ public function setColor($color) if($color !== null){ if(!isset(static::$ansiColorMap['fg'][$color])){ throw new BadMethodCallException( - 'Unknown color "'.$color.'". Please use one of Zend\Console\Color constants.' + 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' ); }else{ $color = static::$ansiColorMap['fg'][$color]; @@ -262,7 +262,7 @@ public function setBgColor($bgColor) if($bgColor !== null){ if(!isset(static::$ansiColorMap['bg'][$bgColor])){ throw new BadMethodCallException( - 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\Color constants.' + 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' ); }else{ $bgColor = static::$ansiColorMap['bg'][$bgColor]; diff --git a/src/AdapterInterface.php b/src/AdapterInterface.php index a75917f..03acc9c 100644 --- a/src/AdapterInterface.php +++ b/src/AdapterInterface.php @@ -221,12 +221,12 @@ public function setCharset(CharsetInterface $charset); /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\Charset $charset + * @return \Zend\Console\CharsetInterface $charset */ public function getCharset(); /** - * @return \Zend\Console\Charset + * @return \Zend\Console\CharsetInterface */ public function getDefaultCharset(); diff --git a/src/PromptInterface.php b/src/PromptInterface.php index f817928..b400a83 100644 --- a/src/PromptInterface.php +++ b/src/PromptInterface.php @@ -1,7 +1,7 @@ Date: Tue, 24 Jul 2012 10:31:10 +0200 Subject: [PATCH 79/98] CS Fixes for Zend\Console\Adapter\AbstractAdapter --- src/Adapter/AbstractAdapter.php | 104 ++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index ba38302..88d283f 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -150,24 +150,22 @@ public function writeBox( /** * Validate coordinates */ - if ( - $x1 < 0 || - $y1 < 0 || - $x2 < $x1 || - $y2 < $y1 - ) { + if ($x1 < 0 + || $y1 < 0 + || $x2 < $x1 + || $y2 < $y1) { + throw new BadMethodCallException('Supplied X,Y coordinates are invalid.'); } /** * Determine charset and dimensions */ - /** @var $charset \Zend\Console\Charset\Ascii */ - $charset = $this->getCharset(); - $width = $x2 - $x1 + 1; - $height = $y2 - $y1 + 1; + $charset = $this->getCharset(); + $width = $x2 - $x1 + 1; + $height = $y2 - $y1 + 1; - if($width <= 2){ + if($width <= 2) { $lineStyle = static::LINE_NONE; } @@ -182,16 +180,16 @@ public function writeBox( */ if($lineStyle !== static::LINE_NONE) { switch ($lineStyle) { - case static::LINE_SINGLE; + case static::LINE_SINGLE: $lineChar = $charset::LINE_SINGLE_EW; break; - case static::LINE_DOUBLE; + case static::LINE_DOUBLE: $lineChar = $charset::LINE_DOUBLE_EW; break; + case static::LINE_BLOCK: default: - case static::LINE_BLOCK; $lineChar = $charset::LINE_BLOCK_EW; break; } @@ -205,28 +203,28 @@ public function writeBox( /** * Draw vertical lines and fill */ - if ( - is_numeric( $fillStyle ) && - $fillStyle !== static::FILL_NONE - ) { + if (is_numeric( $fillStyle ) + && $fillStyle !== static::FILL_NONE) { + switch ($fillStyle) { - case static::FILL_SHADE_LIGHT; + case static::FILL_SHADE_LIGHT: $fillChar = $charset::SHADE_LIGHT; break; - case static::FILL_SHADE_MEDIUM; + case static::FILL_SHADE_MEDIUM: $fillChar = $charset::SHADE_MEDIUM; break; - case static::FILL_SHADE_DARK; + case static::FILL_SHADE_DARK: $fillChar = $charset::SHADE_DARK; break; - case static::FILL_SHADE_LIGHT; + case static::FILL_SHADE_LIGHT: $fillChar = $charset::SHADE_LIGHT; break; - case static::FILL_BLOCK; + case static::FILL_BLOCK: default: $fillChar = $charset::BLOCK; break; } + } elseif ($fillStyle) { $fillChar = $this->stringTrim( $fillStyle, 1 ); } else { @@ -246,8 +244,8 @@ public function writeBox( case static::LINE_BLOCK: $lineChar = $charset::LINE_BLOCK_NS; break; - default: case static::LINE_SINGLE: + default: $lineChar = $charset::LINE_SINGLE_NS; break; } @@ -264,9 +262,13 @@ public function writeBox( /** * Draw corners */ - if($lineStyle !== static::LINE_NONE){ - if($color !== null) $this->setColor($color); - if($bgColor !== null) $this->setBgColor($bgColor); + if($lineStyle !== static::LINE_NONE) { + if($color !== null) { + $this->setColor($color); + } + if($bgColor !== null) { + $this->setBgColor($bgColor); + } if ($lineStyle === static::LINE_SINGLE) { $this->writeAt( $charset::LINE_SINGLE_NW, $x1, $y1 ); $this->writeAt( $charset::LINE_SINGLE_NE, $x2, $y1 ); @@ -309,9 +311,12 @@ public function writeBox( */ public function writeTextBlock( $text, - $width, $height = null, $x = 0, $y = 0, - $color = null, $bgColor = null - ) + $width, + $height = null, + $x = 0, + $y = 0, + $color = null, + $bgColor = null) { } @@ -392,17 +397,26 @@ public function getPos() * @param int $x * @param int $y */ - public function setPos($x, $y){} + public function setPos($x, $y) + { + + } /** * Show console cursor */ - public function showCursor(){} + public function showCursor() + { + + } /** * Hide console cursor */ - public function hideCursor(){} + public function hideCursor() + { + + } /** * Return current console window title. @@ -534,19 +548,19 @@ public function clearScreen() */ protected function getStringWidth($string) { + $width = strlen($string); + if ($this->isUtf8()) { if (static::$hasMBString === null) { static::$hasMBString = extension_loaded( 'mbstring' ); } - if (static::$hasMBString) { - return mb_strlen( $string, 'UTF-8' ); - } else { - return strlen( utf8_decode( $string ) ); - } - } else { - return strlen( $string ); + $width = (static::$hasMBString) + ? mb_strlen($string, 'UTF-8' ) + : strlen(utf8_decode($string)); } + + return $width; } protected function stringTrim($string, $length) @@ -572,7 +586,8 @@ protected function stringTrim($string, $length) * @param int $maxLength Maximum response length * @return string */ - public function readLine($maxLength = 2048){ + public function readLine($maxLength = 2048) + { $f = fopen('php://stdin','r'); $line = stream_get_line($f,2048,"\n"); fclose($f); @@ -585,11 +600,12 @@ public function readLine($maxLength = 2048){ * @param string|null $mask A list of allowed chars * @return string */ - public function readChar($mask = null){ + public function readChar($mask = null) + { $f = fopen('php://stdin','r'); - do{ + do { $char = fread($f,1); - }while($mask === null || stristr($mask,$char)); + } while($mask === null || stristr($mask,$char)); fclose($f); return $char; } From 9df5260b53e6da86719e2c50377fc2baf75ee0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michae=CC=88l=20Schwartz?= Date: Tue, 24 Jul 2012 20:46:53 +0200 Subject: [PATCH 80/98] More CS Fixes for Zend\Console --- src/Adapter/AbstractAdapter.php | 10 +-- src/Adapter/Posix.php | 110 ++++++++++++++++++-------------- src/Adapter/Virtual.php | 66 +++++++++++-------- src/Adapter/Windows.php | 90 +++++++++++++++----------- src/Adapter/WindowsAnsicon.php | 77 ++++++++++++---------- src/Console.php | 50 ++++++++------- src/Prompt/AbstractPrompt.php | 16 +++-- src/Prompt/Char.php | 36 ++++++----- src/Prompt/Confirm.php | 12 ++-- src/Prompt/Line.php | 10 +-- src/Prompt/Number.php | 32 ++++++---- src/Prompt/Select.php | 23 ++++--- src/Request.php | 6 +- src/Response.php | 6 +- 14 files changed, 306 insertions(+), 238 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 88d283f..b069147 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -165,7 +165,7 @@ public function writeBox( $width = $x2 - $x1 + 1; $height = $y2 - $y1 + 1; - if($width <= 2) { + if ($width <= 2) { $lineStyle = static::LINE_NONE; } @@ -178,7 +178,7 @@ public function writeBox( /** * Draw horizontal lines */ - if($lineStyle !== static::LINE_NONE) { + if ($lineStyle !== static::LINE_NONE) { switch ($lineStyle) { case static::LINE_SINGLE: $lineChar = $charset::LINE_SINGLE_EW; @@ -262,11 +262,11 @@ public function writeBox( /** * Draw corners */ - if($lineStyle !== static::LINE_NONE) { - if($color !== null) { + if ($lineStyle !== static::LINE_NONE) { + if ($color !== null) { $this->setColor($color); } - if($bgColor !== null) { + if ($bgColor !== null) { $this->setBgColor($bgColor); } if ($lineStyle === static::LINE_SINGLE) { diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 79ffc85..d025462 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -84,16 +84,17 @@ class Posix extends AbstractAdapter implements AdapterInterface * * @return int */ - public function getWidth(){ + public function getWidth() + { static $width; - if($width > 0){ + if ($width > 0){ return $width; } /** * Try to read env variable */ - if(($result = getenv('COLUMNS')) !== false){ + if (($result = getenv('COLUMNS')) !== false) { return $width = (int)$result; } @@ -101,12 +102,11 @@ public function getWidth(){ * Try to read console size from "tput" command */ $result = exec('tput cols',$output, $return); - if(!$return && is_numeric($result)){ + if (!$return && is_numeric($result)) { return $width = (int)$result; - }else{ - return $width = parent::getWidth(); } + return $width = parent::getWidth(); } /** @@ -114,35 +114,38 @@ public function getWidth(){ * * @return false|int */ - public function getHeight(){ + public function getHeight() + { static $height; - if($height > 0){ + if ($height > 0) { return $height; } /** * Try to read env variable */ - if(($result = getenv('LINES')) !== false){ + if (($result = getenv('LINES')) !== false) { return $height = (int)$result; } /** - * Try to read console size from "tput" command - */ + * Try to read console size from "tput" command + */ $result = exec('tput lines',$output, $return); - if(!$return && is_numeric($result)){ + if (!$return && is_numeric($result)) { return $height = (int)$result; - }else{ - return $height = parent::getHeight(); } + + return $height = parent::getHeight(); + } - protected function runModeCommand(){ + protected function runModeCommand() + { exec('mode',$output,$return); - if($return || !count($output)){ + if ($return || !count($output)) { $this->modeResult = ''; - }else{ + } else { $this->modeResult = trim(implode('',$output)); } } @@ -152,11 +155,12 @@ protected function runModeCommand(){ * * @return bool */ - public function isUtf8(){ + public function isUtf8() + { /** * Try to retrieve it from LANG env variable */ - if(($lang = getenv('LANG')) !== false){ + if (($lang = getenv('LANG')) !== false) { return stristr($lang,'utf-8') || stristr($lang,'utf8'); } @@ -166,14 +170,16 @@ public function isUtf8(){ /** * Show console cursor */ - public function showCursor(){ + public function showCursor() + { echo "\x1b[?25h"; } /** * Hide console cursor */ - public function hideCursor(){ + public function hideCursor() + { echo "\x1b[?25l"; } @@ -182,7 +188,8 @@ public function hideCursor(){ * @param int $x * @param int $y */ - public function setPos($x, $y){ + public function setPos($x, $y) + { echo "\x1b[".$y.';'.$x.'f'; } @@ -199,21 +206,21 @@ public function colorize($string, $color = null, $bgColor = null) /** * Retrieve ansi color codes */ - if($color !== null){ - if(!isset(static::$ansiColorMap['fg'][$color])){ + if ($color !== null) { + if (!isset(static::$ansiColorMap['fg'][$color])) { throw new BadMethodCallException( 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' ); - }else{ + } else { $color = static::$ansiColorMap['fg'][$color]; } } - if($bgColor !== null){ - if(!isset(static::$ansiColorMap['bg'][$bgColor])){ + if ($bgColor !== null){ + if (!isset(static::$ansiColorMap['bg'][$bgColor])) { throw new BadMethodCallException( 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' ); - }else{ + } else { $bgColor = static::$ansiColorMap['bg'][$bgColor]; } } @@ -236,12 +243,12 @@ public function setColor($color) /** * Retrieve ansi color code */ - if($color !== null){ - if(!isset(static::$ansiColorMap['fg'][$color])){ + if ($color !== null) { + if (!isset(static::$ansiColorMap['fg'][$color])) { throw new BadMethodCallException( 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' ); - }else{ + } else { $color = static::$ansiColorMap['fg'][$color]; } } @@ -259,12 +266,12 @@ public function setBgColor($bgColor) /** * Retrieve ansi color code */ - if($bgColor !== null){ - if(!isset(static::$ansiColorMap['bg'][$bgColor])){ + if ($bgColor !== null) { + if (!isset(static::$ansiColorMap['bg'][$bgColor])) { throw new BadMethodCallException( 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' ); - }else{ + } else { $bgColor = static::$ansiColorMap['bg'][$bgColor]; } } @@ -287,7 +294,8 @@ public function resetColor() * * @return string */ - public function getTitle(){ + public function getTitle() + { } @@ -297,7 +305,8 @@ public function getTitle(){ * @param \Zend\Console\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset){ + public function setCharset(CharsetInterface $charset) + { $this->charset = $charset; } @@ -306,8 +315,9 @@ public function setCharset(CharsetInterface $charset){ * * @return \Zend\Console\CharsetInterface $charset */ - public function getCharset(){ - if($this->charset === null){ + public function getCharset() + { + if ($this->charset === null) { $this->charset = $this->getDefaultCharset(); } @@ -317,10 +327,11 @@ public function getCharset(){ /** * @return \Zend\Console\Charset */ - public function getDefaultCharset(){ - if($this->isUtf8()){ + public function getDefaultCharset() + { + if ($this->isUtf8()) { return new Charset\Utf8; - }else{ + } else { return new Charset\DECSG(); } } @@ -336,12 +347,10 @@ public function readChar($mask = null) $this->setTTYMode('-icanon -echo'); $stream = fopen('php://stdin','rb'); - do{ + do { $char = fgetc($stream); - }while( - !$char || - ($mask !== null && !stristr($mask,$char)) - ); + } while(!$char || ($mask !== null && !stristr($mask,$char))); + fclose($stream); $this->restoreTTYMode(); @@ -351,7 +360,8 @@ public function readChar($mask = null) /** * Reset color to console default. */ - public function clear(){ + public function clear() + { echo "\x1b[2J"; // reset bg color $this->setPos(1,1); // reset cursor position } @@ -361,9 +371,11 @@ public function clear(){ * * @return mixed */ - protected function restoreTTYMode(){ - if($this->lastTTYMode === null) + protected function restoreTTYMode() + { + if ($this->lastTTYMode === null) { return; + } shell_exec('stty '.escapeshellarg($this->lastTTYMode)); diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index f2d1e7e..1993e10 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -20,22 +20,23 @@ class Virtual extends AbstractAdapter implements AdapterInterface * * @return int */ - public function getWidth(){ + public function getWidth() + { static $width; - if($width > 0){ + if ($width > 0) { return $width; } /** * Try to read console size from "mode" command */ - if($this->modeResult === null){ + if ($this->modeResult === null) { $this->runProbeCommand(); } - if(preg_match('/Columns\:\s+(\d+)/',$this->modeResult,$matches)){ + if (preg_match('/Columns\:\s+(\d+)/',$this->modeResult,$matches)) { $width = $matches[1]; - }else{ + } else { $width = parent::getWidth(); } @@ -47,33 +48,35 @@ public function getWidth(){ * * @return false|int */ - public function getHeight(){ + public function getHeight() + { static $height; - if($height > 0){ + if ($height > 0) { return $height; } /** * Try to read console size from "mode" command */ - if($this->modeResult === null){ + if ($this->modeResult === null){ $this->runProbeCommand(); } - if(preg_match('/Rows\:\s+(\d+)/',$this->modeResult,$matches)){ + if (preg_match('/Rows\:\s+(\d+)/',$this->modeResult,$matches)) { $height = $matches[1]; - }else{ + } else { $height = parent::getHeight(); } return $height; } - protected function runProbeCommand(){ + protected function runProbeCommand() + { exec('mode',$output,$return); - if($return || !count($output)){ + if ($return || !count($output)) { $this->modeResult = ''; - }else{ + } else { $this->modeResult = trim(implode('',$output)); } } @@ -83,19 +86,20 @@ protected function runProbeCommand(){ * * @return bool */ - public function isUtf8(){ + public function isUtf8() + { /** * Try to read code page info from "mode" command */ - if($this->modeResult === null){ + if ($this->modeResult === null) { $this->runProbeCommand(); } - if(preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)){ + if (preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)) { return (int)$matches[1] == 65001; - }else{ - return false; } + + return false; } /** @@ -103,7 +107,8 @@ public function isUtf8(){ * @param int $x * @param int $y */ - public function setPos($x, $y){ + public function setPos($x, $y) + { } @@ -112,16 +117,17 @@ public function setPos($x, $y){ * * @return string */ - public function getTitle(){ + public function getTitle() + { /** * Try to use powershell to retrieve console window title */ exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); - if($result || !$output){ + if ($result || !$output) { return ''; - }else{ - return trim($output,"\r\n"); } + + return trim($output,"\r\n"); } /** @@ -129,7 +135,8 @@ public function getTitle(){ * * @param \Zend\Console\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset){ + public function setCharset(CharsetInterface $charset) + { $this->charset = $charset; } @@ -138,8 +145,9 @@ public function setCharset(CharsetInterface $charset){ * * @return \Zend\Console\CharsetInterface $charset */ - public function getCharset(){ - if($this->charset === null){ + public function getCharset() + { + if ($this->charset === null) { $this->charset = $this->getDefaultCharset(); } @@ -149,11 +157,13 @@ public function getCharset(){ /** * @return \Zend\Console\Charset\AsciiExtended */ - public function getDefaultCharset(){ + public function getDefaultCharset() + { return new Charset\AsciiExtended; } - protected function switchToUtf8(){ + protected function switchToUtf8() + { `mode con cp select=65001`; } } diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index c74ece2..8da14da 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -18,22 +18,23 @@ class Windows extends Virtual implements AdapterInterface * * @return int */ - public function getWidth(){ + public function getWidth() + { static $width; - if($width > 0){ + if ($width > 0) { return $width; } /** * Try to read console size from "mode" command */ - if($this->probeResult === null){ + if ($this->probeResult === null) { $this->runProbeCommand(); } - if(count($this->probeResult) && (int)$this->probeResult[0]){ + if (count($this->probeResult) && (int)$this->probeResult[0]) { $width = (int)$this->probeResult[0]; - }else{ + } else { $width = parent::getWidth(); } @@ -45,29 +46,31 @@ public function getWidth(){ * * @return false|int */ - public function getHeight(){ + public function getHeight() + { static $height; - if($height > 0){ + if ($height > 0) { return $height; } /** * Try to read console size from "mode" command */ - if($this->probeResult === null){ + if ($this->probeResult === null) { $this->runProbeCommand(); } - if(count($this->probeResult) && (int)$this->probeResult[1]){ + if (count($this->probeResult) && (int)$this->probeResult[1]) { $height = (int)$this->probeResult[1]; - }else{ + } else { $height = parent::getheight(); } return $height; } - protected function runProbeCommand(){ + protected function runProbeCommand() + { /** * Run a Windows Powershell command that determines parameters of console window. The command is fed through * standard input (with echo) to prevent Powershell from creating a sub-thread and hanging PHP when run through @@ -78,9 +81,9 @@ protected function runProbeCommand(){ $output, $return ); - if($return || empty($output)){ + if ($return || empty($output)) { $this->probeResult = ''; - }else{ + } else { $this->probeResult = $output; } } @@ -90,19 +93,20 @@ protected function runProbeCommand(){ * * @return bool */ - public function isUtf8(){ + public function isUtf8() + { /** * Try to read code page info from "mode" command */ - if($this->probeResult === null){ + if ($this->probeResult === null) { $this->runProbeCommand(); } - if(preg_match('/Code page\:\s+(\d+)/',$this->probeResult,$matches)){ + if (preg_match('/Code page\:\s+(\d+)/',$this->probeResult,$matches)) { return (int)$matches[1] == 65001; - }else{ - return false; } + + return false; } /** @@ -110,7 +114,8 @@ public function isUtf8(){ * @param int $x * @param int $y */ - public function setPos($x, $y){ + public function setPos($x, $y) + { } @@ -119,16 +124,17 @@ public function setPos($x, $y){ * * @return string */ - public function getTitle(){ + public function getTitle() + { /** * Try to use powershell to retrieve console window title */ exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); - if($result || !$output){ + if ($result || !$output) { return ''; - }else{ - return trim($output,"\r\n"); } + + return trim($output,"\r\n"); } /** @@ -136,7 +142,8 @@ public function getTitle(){ * * @param \Zend\Console\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset){ + public function setCharset(CharsetInterface $charset) + { $this->charset = $charset; } @@ -145,8 +152,9 @@ public function setCharset(CharsetInterface $charset){ * * @return \Zend\Console\CharsetInterface $charset */ - public function getCharset(){ - if($this->charset === null){ + public function getCharset() + { + if ($this->charset === null) { $this->charset = $this->getDefaultCharset(); } @@ -156,11 +164,13 @@ public function getCharset(){ /** * @return \Zend\Console\Charset\AsciiExtended */ - public function getDefaultCharset(){ + public function getDefaultCharset() + { return new Charset\AsciiExtended; } - protected function switchToUtf8(){ + protected function switchToUtf8() + { `mode con cp select=65001`; } @@ -187,38 +197,38 @@ public function clearLine() * @param string|null $mask A list of allowed chars * @return string */ - public function readChar($mask = null){ + public function readChar($mask = null) + { /** * Decide if we can use `choice` tool */ $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]*$/',$mask); - do{ - if($useChoice){ + do { + if ($useChoice) { /** * Use the `choice` tool available since windows 2000 */ system('choice /n /cs /c '.escapeshellarg($mask).' >NUL',$return); - if($return == 255 || $return < 1 || $return > strlen($mask)){ + if ($return == 255 || $return < 1 || $return > strlen($mask)) { throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); - }else{ + } else { /** * Fetch the char from mask */ $char = substr($mask,$return-1,1); } - }else{ + } else { /** * Use a fallback method */ $char = $this->readLine(1); - if(!$char){ + if (!$char) { $char = "\n"; // user pressed [enter] } } - }while( - ($mask !== null && !stristr($mask,$char)) - ); + } while (($mask !== null && !stristr($mask,$char))); + return $char; } @@ -228,10 +238,12 @@ public function readChar($mask = null){ * @param int $maxLength Maximum response length * @return string */ - public function readLine($maxLength = 2048){ + public function readLine($maxLength = 2048) + { $f = fopen('php://stdin','r'); $line = trim(fread($f,$maxLength)); fclose($f); + return $line; } diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index e2b1a81..e786413 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -32,18 +32,19 @@ class WindowsAnsicon extends Posix implements AdapterInterface * * @return int */ - public function getWidth(){ + public function getWidth() + { static $width; - if($width > 0){ + if ($width > 0) { return $width; } /** * Try to read console size from ANSICON env var */ - if(preg_match('/\((\d+)x/',getenv('ANSICON'),$matches)){ + if (preg_match('/\((\d+)x/',getenv('ANSICON'),$matches)) { $width = $matches[1]; - }else{ + } else { $width = AbstractAdapter::getWidth(); } @@ -55,28 +56,30 @@ public function getWidth(){ * * @return false|int */ - public function getHeight(){ + public function getHeight() + { static $height; - if($height > 0){ + if ($height > 0) { return $height; } /** * Try to read console size from ANSICON env var */ - if(preg_match('/\(\d+x(\d+)/',getenv('ANSICON'),$matches)){ + if (preg_match('/\(\d+x(\d+)/',getenv('ANSICON'),$matches)) { $height = $matches[1]; - }else{ + } else { $height = AbstractAdapter::getHeight(); } return $height; } - protected function runModeCommand(){ + protected function runModeCommand() + { exec('mode',$output,$return); - if($return || !count($output)){ + if ($return || !count($output)) { $this->modeResult = ''; - }else{ + } else { $this->modeResult = trim(implode('',$output)); } } @@ -86,19 +89,20 @@ protected function runModeCommand(){ * * @return bool */ - public function isUtf8(){ + public function isUtf8() + { /** * Try to read code page info from "mode" command */ - if($this->modeResult === null){ + if ($this->modeResult === null) { $this->runModeCommand(); } - if(preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)){ + if (preg_match('/Code page\:\s+(\d+)/', $this->modeResult,$matches)) { return (int)$matches[1] == 65001; - }else{ - return false; } + + return false; } /** @@ -106,16 +110,17 @@ public function isUtf8(){ * * @return string */ - public function getTitle(){ + public function getTitle() + { /** * Try to use powershell to retrieve console window title */ exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); - if($result || !$output){ + if ($result || !$output){ return ''; - }else{ - return trim($output,"\r\n"); } + + return trim($output,"\r\n"); } /** @@ -140,7 +145,8 @@ public function clearLine() * * @param \Zend\Console\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset){ + public function setCharset(CharsetInterface $charset) + { $this->charset = $charset; } @@ -150,8 +156,9 @@ public function setCharset(CharsetInterface $charset){ * @return \Zend\Console\CharsetInterface $charset */ - public function getCharset(){ - if($this->charset === null){ + public function getCharset() + { + if ($this->charset === null) { $this->charset = $this->getDefaultCharset(); } @@ -161,7 +168,8 @@ public function getCharset(){ /** * @return \Zend\Console\Charset\AsciiExtended */ - public function getDefaultCharset(){ + public function getDefaultCharset() + { return new Charset\AsciiExtended(); } @@ -171,30 +179,29 @@ public function getDefaultCharset(){ * @param string|null $mask A list of allowed chars * @return string */ - public function readChar($mask = null){ + public function readChar($mask = null) + { /** * Decide if we can use `choice` tool */ - $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]$',$mask); + $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]$', $mask); - do{ - if($useChoice){ + do { + if ($useChoice) { system('choice /n /cs /c '.$mask,$return); - if($return == 255 || $return < 1 || $return > strlen($mask)){ + if ($return == 255 || $return < 1 || $return > strlen($mask)) { throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); - }else{ + } else { /** * Fetch the char from mask */ $char = substr($mask,$return-1,1); } - }else{ + } else { $char = parent::readChar($mask); } - }while( - !$char || - ($mask !== null && !stristr($mask,$char)) - ); + } while(!$char || ($mask !== null && !stristr($mask, $char))); + return $char; } diff --git a/src/Console.php b/src/Console.php index 4f5b647..cd024f2 100644 --- a/src/Console.php +++ b/src/Console.php @@ -23,27 +23,28 @@ abstract class Console * @param null $forceAdapter Console\Adapter class name (can be absolute namespace or relative to Adapter\) * @return \Zend\Console\Adapter */ - static public function getInstance($forceAdapter = null, $forceCharset = null){ + static public function getInstance($forceAdapter = null, $forceCharset = null) + { /** * Create instance */ - if(static::$instance === null){ - if($forceAdapter !== null){ + if (static::$instance === null) { + if ($forceAdapter !== null) { /** * Use the supplied adapter class */ - if(substr($forceAdapter,0,1) == '\\'){ + if (substr($forceAdapter,0,1) == '\\') { $className = $forceAdapter; - }elseif(stristr($forceAdapter,'\\')){ + } elseif (stristr($forceAdapter,'\\')) { $className = __NAMESPACE__.'\\'.ltrim($forceAdapter,'\\'); - }else{ + } else { $className = __NAMESPACE__.'\\Adapter\\'.$forceAdapter; } - if(!class_exists($className)){ + if (!class_exists($className)) { throw new InvalidArgumentException('Cannot find Console adapter class '.$className); } - }else{ + } else { /** * Try to detect best instance for console */ @@ -58,16 +59,16 @@ static public function getInstance($forceAdapter = null, $forceCharset = null){ /** * Try to use the supplied charset class */ - if($forceCharset !== null){ - if(substr($forceCharset,0,1) == '\\'){ + if ($forceCharset !== null){ + if (substr($forceCharset,0,1) == '\\') { $className = $forceCharset; - }elseif(stristr($forceAdapter,'\\')){ + } elseif (stristr($forceAdapter,'\\')) { $className = __NAMESPACE__.'\\'.ltrim($forceCharset,'\\'); - }else{ + } else { $className = __NAMESPACE__.'\\Charset\\'.$forceCharset; } - if(!class_exists($className)){ + if (!class_exists($className)) { throw new InvalidArgumentException('Cannot find Charset class '.$className); } @@ -87,7 +88,8 @@ static public function getInstance($forceAdapter = null, $forceCharset = null){ * @static * @return bool */ - static public function isWindows(){ + static public function isWindows() + { return class_exists('COM',false); } @@ -97,7 +99,8 @@ static public function isWindows(){ * @static * @return bool */ - static public function isAnsicon(){ + static public function isAnsicon() + { return getenv('ANSICON') !== false; } @@ -107,7 +110,8 @@ static public function isAnsicon(){ * @static * @return bool */ - static public function isConsole(){ + static public function isConsole() + { return PHP_SAPI == 'cli'; } @@ -115,17 +119,18 @@ static public function isConsole(){ * @static * @return \Zend\Console\Adapter|null */ - static public function detectBestAdapter(){ + static public function detectBestAdapter() + { // Check if we are in a console environment - if(!static::isConsole()){ + if (!static::isConsole()) { return null; } // Check if we're on windows - if(static::isWindows()){ - if(static::isAnsicon()){ + if (static::isWindows()) { + if (static::isAnsicon()) { $className = __NAMESPACE__.'\Adapter\WindowsAnsicon'; - }else{ + } else { $className = __NAMESPACE__.'\Adapter\Windows'; } @@ -145,7 +150,8 @@ static public function detectBestAdapter(){ * @param $arguments * @return mixed */ - public static function __callStatic($funcName, $arguments){ + public static function __callStatic($funcName, $arguments) + { $instance = static::getInstance(); return call_user_func_array(array($instance,$funcName),$arguments); } diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index fecbb9e..f718ed1 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -17,14 +17,18 @@ abstract class AbstractPrompt implements PromptInterface */ protected $lastResponse; - public function show(){} + public function show() + { + + } /** * Return last answer to this prompt. * * @return mixed */ - public function getLastResponse(){ + public function getLastResponse() + { return $this->lastResponse; } @@ -33,8 +37,9 @@ public function getLastResponse(){ * * @return \Zend\Console\AdapterInterface */ - public function getConsole(){ - if(!$this->console){ + public function getConsole() + { + if (!$this->console) { $this->console = Console::getInstance(); } @@ -46,7 +51,8 @@ public function getConsole(){ * * @param \Zend\Console\AdapterInterface $adapter */ - public function setConsole(ConsoleAdapter $adapter){ + public function setConsole(ConsoleAdapter $adapter) + { $this->console = $adapter; } diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index faa8366..af4cbfe 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -40,29 +40,33 @@ class Char extends AbstractPrompt implements PromptInterface * @param bool $echo Display the selection after user presses key */ public function __construct( - $promptText = 'Please hit a key', $allowedChars = 'abc', $ignoreCase = true, $allowEmpty = false, $echo = true - ){ - if($promptText !== null){ + $promptText = 'Please hit a key', + $allowedChars = 'abc', + $ignoreCase = true, + $allowEmpty = false, + $echo = true) + { + if ($promptText !== null) { $this->setPromptText($promptText); } - if($allowEmpty !== null){ + if ($allowEmpty !== null) { $this->setAllowEmpty($allowEmpty); } - if($ignoreCase !== null){ + if ($ignoreCase !== null) { $this->setIgnoreCase($ignoreCase); } - if($allowedChars !== null){ - if($this->ignoreCase){ + if ($allowedChars !== null) { + if ($this->ignoreCase) { $this->setAllowedChars(strtolower($allowedChars)); - }else{ + } else { $this->setAllowedChars($allowedChars); } } - if($echo !== null){ + if ($echo !== null) { $this->setEcho($echo); } } @@ -80,7 +84,7 @@ public function show() /** * Normalize the mask if case is irrelevant */ - if($this->ignoreCase){ + if ($this->ignoreCase) { $mask = strtolower($mask); // lowercase all $mask .= strtoupper($mask); // uppercase and append $mask = str_split($mask); // convert to array @@ -88,7 +92,7 @@ public function show() $mask = implode("",$mask); // convert back to string } - do{ + do { /** * Read char from console */ @@ -97,22 +101,22 @@ public function show() /** * Lowercase the response if case is irrelevant */ - if($this->ignoreCase){ + if ($this->ignoreCase) { $char = strtolower($char); } /** * Check if it is an allowed char */ - if(stristr($this->allowedChars,$char)){ - if($this->echo){ + if (stristr($this->allowedChars,$char)) { + if ($this->echo) { echo trim($char)."\n"; - }else{ + } else { echo "\n"; } break; } - }while(true); + } while(true); return $this->lastResponse = $char; } diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index d41f354..df0061e 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -38,17 +38,19 @@ class Confirm extends Char implements PromptInterface * @param string $noChar The "no" key (defaults to N) */ public function __construct( - $promptText = 'Are you sure?', $yesChar = 'y', $noChar = 'n' - ){ - if($promptText !== null){ + $promptText = 'Are you sure?', + $yesChar = 'y', + $noChar = 'n') + { + if ($promptText !== null) { $this->setPromptText($promptText); } - if($yesChar !== null){ + if ($yesChar !== null) { $this->setYesChar($yesChar); } - if($noChar !== null){ + if ($noChar !== null) { $this->setNoChar($noChar); } } diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 60896f0..4f8e249 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -29,15 +29,15 @@ class Line extends AbstractPrompt implements PromptInterface */ public function __construct($promptText = 'Please enter value: ', $allowEmpty = false, $maxLength = 2048) { - if($promptText !== null){ + if ($promptText !== null) { $this->setPromptText($promptText); } - if($allowEmpty !== null){ + if ($allowEmpty !== null) { $this->setAllowEmpty($allowEmpty); } - if($maxLength !== null){ + if ($maxLength !== null) { $this->setMaxLength($maxLength); } } @@ -49,10 +49,10 @@ public function __construct($promptText = 'Please enter value: ', $allowEmpty = */ public function show() { - do{ + do { $this->getConsole()->write($this->promptText); $line = $this->getConsole()->readLine($this->maxLength); - }while(!$this->allowEmpty && !$line); + } while(!$this->allowEmpty && !$line); return $this->lastResponse = $line; } diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index da505b5..cdcc530 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -35,25 +35,29 @@ class Number extends Line implements PromptInterface * @param integer $max Maximum value (inclusive) */ public function __construct( - $promptText = 'Please enter a number: ', $allowEmpty = false, $allowFloat = false, $min = null, $max = null - ){ - if($promptText !== null){ + $promptText = 'Please enter a number: ', + $allowEmpty = false, + $allowFloat = false, + $min = null, + $max = null) + { + if ($promptText !== null){ $this->setPromptText($promptText); } - if($allowEmpty !== null){ + if ($allowEmpty !== null){ $this->setAllowEmpty($allowEmpty); } - if($min !== null){ + if ($min !== null){ $this->setMin($min); } - if($max !== null){ + if ($max !== null){ $this->setMax($max); } - if($allowFloat !== null){ + if ($allowFloat !== null){ $this->setAllowFloat($allowFloat); } } @@ -71,20 +75,20 @@ public function show() do{ $valid = true; $number = parent::show(); - if($number === "" && !$this->allowEmpty){ + if ($number === "" && !$this->allowEmpty){ $valid = false; - }elseif($number === ""){ + }elseif ($number === ""){ $number = null; - }elseif(!is_numeric($number)){ + }elseif (!is_numeric($number)){ $this->getConsole()->writeLine("$number is not a number\n"); $valid = false; - }elseif(!$this->allowFloat && (round($number) != $number) ){ + }elseif (!$this->allowFloat && (round($number) != $number) ){ $this->getConsole()->writeLine("Please enter a non-floating number, i.e. ".round($number)."\n"); $valid = false; - }elseif($this->max !== null && $number > $this->max){ + }elseif ($this->max !== null && $number > $this->max){ $this->getConsole()->writeLine("Please enter a number not greater than ".$this->max."\n"); $valid = false; - }elseif($this->min !== null && $number < $this->min){ + }elseif ($this->min !== null && $number < $this->min){ $this->getConsole()->writeLine("Please enter a number not smaller than ".$this->min."\n"); $valid = false; } @@ -93,7 +97,7 @@ public function show() /** * Cast proper type */ - if($number !== null){ + if ($number !== null){ $number = $this->allowFloat ? (double)$number : (int)$number; } diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 29e51e2..d0edfb8 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -30,13 +30,16 @@ class Select extends Char implements PromptInterface * @param bool $echo True to display selected option? */ public function __construct( - $promptText = 'Please select one option', $options = array(), $allowEmpty = false, $echo = false - ){ - if($promptText !== null){ + $promptText = 'Please select one option', + $options = array(), + $allowEmpty = false, + $echo = false) + { + if ($promptText !== null) { $this->setPromptText($promptText); } - if(!count($options)){ + if (!count($options)) { throw new BadMethodCallException( 'Cannot construct a "select" prompt without any options' ); @@ -44,11 +47,11 @@ public function __construct( $this->setOptions($options); - if($allowEmpty !== null){ + if ($allowEmpty !== null) { $this->setAllowEmpty($allowEmpty); } - if($echo !== null){ + if ($echo !== null) { $this->setEcho($echo); } @@ -74,7 +77,7 @@ public function show() * Ask for selection */ $mask = implode("",array_keys($this->options)); - if($this->allowEmpty){ + if ($this->allowEmpty){ $mask .= "\r\n"; } $this->setAllowedChars($mask); @@ -93,18 +96,18 @@ public function show() */ public function setOptions($options) { - if(!is_array($options) && !$options instanceof \Traversable){ + if (!is_array($options) && !$options instanceof \Traversable) { throw new BadMethodCallException( 'Please specify an array or Traversable object as options' ); } - if(!is_array($options)){ + if (!is_array($options)) { $this->options = array(); foreach($options as $k => $v){ $this->options[$k] = $v; } - }else{ + } else { $this->options = $options; } } diff --git a/src/Request.php b/src/Request.php index 4ed3fc8..4f64ce9 100644 --- a/src/Request.php +++ b/src/Request.php @@ -31,7 +31,7 @@ class Request extends Message implements RequestInterface */ public function __construct(array $args = null, array $env = null) { - if($args === null){ + if ($args === null){ if (!isset($_SERVER['argv'])) { $errorDescription = (ini_get('register_argc_argv') == false) ? "Cannot create Console\\Request because PHP ini option 'register_argc_argv' is set Off" @@ -41,14 +41,14 @@ public function __construct(array $args = null, array $env = null) $args = $_SERVER['argv']; } - if($env === null){ + if ($env === null) { $env = $_ENV; } /** * Extract first param assuming it is the script name */ - if(count($args) > 0){ + if (count($args) > 0) { $this->setScriptName(array_shift($args)); } diff --git a/src/Response.php b/src/Response.php index 0c8ff6d..a927300 100644 --- a/src/Response.php +++ b/src/Response.php @@ -20,7 +20,8 @@ public function contentSent() * @param integer $errorLevel * @return Response */ - public function setErrorLevel($errorLevel){ + public function setErrorLevel($errorLevel) + { $this->setMetadata('errorLevel', $errorLevel); return $this; } @@ -30,7 +31,8 @@ public function setErrorLevel($errorLevel){ * * @return integer|0 */ - public function getErrorLevel(){ + public function getErrorLevel() + { return $this->getMetadata('errorLevel', 0); } From 50a946f818154dce1dcb990709542e7cb8bf0eb2 Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Tue, 24 Jul 2012 21:16:57 +0200 Subject: [PATCH 81/98] Add missing file level docblocks --- src/Adapter/AbstractAdapter.php | 19 ++++++++++++++----- src/Adapter/Posix.php | 9 +++++++++ src/Adapter/Virtual.php | 9 +++++++++ src/Adapter/Windows.php | 9 +++++++++ src/Adapter/WindowsAnsicon.php | 9 +++++++++ src/AdapterInterface.php | 9 +++++++++ src/Charset/Ascii.php | 11 ++++++++++- src/Charset/AsciiExtended.php | 11 ++++++++++- src/Charset/DECSG.php | 15 ++++++++++++--- src/Charset/Utf8.php | 13 +++++++++++-- src/Charset/Utf8Heavy.php | 9 +++++++++ src/CharsetInterface.php | 9 +++++++++ src/ColorInterface.php | 8 ++++++++ src/Console.php | 9 +++++++++ src/Prompt/AbstractPrompt.php | 9 +++++++++ src/Prompt/Char.php | 9 +++++++++ src/Prompt/Confirm.php | 9 +++++++++ src/Prompt/Line.php | 9 +++++++++ src/Prompt/Number.php | 9 +++++++++ src/Prompt/Select.php | 9 +++++++++ src/PromptInterface.php | 9 +++++++++ src/Request.php | 8 ++++++++ src/Response.php | 8 ++++++++ 23 files changed, 216 insertions(+), 12 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 88d283f..262be85 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -1,4 +1,13 @@ Date: Tue, 24 Jul 2012 21:27:28 +0200 Subject: [PATCH 82/98] Add class level docblocks to all files --- src/Adapter/AbstractAdapter.php | 5 +++++ src/Adapter/Posix.php | 3 +++ src/Adapter/Virtual.php | 4 ++++ src/Adapter/Windows.php | 5 +++++ src/Adapter/WindowsAnsicon.php | 4 ++++ src/AdapterInterface.php | 4 ++++ src/Charset/Ascii.php | 4 ++++ src/Charset/AsciiExtended.php | 3 +++ src/Charset/DECSG.php | 3 +++ src/Charset/Utf8.php | 3 +++ src/Charset/Utf8Heavy.php | 3 +++ src/CharsetInterface.php | 5 ++++- src/ColorInterface.php | 5 ++++- src/Console.php | 2 ++ src/Exception/BadMethodCallException.php | 5 +++++ src/Exception/ExceptionInterface.php | 1 + src/Exception/InvalidArgumentException.php | 5 +++++ src/Exception/RuntimeException.php | 3 ++- src/Prompt/AbstractPrompt.php | 5 +++++ src/Prompt/Char.php | 5 +++++ src/Prompt/Confirm.php | 5 +++++ src/Prompt/Line.php | 5 +++++ src/Prompt/Number.php | 5 +++++ src/Prompt/Select.php | 5 +++++ src/PromptInterface.php | 4 ++++ src/Request.php | 4 ++++ src/Response.php | 4 ++++ 27 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 262be85..b85abe0 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -16,6 +16,11 @@ use Zend\Console\Exception\BadMethodCallException; use Zend\Console; +/** + * @category Zend + * @package Zend_Console + * @subpackage Adapter + */ abstract class AbstractAdapter implements AdapterInterface { protected static $hasMBString; diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 18399cc..9cd28f8 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -18,6 +18,9 @@ /** * @link http://en.wikipedia.org/wiki/ANSI_escape_code + * @category Zend + * @package Zend_Console + * @subpackage Adapter */ class Posix extends AbstractAdapter implements AdapterInterface { diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index 6209db9..0746f9f 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -17,6 +17,10 @@ /** * Virtual buffer adapter + * + * @category Zend + * @package Zend_Console + * @subpackage Adapter */ class Virtual extends AbstractAdapter implements AdapterInterface { diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index bc45016..2d8176a 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -16,6 +16,11 @@ use Zend\Console\Exception\RuntimeException; use Zend\Console; +/** + * @category Zend + * @package Zend_Console + * @subpackage Adapter + */ class Windows extends Virtual implements AdapterInterface { protected static $hasMBString; diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index c79fbc3..a9f1dd4 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -29,6 +29,10 @@ * Console should not run in UTF8 code page (65001), because ANSICON does not behave well with it. * It's best to use non-unicode code page 437, 850, 851, 852 or similar. Run "help mode" for more * information on how to change Windows console code page. + * + * @category Zend + * @package Zend_Console + * @subpackage Adapter */ class WindowsAnsicon extends Posix implements AdapterInterface { diff --git a/src/AdapterInterface.php b/src/AdapterInterface.php index cd26ca3..d29dd98 100644 --- a/src/AdapterInterface.php +++ b/src/AdapterInterface.php @@ -10,6 +10,10 @@ namespace Zend\Console; +/** + * @category Zend + * @package Zend_Console + */ interface AdapterInterface { const LINE_NONE = 1; diff --git a/src/Charset/Ascii.php b/src/Charset/Ascii.php index 0de5a75..20fa766 100644 --- a/src/Charset/Ascii.php +++ b/src/Charset/Ascii.php @@ -14,6 +14,10 @@ /** * Basic (low) ASCII line drawing characters. + * + * @category Zend + * @package Zend_Console + * @subpackage Charset */ class Ascii implements CharsetInterface{ diff --git a/src/Charset/AsciiExtended.php b/src/Charset/AsciiExtended.php index 3cf1f7f..81c62ff 100644 --- a/src/Charset/AsciiExtended.php +++ b/src/Charset/AsciiExtended.php @@ -16,6 +16,9 @@ * Extended ASCII character set (positions 127+, MS DOS & Windows compatible) * * @link http://en.wikipedia.org/wiki/Box-drawing_characters + * @category Zend + * @package Zend_Console + * @subpackage Charset */ class AsciiExtended implements CharsetInterface{ diff --git a/src/Charset/DECSG.php b/src/Charset/DECSG.php index 0c4c1cd..f6e58f2 100644 --- a/src/Charset/DECSG.php +++ b/src/Charset/DECSG.php @@ -16,6 +16,9 @@ * DEC Special Graphics (VT100 line drawing) character set * * @link http://vt100.net/docs/vt220-rm/table2-4.html + * @category Zend + * @package Zend_Console + * @subpackage Charset */ class DECSG implements CharsetInterface{ diff --git a/src/Charset/Utf8.php b/src/Charset/Utf8.php index aee2da1..5be6c7c 100644 --- a/src/Charset/Utf8.php +++ b/src/Charset/Utf8.php @@ -16,6 +16,9 @@ * UTF-8 box drawing * * @link http://en.wikipedia.org/wiki/Box-drawing_characters + * @category Zend + * @package Zend_Console + * @subpackage Charset */ class Utf8 implements CharsetInterface{ const ACTIVATE = ""; diff --git a/src/Charset/Utf8Heavy.php b/src/Charset/Utf8Heavy.php index ced9d14..c0da61f 100644 --- a/src/Charset/Utf8Heavy.php +++ b/src/Charset/Utf8Heavy.php @@ -14,6 +14,9 @@ * UTF-8 box drawing (modified to use heavy single lines) * * @link http://en.wikipedia.org/wiki/Box-drawing_characters + * @category Zend + * @package Zend_Console + * @subpackage Charset */ class Utf8Heavy extends Utf8 { diff --git a/src/CharsetInterface.php b/src/CharsetInterface.php index 9efa1d7..52b4a96 100644 --- a/src/CharsetInterface.php +++ b/src/CharsetInterface.php @@ -10,6 +10,9 @@ namespace Zend\Console; - +/** + * @category Zend + * @package Zend_Console + */ interface CharsetInterface { } diff --git a/src/ColorInterface.php b/src/ColorInterface.php index 6da25db..3677763 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -10,7 +10,10 @@ namespace Zend\Console; - +/** + * @category Zend + * @package Zend_Console + */ interface ColorInterface { const NORMAL = 0; const RESET = 0; diff --git a/src/Console.php b/src/Console.php index baafe43..1af2da2 100644 --- a/src/Console.php +++ b/src/Console.php @@ -16,6 +16,8 @@ * An static, utility class for interacting with Console enviromen. * Declared abstract to prevent from instantiating. * + * @category Zend + * @package Zend_Console */ abstract class Console { diff --git a/src/Exception/BadMethodCallException.php b/src/Exception/BadMethodCallException.php index 3265553..223b812 100644 --- a/src/Exception/BadMethodCallException.php +++ b/src/Exception/BadMethodCallException.php @@ -10,6 +10,11 @@ namespace Zend\Console\Exception; +/** + * @category Zend + * @package Zend_Console + * @subpackage Exception + */ class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface { diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index e67f691..1412b51 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -13,6 +13,7 @@ /** * @category Zend * @package Zend_Console + * @subpackage Exception */ interface ExceptionInterface { diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 60395fb..64fba73 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -10,6 +10,11 @@ namespace Zend\Console\Exception; +/** + * @category Zend + * @package Zend_Console + * @subpackage Exception + */ class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface { } diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 4e07703..d956932 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -12,7 +12,8 @@ /** * @category Zend - * @package Zend_Console_Getopt + * @package Zend_Console + * @subpackage Exception */ class RuntimeException extends \RuntimeException implements ExceptionInterface { diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index 9eceb57..b08479c 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -14,6 +14,11 @@ use Zend\Console\Console; use Zend\Console\AdapterInterface as ConsoleAdapter; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ abstract class AbstractPrompt implements PromptInterface { /** diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 5ae8d38..fbdb185 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -12,6 +12,11 @@ use Zend\Console\PromptInterface; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ class Char extends AbstractPrompt implements PromptInterface { /** diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index cc023d6..478a5c3 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -12,6 +12,11 @@ use Zend\Console\PromptInterface; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ class Confirm extends Char implements PromptInterface { /** diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 38c04fe..5007285 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -12,6 +12,11 @@ use Zend\Console\PromptInterface; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ class Line extends AbstractPrompt implements PromptInterface { /** diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index df5ae27..21a0bde 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -12,6 +12,11 @@ use Zend\Console\PromptInterface; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ class Number extends Line implements PromptInterface { /** diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 4097ce2..1ec4187 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -13,6 +13,11 @@ use Zend\Console\PromptInterface; use Zend\Console\Exception\BadMethodCallException; +/** + * @category Zend + * @package Zend_Console + * @subpackage Prompt + */ class Select extends Char implements PromptInterface { /** diff --git a/src/PromptInterface.php b/src/PromptInterface.php index 0248f26..a117d01 100644 --- a/src/PromptInterface.php +++ b/src/PromptInterface.php @@ -12,6 +12,10 @@ use Zend\Console\AdapterInterface as ConsoleAdapter; +/** + * @category Zend + * @package Zend_Console + */ interface PromptInterface { /** diff --git a/src/Request.php b/src/Request.php index 42123cf..757eafd 100644 --- a/src/Request.php +++ b/src/Request.php @@ -15,6 +15,10 @@ use Zend\Stdlib\ParametersInterface; use Zend\Stdlib\RequestInterface; +/** + * @category Zend + * @package Zend_Console + */ class Request extends Message implements RequestInterface { /** diff --git a/src/Response.php b/src/Response.php index 03a7526..95bb6e2 100644 --- a/src/Response.php +++ b/src/Response.php @@ -13,6 +13,10 @@ use Zend\Stdlib\Message; use Zend\Stdlib\ResponseInterface; +/** + * @category Zend + * @package Zend_Console + */ class Response extends Message implements ResponseInterface { protected $contentSent = false; From 7679e3584e8b92a2142e63164f61fcbf851e6171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michae=CC=88l=20Schwartz?= Date: Wed, 25 Jul 2012 13:41:48 +0200 Subject: [PATCH 83/98] Last pass of CS Fixes on Zend\Console --- src/Adapter/AbstractAdapter.php | 27 +++++++++++++--------- src/Adapter/Posix.php | 12 +++++----- src/Adapter/Virtual.php | 5 +++-- src/Adapter/Windows.php | 3 +-- src/Adapter/WindowsAnsicon.php | 4 ++-- src/AdapterInterface.php | 21 ++++++++++++----- src/Charset/Ascii.php | 4 +++- src/Charset/AsciiExtended.php | 3 ++- src/Charset/DECSG.php | 3 ++- src/Charset/Utf8.php | 4 +++- src/Charset/Utf8Heavy.php | 3 ++- src/CharsetInterface.php | 3 ++- src/ColorInterface.php | 3 ++- src/Console.php | 2 +- src/Getopt.php | 13 ++++++----- src/Prompt/Char.php | 15 +++++++------ src/Prompt/Confirm.php | 8 +++---- src/Prompt/Line.php | 2 +- src/Prompt/Number.php | 40 ++++++++++++++++----------------- src/Prompt/Select.php | 16 ++++++------- src/PromptInterface.php | 3 ++- src/Request.php | 2 +- 22 files changed, 113 insertions(+), 83 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 33335d5..ade581a 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -98,7 +98,7 @@ public function writeLine($text = "", $color = null, $bgColor = null) } elseif ($width == $consoleWidth) { $this->write($text, $color, $bgColor); } else { - $this->write($text. "\n", $color, $bgColor);; + $this->write($text. "\n", $color, $bgColor); } } @@ -136,11 +136,17 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null) * @param null|int $fillBgColor (optional) Background color of box fill */ public function writeBox( - $x1, $y1, $x2, $y2, - $lineStyle = self::LINE_SINGLE, $fillStyle = self::FILL_NONE, - $color = null, $bgColor = null, $fillColor = null, $fillBgColor = null - ) - { + $x1, + $y1, + $x2, + $y2, + $lineStyle = self::LINE_SINGLE, + $fillStyle = self::FILL_NONE, + $color = null, + $bgColor = null, + $fillColor = null, + $fillBgColor = null + ) { /** * Sanitize coordinates */ @@ -330,8 +336,8 @@ public function writeTextBlock( $x = 0, $y = 0, $color = null, - $bgColor = null) - { + $bgColor = null + ) { } @@ -468,7 +474,7 @@ public function resetTitle() */ public function colorize($string, $color = null, $bgColor = null) { - return $string; + return $string; } /** @@ -619,8 +625,9 @@ public function readChar($mask = null) $f = fopen('php://stdin','r'); do { $char = fread($f,1); - } while($mask === null || stristr($mask,$char)); + } while ($mask === null || stristr($mask,$char)); fclose($f); return $char; } } + diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 444cdad..3a87e94 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -99,7 +99,7 @@ class Posix extends AbstractAdapter implements AdapterInterface public function getWidth() { static $width; - if ($width > 0){ + if ($width > 0) { return $width; } @@ -147,9 +147,9 @@ public function getHeight() if (!$return && is_numeric($result)) { return $height = (int)$result; } - + return $height = parent::getHeight(); - + } protected function runModeCommand() @@ -227,7 +227,7 @@ public function colorize($string, $color = null, $bgColor = null) $color = static::$ansiColorMap['fg'][$color]; } } - if ($bgColor !== null){ + if ($bgColor !== null) { if (!isset(static::$ansiColorMap['bg'][$bgColor])) { throw new BadMethodCallException( 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' @@ -361,7 +361,7 @@ public function readChar($mask = null) $stream = fopen('php://stdin','rb'); do { $char = fgetc($stream); - } while(!$char || ($mask !== null && !stristr($mask,$char))); + } while (!$char || ($mask !== null && !stristr($mask,$char))); fclose($stream); @@ -415,5 +415,5 @@ protected function setTTYMode($mode) /** * @todo Add GNU readline support */ - } + diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index 700ef59..0b556d7 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -71,7 +71,7 @@ public function getHeight() /** * Try to read console size from "mode" command */ - if ($this->modeResult === null){ + if ($this->modeResult === null) { $this->runProbeCommand(); } @@ -111,7 +111,7 @@ public function isUtf8() if (preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)) { return (int)$matches[1] == 65001; } - + return false; } @@ -179,4 +179,5 @@ protected function switchToUtf8() { `mode con cp select=65001`; } + } diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index ba11470..c68a176 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -257,9 +257,8 @@ public function readLine($maxLength = 2048) $f = fopen('php://stdin','r'); $line = trim(fread($f,$maxLength)); fclose($f); - + return $line; } - } diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 6083b69..080852d 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -129,7 +129,7 @@ public function getTitle() * Try to use powershell to retrieve console window title */ exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); - if ($result || !$output){ + if ($result || !$output) { return ''; } @@ -213,7 +213,7 @@ public function readChar($mask = null) } else { $char = parent::readChar($mask); } - } while(!$char || ($mask !== null && !stristr($mask, $char))); + } while (!$char || ($mask !== null && !stristr($mask, $char))); return $char; } diff --git a/src/AdapterInterface.php b/src/AdapterInterface.php index d29dd98..245d427 100644 --- a/src/AdapterInterface.php +++ b/src/AdapterInterface.php @@ -82,9 +82,16 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null); * @param null|int $fillBgColor (optional) Background color of box fill */ public function writeBox( - $x1, $y1, $x2, $y2, - $lineStyle = self::LINE_SINGLE, $fillStyle = self::FILL_NONE, - $color = null, $bgColor = null, $fillColor = null, $fillBgColor = null + $x1, + $y1, + $x2, + $y2, + $lineStyle = self::LINE_SINGLE, + $fillStyle = self::FILL_NONE, + $color = null, + $bgColor = null, + $fillColor = null, + $fillBgColor = null ); /** @@ -102,8 +109,12 @@ public function writeBox( */ public function writeTextBlock( $text, - $width, $height = null, $x = 0, $y = 0, - $color = null, $bgColor = null + $width, + $height = null, + $x = 0, + $y = 0, + $color = null, + $bgColor = null ); diff --git a/src/Charset/Ascii.php b/src/Charset/Ascii.php index 20fa766..b1d193b 100644 --- a/src/Charset/Ascii.php +++ b/src/Charset/Ascii.php @@ -19,7 +19,8 @@ * @package Zend_Console * @subpackage Charset */ -class Ascii implements CharsetInterface{ +class Ascii implements CharsetInterface +{ const ACTIVATE = ""; const DEACTIVATE = ""; @@ -52,4 +53,5 @@ class Ascii implements CharsetInterface{ const LINE_BLOCK_SE = "+"; const LINE_BLOCK_SW = "+"; const LINE_BLOCK_CROSS = "+"; + } diff --git a/src/Charset/AsciiExtended.php b/src/Charset/AsciiExtended.php index 81c62ff..7357f1b 100644 --- a/src/Charset/AsciiExtended.php +++ b/src/Charset/AsciiExtended.php @@ -20,7 +20,8 @@ * @package Zend_Console * @subpackage Charset */ -class AsciiExtended implements CharsetInterface{ +class AsciiExtended implements CharsetInterface +{ const ACTIVATE = ""; const DEACTIVATE = ""; diff --git a/src/Charset/DECSG.php b/src/Charset/DECSG.php index f6e58f2..ec6b9ff 100644 --- a/src/Charset/DECSG.php +++ b/src/Charset/DECSG.php @@ -20,7 +20,8 @@ * @package Zend_Console * @subpackage Charset */ -class DECSG implements CharsetInterface{ +class DECSG implements CharsetInterface +{ const ACTIVATE = "\x1b(0"; const DEACTIVATE = "\x1b(B"; diff --git a/src/Charset/Utf8.php b/src/Charset/Utf8.php index 5be6c7c..17afa58 100644 --- a/src/Charset/Utf8.php +++ b/src/Charset/Utf8.php @@ -20,7 +20,9 @@ * @package Zend_Console * @subpackage Charset */ -class Utf8 implements CharsetInterface{ +class Utf8 implements CharsetInterface +{ + const ACTIVATE = ""; const DEACTIVATE = ""; diff --git a/src/Charset/Utf8Heavy.php b/src/Charset/Utf8Heavy.php index c0da61f..183d8dd 100644 --- a/src/Charset/Utf8Heavy.php +++ b/src/Charset/Utf8Heavy.php @@ -18,7 +18,8 @@ * @package Zend_Console * @subpackage Charset */ -class Utf8Heavy extends Utf8 { +class Utf8Heavy extends Utf8 +{ const LINE_SINGLE_EW = "━"; const LINE_SINGLE_NS = "┃"; diff --git a/src/CharsetInterface.php b/src/CharsetInterface.php index 52b4a96..b1cd2a6 100644 --- a/src/CharsetInterface.php +++ b/src/CharsetInterface.php @@ -14,5 +14,6 @@ * @category Zend * @package Zend_Console */ -interface CharsetInterface { +interface CharsetInterface +{ } diff --git a/src/ColorInterface.php b/src/ColorInterface.php index 3677763..7bcbb2e 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -14,7 +14,8 @@ * @category Zend * @package Zend_Console */ -interface ColorInterface { +interface ColorInterface +{ const NORMAL = 0; const RESET = 0; diff --git a/src/Console.php b/src/Console.php index e7fdb8b..2c71dcf 100644 --- a/src/Console.php +++ b/src/Console.php @@ -70,7 +70,7 @@ static public function getInstance($forceAdapter = null, $forceCharset = null) /** * Try to use the supplied charset class */ - if ($forceCharset !== null){ + if ($forceCharset !== null) { if (substr($forceCharset,0,1) == '\\') { $className = $forceCharset; } elseif (stristr($forceAdapter,'\\')) { diff --git a/src/Getopt.php b/src/Getopt.php index 7678fab..3387a3e 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -318,7 +318,7 @@ public function __unset($key) */ public function addArguments($argv) { - if(!is_array($argv)) { + if (!is_array($argv)) { throw new Exception\InvalidArgumentException("Parameter #1 to addArguments should be an array"); } $this->_argv = array_merge($this->_argv, $argv); @@ -336,7 +336,7 @@ public function addArguments($argv) */ public function setArguments($argv) { - if(!is_array($argv)) { + if (!is_array($argv)) { throw new Exception\InvalidArgumentException("Parameter #1 to setArguments should be an array"); } $this->_argv = $argv; @@ -541,9 +541,10 @@ public function getRemainingArgs() return $this->_remainingArgs; } - public function getArguments(){ + public function getArguments() + { $result = $this->getRemainingArgs(); - foreach($this->getOptions() as $option){ + foreach ($this->getOptions() as $option) { $result[$option] = $this->getOption($option); } return $result; @@ -680,7 +681,7 @@ public function parse() $this->_parseLongOption($argv); } elseif (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1)) { $this->_parseShortOptionCluster($argv); - } else if($this->_getoptConfig[self::CONFIG_PARSEALL]) { + } else if ($this->_getoptConfig[self::CONFIG_PARSEALL]) { $this->_remainingArgs[] = array_shift($argv); } else { /* @@ -844,7 +845,7 @@ protected function _setSingleOptionValue($flag, $value) if (!array_key_exists($flag, $this->_options)) { $this->_options[$flag] = $value; - } else if($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { + } else if ($this->_getoptConfig[self::CONFIG_CUMULATIVE_PARAMETERS]) { $this->_options[$flag] = (array) $this->_options[$flag]; array_push($this->_options[$flag], $value); } else { diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 70e691b..7985141 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -54,12 +54,13 @@ class Char extends AbstractPrompt implements PromptInterface * @param bool $echo Display the selection after user presses key */ public function __construct( - $promptText = 'Please hit a key', - $allowedChars = 'abc', - $ignoreCase = true, - $allowEmpty = false, - $echo = true) - { + $promptText = 'Please hit a key', + $allowedChars = 'abc', + $ignoreCase = true, + $allowEmpty = false, + $echo = true + ) { + if ($promptText !== null) { $this->setPromptText($promptText); } @@ -130,7 +131,7 @@ public function show() } break; } - } while(true); + } while (true); return $this->lastResponse = $char; } diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index 26ea11e..e8dcaf3 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -52,10 +52,10 @@ class Confirm extends Char implements PromptInterface * @param string $noChar The "no" key (defaults to N) */ public function __construct( - $promptText = 'Are you sure?', - $yesChar = 'y', - $noChar = 'n') - { + $promptText = 'Are you sure?', + $yesChar = 'y', + $noChar = 'n' + ) { if ($promptText !== null) { $this->setPromptText($promptText); } diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index fcfe5f7..66e46c8 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -66,7 +66,7 @@ public function show() do { $this->getConsole()->write($this->promptText); $line = $this->getConsole()->readLine($this->maxLength); - } while(!$this->allowEmpty && !$line); + } while (!$this->allowEmpty && !$line); return $this->lastResponse = $line; } diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index 4699636..ae82cd0 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -49,29 +49,29 @@ class Number extends Line implements PromptInterface * @param integer $max Maximum value (inclusive) */ public function __construct( - $promptText = 'Please enter a number: ', - $allowEmpty = false, - $allowFloat = false, - $min = null, - $max = null) - { - if ($promptText !== null){ + $promptText = 'Please enter a number: ', + $allowEmpty = false, + $allowFloat = false, + $min = null, + $max = null + ) { + if ($promptText !== null) { $this->setPromptText($promptText); } - if ($allowEmpty !== null){ + if ($allowEmpty !== null) { $this->setAllowEmpty($allowEmpty); } - if ($min !== null){ + if ($min !== null) { $this->setMin($min); } - if ($max !== null){ + if ($max !== null) { $this->setMax($max); } - if ($allowFloat !== null){ + if ($allowFloat !== null) { $this->setAllowFloat($allowFloat); } } @@ -86,32 +86,32 @@ public function show() /** * Ask for a number and validate it. */ - do{ + do { $valid = true; $number = parent::show(); - if ($number === "" && !$this->allowEmpty){ + if ($number === "" && !$this->allowEmpty) { $valid = false; - }elseif ($number === ""){ + } elseif ($number === ""){ $number = null; - }elseif (!is_numeric($number)){ + } elseif (!is_numeric($number)){ $this->getConsole()->writeLine("$number is not a number\n"); $valid = false; - }elseif (!$this->allowFloat && (round($number) != $number) ){ + } elseif (!$this->allowFloat && (round($number) != $number) ){ $this->getConsole()->writeLine("Please enter a non-floating number, i.e. ".round($number)."\n"); $valid = false; - }elseif ($this->max !== null && $number > $this->max){ + } elseif ($this->max !== null && $number > $this->max){ $this->getConsole()->writeLine("Please enter a number not greater than ".$this->max."\n"); $valid = false; - }elseif ($this->min !== null && $number < $this->min){ + } elseif ($this->min !== null && $number < $this->min){ $this->getConsole()->writeLine("Please enter a number not smaller than ".$this->min."\n"); $valid = false; } - }while(!$valid); + } while (!$valid); /** * Cast proper type */ - if ($number !== null){ + if ($number !== null) { $number = $this->allowFloat ? (double)$number : (int)$number; } diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index ab88a63..e2d8b77 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -44,11 +44,11 @@ class Select extends Char implements PromptInterface * @param bool $echo True to display selected option? */ public function __construct( - $promptText = 'Please select one option', - $options = array(), - $allowEmpty = false, - $echo = false) - { + $promptText = 'Please select one option', + $options = array(), + $allowEmpty = false, + $echo = false + ) { if ($promptText !== null) { $this->setPromptText($promptText); } @@ -83,7 +83,7 @@ public function show() */ $console = $this->getConsole(); $console->writeLine($this->promptText); - foreach($this->options as $k=>$v){ + foreach ($this->options as $k => $v) { $console->writeLine(' '.$k.') '.$v); } @@ -91,7 +91,7 @@ public function show() * Ask for selection */ $mask = implode("",array_keys($this->options)); - if ($this->allowEmpty){ + if ($this->allowEmpty) { $mask .= "\r\n"; } $this->setAllowedChars($mask); @@ -118,7 +118,7 @@ public function setOptions($options) if (!is_array($options)) { $this->options = array(); - foreach($options as $k => $v){ + foreach ($options as $k => $v) { $this->options[$k] = $v; } } else { diff --git a/src/PromptInterface.php b/src/PromptInterface.php index a117d01..ea13f14 100644 --- a/src/PromptInterface.php +++ b/src/PromptInterface.php @@ -16,7 +16,8 @@ * @category Zend * @package Zend_Console */ -interface PromptInterface { +interface PromptInterface +{ /** * Show the prompt to user and return the answer. diff --git a/src/Request.php b/src/Request.php index 69d9cc6..588cd9b 100644 --- a/src/Request.php +++ b/src/Request.php @@ -43,7 +43,7 @@ class Request extends Message implements RequestInterface */ public function __construct(array $args = null, array $env = null) { - if ($args === null){ + if ($args === null) { if (!isset($_SERVER['argv'])) { $errorDescription = (ini_get('register_argc_argv') == false) ? "Cannot create Console\\Request because PHP ini option 'register_argc_argv' is set Off" From 748c5a4bb6ca31cea0ffa887ce3cb955a6550a61 Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Thu, 26 Jul 2012 17:12:56 -0700 Subject: [PATCH 84/98] Globally fix visibility issues for PSR2 php-cs-fixer fix . --fixers=visibility --- src/Console.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Console.php b/src/Console.php index 2c71dcf..5ab40f3 100644 --- a/src/Console.php +++ b/src/Console.php @@ -34,7 +34,7 @@ abstract class Console * @param null $forceAdapter Console\Adapter class name (can be absolute namespace or relative to Adapter\) * @return \Zend\Console\Adapter */ - static public function getInstance($forceAdapter = null, $forceCharset = null) + public static function getInstance($forceAdapter = null, $forceCharset = null) { /** * Create instance @@ -99,7 +99,7 @@ static public function getInstance($forceAdapter = null, $forceCharset = null) * @static * @return bool */ - static public function isWindows() + public static function isWindows() { return class_exists('COM',false); } @@ -110,7 +110,7 @@ static public function isWindows() * @static * @return bool */ - static public function isAnsicon() + public static function isAnsicon() { return getenv('ANSICON') !== false; } @@ -121,7 +121,7 @@ static public function isAnsicon() * @static * @return bool */ - static public function isConsole() + public static function isConsole() { return PHP_SAPI == 'cli'; } @@ -130,7 +130,7 @@ static public function isConsole() * @static * @return \Zend\Console\Adapter|null */ - static public function detectBestAdapter() + public static function detectBestAdapter() { // Check if we are in a console environment if (!static::isConsole()) { From 99769526daaeae3ae5c04b4ec2738fcc390f3236 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Thu, 2 Aug 2012 17:21:08 +0200 Subject: [PATCH 85/98] Add a workaround for Windows adapter to read a single char. Reading a single char, validated against a char mask now works on Windows. The adapter will attempt to use either "choice" command (known since Windows 95) or Windows PowerShell, to obtain a single keystroke from user and validate it against a mask of allowed characters. This method works with both low and high ASCII chars, which enables capturing keys such as cursors, tab, escape, backspace and enter. --- src/Adapter/AbstractAdapter.php | 3 +- src/Adapter/Windows.php | 118 +++++++++++++++++++++++++++----- src/Adapter/WindowsAnsicon.php | 102 +++++++++++++++++++++++++-- 3 files changed, 198 insertions(+), 25 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index ade581a..22f3012 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -14,6 +14,7 @@ use Zend\Console\ColorInterface; use Zend\Console\CharsetInterface; use Zend\Console\Exception\BadMethodCallException; +use Zend\Console\Charset; use Zend\Console; /** @@ -611,7 +612,7 @@ public function readLine($maxLength = 2048) $f = fopen('php://stdin','r'); $line = stream_get_line($f,2048,"\n"); fclose($f); - return $line; + return rtrim($line,"\n\r"); } /** diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 11de4e5..4d984f1 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -205,11 +205,11 @@ public function clearLine() echo "\r".str_repeat(' ',$this->getWidth())."\r"; } - /** * Read a single character from the console input * * @param string|null $mask A list of allowed chars + * @throws \Zend\Console\Exception\RuntimeException * @return string */ public function readChar($mask = null) @@ -217,32 +217,114 @@ public function readChar($mask = null) /** * Decide if we can use `choice` tool */ - $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]*$/',$mask); - - do { - if ($useChoice) { - /** - * Use the `choice` tool available since windows 2000 - */ - system('choice /n /cs /c '.escapeshellarg($mask).' >NUL',$return); + $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]+$/D', $mask); + + if ($useChoice) { + /** + * Use Windows 95+ "choice" command, which allows for reading a single character matching a mask, + * but is limited to lower ASCII range. + */ + do { + system('choice /n /cs /c:' . $mask, $return); if ($return == 255 || $return < 1 || $return > strlen($mask)) { throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); } else { /** * Fetch the char from mask */ - $char = substr($mask,$return-1,1); + $char = substr($mask, $return - 1, 1); } - } else { - /** - * Use a fallback method - */ - $char = $this->readLine(1); - if (!$char) { - $char = "\n"; // user pressed [enter] + } while (!$char || ($mask !== null && !stristr($mask, $char))); + + return $char; + } + + /** + * Try to use PowerShell, giving it console access. Because PowersShell interpreter can take a short while to + * load, we are emptying the whole keyboard buffer and picking the last key that has been pressed before or + * after PowerShell command has started. The ASCII code for that key is then converted to a character. + */ + if ($mask === null) { + exec( + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' . + 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}' . + 'write $key.VirtualKeyCode;' . + '"', + $result, + $return + ); + + // Retrieve char from the result. + $char = !empty($result) ? implode('', $result) : null; + + if (!empty($char) && !$return) { + // We have obtained an ASCII code, convert back to a char ... + $char = chr($char); + + // ... and return it... + return $char; + } + } else { + /** + * Windows and DOS will return carriage-return char (ASCII 13) when the user presses [ENTER] key, + * but Console Adapter user might have provided a \n Newline (ASCII 10) in the mask, to allow [ENTER]. + * We are going to replace all CR with NL to conform. + */ + $mask = strtr($mask, "\n", "\r"); + + /** + * Prepare a list of ASCII codes from mask chars + */ + $asciiMask = array_map(function($char) + { + return ord($char); + }, str_split($mask)); + $asciiMask = array_unique($asciiMask); + + /** + * Char mask filtering is now handled by the PowerShell itself, because it's a much faster method than + * invoking PS interpreter after each mismatch. The command should return ASCII code of a matching key. + */ + $result = $return = null; + exec( + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' . + '[int[]] $mask = ' . join(',', $asciiMask) . ';' . + 'do {' . + '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;' . + '} while( !($mask -contains $key) );' . + 'write $key;' . + '"', + $result, + $return + ); + + $char = !empty($result) ? trim(implode('', $result)) : null; + + if (!$return && $char && ($mask === null || in_array($char, $asciiMask))) { + // Normalize CR to LF + if ($char == 13) { + $char = 10; } + + // Convert to a char + $char = chr($char); + + // ... and return it... + return $char; } - } while (($mask !== null && !stristr($mask,$char))); + } + + /** + * Fall back to standard input, which on Windows does not allow reading a single character. This is a + * limitation of Windows streams implementation (not PHP) and this behavior cannot be changed with a command + * like "stty", known to POSIX systems. + */ + $stream = fopen('php://stdin', 'rb'); + do { + $char = fgetc($stream); + $char = substr(trim($char), 0, 1); + } while (!$char || ($mask !== null && !stristr($mask, $char))); + fclose($stream); return $char; } diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 5bfac7a..45370b7 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -191,6 +191,7 @@ public function getDefaultCharset() * Read a single character from the console input * * @param string|null $mask A list of allowed chars + * @throws \Zend\Console\Exception\RuntimeException * @return string */ public function readChar($mask = null) @@ -198,11 +199,15 @@ public function readChar($mask = null) /** * Decide if we can use `choice` tool */ - $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]$', $mask); + $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]+$/D', $mask); - do { - if ($useChoice) { - system('choice /n /cs /c '.$mask,$return); + if ($useChoice) { + /** + * Use Windows 98+ "choice" command, which allows for reading a single character matching a mask, + * but is limited to lower ASCII range. + */ + do { + system('choice /n /cs /c:'.$mask,$return); if ($return == 255 || $return < 1 || $return > strlen($mask)) { throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); } else { @@ -211,10 +216,95 @@ public function readChar($mask = null) */ $char = substr($mask,$return-1,1); } - } else { - $char = parent::readChar($mask); + } while (!$char || ($mask !== null && !stristr($mask, $char))); + + return $char; + } + + /** + * Try to use PowerShell, giving it console access. Because PowersShell interpreter can take a short while to + * load, we are emptying the whole keyboard buffer and picking the last key that has been pressed before or + * after PowerShell command has started. The ASCII code for that key is then converted to a character. + */ + if ($mask === null) { + exec( + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "'. + 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}'. + 'write $key.VirtualKeyCode;'. + '"', + $result, + $return + ); + + // Retrieve char from the result. + $char = !empty($result) ? implode('', $result) : null; + + if(!empty($char) && !$return){ + // We have obtained an ASCII code, convert back to a char ... + $char = chr($char); + + // ... and return it... + return $char; + } + } else { + /** + * Windows and DOS will return carriage-return char (ASCII 13) when the user presses [ENTER] key, + * but Console Adapter user might have provided a \n Newline (ASCII 10) in the mask, to allow [ENTER]. + * We are going to replace all CR with NL to conform. + */ + $mask = strtr($mask,"\n","\r"); + + /** + * Prepare a list of ASCII codes from mask chars + */ + $asciiMask = array_map(function($char){ + return ord($char); + },str_split($mask)); + $asciiMask = array_unique($asciiMask); + + /** + * Char mask filtering is now handled by the PowerShell itself, because it's a much faster method than + * invoking PS interpreter after each mismatch. The command should return ASCII code of a matching key. + */ + $result = $return = null; + exec( + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "'. + '[int[]] $mask = '.join(',',$asciiMask).';'. + 'do {'. + '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;'. + '} while( !($mask -contains $key) );'. + 'write $key;'. + '"', + $result, + $return + ); + + $char = !empty($result) ? trim(implode('',$result)) : null; + + if(!$return && $char && ($mask === null || in_array($char,$asciiMask))){ + // We have obtained an ASCII code, check if it is a carriage return and normalize it as needed + if ($char == 13) { + $char = 10; + } + // Convert to a character + $char = chr($char); + + // ... and return it... + return $char; } + } + + /** + * Fall back to standard input, which on Windows does not allow reading a single character. This is a + * limitation of Windows streams implementation (not PHP) and this behavior cannot be changed with a command + * like "stty", known to POSIX systems. + */ + $stream = fopen('php://stdin','rb'); + do { + $char = fgetc($stream); + $char = substr(trim($char), 0, 1); } while (!$char || ($mask !== null && !stristr($mask, $char))); + fclose($stream); return $char; } From 4420401fd64f6d3cb69e482463772a630202f424 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Thu, 2 Aug 2012 17:26:38 +0200 Subject: [PATCH 86/98] Add convenience method to statically create prompts. It is now possible to create prompts by calling static prompt() method, i.e. `$key = Prompt\Char::prompt("Press any key")`. --- src/Prompt/AbstractPrompt.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index d410e97..2a7773b 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -13,6 +13,7 @@ use Zend\Console\PromptInterface; use Zend\Console\Console; use Zend\Console\AdapterInterface as ConsoleAdapter; +use Zend\Console\Exception\BadMethodCallException; /** * @category Zend @@ -31,10 +32,7 @@ abstract class AbstractPrompt implements PromptInterface */ protected $lastResponse; - public function show() - { - - } + abstract public function show(); /** * Return last answer to this prompt. @@ -70,4 +68,26 @@ public function setConsole(ConsoleAdapter $adapter) $this->console = $adapter; } + /** + * Create an instance of this prompt, show it and return response. + * + * This is a convenience method for creating statically creating prompts, i.e.: + * + * $name = Zend\Console\Prompt\Line::prompt("Enter your name: "); + * + * @throws \Zend\Console\Exception\BadMethodCallException + * @return mixed + */ + public static function prompt(){ + if (get_called_class() === __CLASS__) { + throw new BadMethodCallException( + 'Cannot call prompt() on AbstractPrompt class. Use one of Console\Prompt\ subclasses.' + ); + } + + $refl = new \ReflectionClass(get_called_class()); + $instance = $refl->newInstanceArgs(func_get_args()); + return $instance->show(); + } + } From 4ec12921ea82117f485ec220572f79ef088a3225 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 2 Aug 2012 13:11:48 -0500 Subject: [PATCH 87/98] [zendframework/zf2#2096] CS cleanup - Fixed whitespace issues - Moved interfaces into their subnamespaces - Do not use phpdoc-style docblocks as in-body comments --- src/Adapter/AbstractAdapter.php | 289 ++++++++++++------------- src/{ => Adapter}/AdapterInterface.php | 10 +- src/Adapter/Posix.php | 249 ++++++++++----------- src/Adapter/Virtual.php | 75 ++++--- src/Adapter/Windows.php | 179 ++++++++------- src/Adapter/WindowsAnsicon.php | 176 ++++++++------- src/Charset/Ascii.php | 2 - src/Charset/AsciiExtended.php | 2 - src/{ => Charset}/CharsetInterface.php | 2 +- src/Charset/DECSG.php | 2 - src/Charset/Utf8.php | 2 - src/Console.php | 128 +++++------ src/Prompt/AbstractPrompt.php | 32 +-- src/Prompt/Char.php | 4 +- src/Prompt/Confirm.php | 4 +- src/Prompt/Line.php | 4 +- src/Prompt/Number.php | 4 +- src/{ => Prompt}/PromptInterface.php | 10 +- src/Prompt/Select.php | 9 +- 19 files changed, 559 insertions(+), 624 deletions(-) rename src/{ => Adapter}/AdapterInterface.php (97%) rename src/{ => Charset}/CharsetInterface.php (92%) rename src/{ => Prompt}/PromptInterface.php (83%) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 22f3012..823c50a 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -10,12 +10,8 @@ namespace Zend\Console\Adapter; -use Zend\Console\AdapterInterface; -use Zend\Console\ColorInterface; -use Zend\Console\CharsetInterface; -use Zend\Console\Exception\BadMethodCallException; use Zend\Console\Charset; -use Zend\Console; +use Zend\Console\Exception; /** * @category Zend @@ -24,31 +20,43 @@ */ abstract class AbstractAdapter implements AdapterInterface { + /** + * Whether or not mbstring is enabled + * + * @var null|bool + */ protected static $hasMBString; /** - * @var \Zend\Console\CharsetInterface + * @var Charset\CharsetInterface */ protected $charset; /** - * Current cursor position + * Current cursor X position + * + * @var int + */ + protected $posX; + + /** + * Current cursor Y position * * @var int */ - protected $posX, $posY; + protected $posY; /** * Write a chunk of text to console. * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor */ public function write($text, $color = null, $bgColor = null) { if ($color !== null || $bgColor !== null) { - echo $this->colorize( $text, $color, $bgColor ); + echo $this->colorize($text, $color, $bgColor); } else { echo $text; } @@ -57,13 +65,13 @@ public function write($text, $color = null, $bgColor = null) /** * Alias for write() * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor */ public function writeText($text, $color = null, $bgColor = null) { - return $this->write( $text, $color, $bgColor ); + return $this->write($text, $color, $bgColor); } /** @@ -71,30 +79,24 @@ public function writeText($text, $color = null, $bgColor = null) * If the text is longer than console width it will be truncated. * * - * @param string $text - * @param null|int $color - * @param null|int $bgColor + * @param string $text + * @param null|int $color + * @param null|int $bgColor */ public function writeLine($text = "", $color = null, $bgColor = null) { - $width = $this->getStringWidth( $text ); + $width = $this->getStringWidth($text); - /** - * Remove newline characters from the end of string - */ - $text = trim( $text, "\r\n" ); + // Remove newline characters from the end of string + $text = trim($text, "\r\n"); - /** - * Replace newline characters with spaces - */ - $test = str_replace( "\n", " ", $text ); + // Replace newline characters with spaces + $test = str_replace("\n", " ", $text); - /** - * Trim the line if it's too long and output text - */ + // Trim the line if it's too long and output text $consoleWidth = $this->getWidth(); if ($width > $consoleWidth) { - $text = $this->stringTrim( $text, $consoleWidth ); + $text = $this->stringTrim($text, $consoleWidth); $this->write($text, $color, $bgColor); } elseif ($width == $consoleWidth) { $this->write($text, $color, $bgColor); @@ -107,11 +109,11 @@ public function writeLine($text = "", $color = null, $bgColor = null) * Write a piece of text at the coordinates of $x and $y * * - * @param string $text Text to write - * @param int $x Console X coordinate (column) - * @param int $y Console Y coordinate (row) - * @param null|int $color - * @param null|int $bgColor + * @param string $text Text to write + * @param int $x Console X coordinate (column) + * @param int $y Console Y coordinate (row) + * @param null|int $color + * @param null|int $bgColor */ public function writeAt($text, $x, $y, $color = null, $bgColor = null) { @@ -124,17 +126,16 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null) * If X or Y coordinate value is negative, it will be calculated as the distance from far right or bottom edge * of the console (respectively). * - * - * @param int $x1 Top-left corner X coordinate (column) - * @param int $y1 Top-left corner Y coordinate (row) - * @param int $x2 Bottom-right corner X coordinate (column) - * @param int $y2 Bottom-right corner Y coordinate (row) - * @param int $lineStyle (optional) Box border style. - * @param int $fillStyle (optional) Box fill style or a single character to fill it with. - * @param int $color (optional) Foreground color - * @param int $bgColor (optional) Background color - * @param null|int $fillColor (optional) Foreground color of box fill - * @param null|int $fillBgColor (optional) Background color of box fill + * @param int $x1 Top-left corner X coordinate (column) + * @param int $y1 Top-left corner Y coordinate (row) + * @param int $x2 Bottom-right corner X coordinate (column) + * @param int $y2 Bottom-right corner Y coordinate (row) + * @param int $lineStyle (optional) Box border style. + * @param int $fillStyle (optional) Box fill style or a single character to fill it with. + * @param int $color (optional) Foreground color + * @param int $bgColor (optional) Background color + * @param null|int $fillColor (optional) Foreground color of box fill + * @param null|int $fillBgColor (optional) Background color of box fill */ public function writeBox( $x1, @@ -148,17 +149,13 @@ public function writeBox( $fillColor = null, $fillBgColor = null ) { - /** - * Sanitize coordinates - */ - $x1 = (int)$x1; - $y1 = (int)$y1; - $x2 = (int)$x2; - $y2 = (int)$y2; - - /** - * Translate negative coordinates - */ + // Sanitize coordinates + $x1 = (int) $x1; + $y1 = (int) $y1; + $x2 = (int) $x2; + $y2 = (int) $y2; + + // Translate negative coordinates if ($x2 < 0) { $x2 = $this->getWidth() - $x2; } @@ -167,38 +164,28 @@ public function writeBox( $y2 = $this->getHeight() - $y2; } - - /** - * Validate coordinates - */ + // Validate coordinates if ($x1 < 0 || $y1 < 0 || $x2 < $x1 - || $y2 < $y1) { - - throw new BadMethodCallException('Supplied X,Y coordinates are invalid.'); + || $y2 < $y1 + ) { + throw new Exception\BadMethodCallException('Supplied X,Y coordinates are invalid.'); } - /** - * Determine charset and dimensions - */ - $charset = $this->getCharset(); - $width = $x2 - $x1 + 1; - $height = $y2 - $y1 + 1; + // Determine charset and dimensions + $charset = $this->getCharset(); + $width = $x2 - $x1 + 1; + $height = $y2 - $y1 + 1; if ($width <= 2) { $lineStyle = static::LINE_NONE; } - - /** - * Activate line drawing - */ + // Activate line drawing $this->write($charset::ACTIVATE); - /** - * Draw horizontal lines - */ + // Draw horizontal lines if ($lineStyle !== static::LINE_NONE) { switch ($lineStyle) { case static::LINE_SINGLE: @@ -215,16 +202,14 @@ public function writeBox( break; } - $this->setPos( $x1 + 1, $y1 ); - $this->write( str_repeat( $lineChar, $width - 2 ), $color, $bgColor ); - $this->setPos( $x1 + 1, $y2 ); - $this->write( str_repeat( $lineChar, $width - 2 ), $color, $bgColor ); + $this->setPos($x1 + 1, $y1); + $this->write(str_repeat($lineChar, $width - 2), $color, $bgColor); + $this->setPos($x1 + 1, $y2); + $this->write(str_repeat($lineChar, $width - 2), $color, $bgColor); } - /** - * Draw vertical lines and fill - */ - if (is_numeric( $fillStyle ) + // Draw vertical lines and fill + if (is_numeric($fillStyle) && $fillStyle !== static::FILL_NONE) { switch ($fillStyle) { @@ -247,15 +232,15 @@ public function writeBox( } } elseif ($fillStyle) { - $fillChar = $this->stringTrim( $fillStyle, 1 ); + $fillChar = $this->stringTrim($fillStyle, 1); } else { $fillChar = ' '; } if ($lineStyle === static::LINE_NONE) { for ($y = $y1; $y <= $y2; $y++) { - $this->setPos( $x1, $y ); - $this->write(str_repeat( $fillChar, $width), $fillColor, $fillBgColor); + $this->setPos($x1, $y); + $this->write(str_repeat($fillChar, $width), $fillColor, $fillBgColor); } } else { switch($lineStyle){ @@ -272,17 +257,15 @@ public function writeBox( } for ($y = $y1 + 1; $y < $y2; $y++) { - $this->setPos( $x1, $y ); + $this->setPos($x1, $y); $this->write($lineChar, $color, $bgColor); - $this->write(str_repeat( $fillChar, $width - 2 ), $fillColor, $fillBgColor); + $this->write(str_repeat($fillChar, $width - 2), $fillColor, $fillBgColor); $this->write($lineChar, $color, $bgColor); } } - /** - * Draw corners - */ + // Draw corners if ($lineStyle !== static::LINE_NONE) { if ($color !== null) { $this->setColor($color); @@ -291,29 +274,26 @@ public function writeBox( $this->setBgColor($bgColor); } if ($lineStyle === static::LINE_SINGLE) { - $this->writeAt( $charset::LINE_SINGLE_NW, $x1, $y1 ); - $this->writeAt( $charset::LINE_SINGLE_NE, $x2, $y1 ); - $this->writeAt( $charset::LINE_SINGLE_SE, $x2, $y2 ); - $this->writeAt( $charset::LINE_SINGLE_SW, $x1, $y2 ); + $this->writeAt($charset::LINE_SINGLE_NW, $x1, $y1); + $this->writeAt($charset::LINE_SINGLE_NE, $x2, $y1); + $this->writeAt($charset::LINE_SINGLE_SE, $x2, $y2); + $this->writeAt($charset::LINE_SINGLE_SW, $x1, $y2); } elseif ($lineStyle === static::LINE_DOUBLE) { - $this->writeAt( $charset::LINE_DOUBLE_NW, $x1, $y1 ); - $this->writeAt( $charset::LINE_DOUBLE_NE, $x2, $y1 ); - $this->writeAt( $charset::LINE_DOUBLE_SE, $x2, $y2 ); - $this->writeAt( $charset::LINE_DOUBLE_SW, $x1, $y2 ); + $this->writeAt($charset::LINE_DOUBLE_NW, $x1, $y1); + $this->writeAt($charset::LINE_DOUBLE_NE, $x2, $y1); + $this->writeAt($charset::LINE_DOUBLE_SE, $x2, $y2); + $this->writeAt($charset::LINE_DOUBLE_SW, $x1, $y2); } elseif ($lineStyle === static::LINE_BLOCK) { - $this->writeAt( $charset::LINE_BLOCK_NW, $x1, $y1 ); - $this->writeAt( $charset::LINE_BLOCK_NE, $x2, $y1 ); - $this->writeAt( $charset::LINE_BLOCK_SE, $x2, $y2 ); - $this->writeAt( $charset::LINE_BLOCK_SW, $x1, $y2 ); + $this->writeAt($charset::LINE_BLOCK_NW, $x1, $y1); + $this->writeAt($charset::LINE_BLOCK_NE, $x2, $y1); + $this->writeAt($charset::LINE_BLOCK_SE, $x2, $y2); + $this->writeAt($charset::LINE_BLOCK_SW, $x1, $y2); } } - /** - * Deactivate line drawing and reset colors - */ + // Deactivate line drawing and reset colors $this->write($charset::DEACTIVATE); $this->resetColor(); - } /** @@ -321,14 +301,13 @@ public function writeBox( * In case a line of text does not fit desired width, it will be wrapped to the next line. * In case the whole text does not fit in desired height, it will be truncated. * - * - * @param string $text Text to write - * @param int $width Maximum block width. Negative value means distance from right edge. - * @param int|null $height Maximum block height. Negative value means distance from bottom edge. - * @param int $x Block X coordinate (column) - * @param int $y Block Y coordinate (row) - * @param null|int $color (optional) Text color - * @param null|int $bgColor (optional) Text background color + * @param string $text Text to write + * @param int $width Maximum block width. Negative value means distance from right edge. + * @param int|null $height Maximum block height. Negative value means distance from bottom edge. + * @param int $x Block X coordinate (column) + * @param int $y Block Y coordinate (row) + * @param null|int $color (optional) Text color + * @param null|int $bgColor (optional) Text background color */ public function writeTextBlock( $text, @@ -339,7 +318,6 @@ public function writeTextBlock( $color = null, $bgColor = null ) { - } /** @@ -365,13 +343,13 @@ public function getHeight() /** * Determine and return current console width and height. * - * @return array array($width, $height) + * @return array array($width, $height) */ public function getSize() { return array( $this->getWidth(), - $this->getHeight() + $this->getHeight(), ); } @@ -389,11 +367,10 @@ public function isUtf8() * Return current cursor position - array($x, $y) * * - * @return array array($x, $y); + * @return array array($x, $y); */ public function getPos() { - } // /** @@ -411,16 +388,15 @@ public function getPos() // * @return false|int Integer or false if failed to determine. // */ // public function getY(); -// + /** * Set cursor position * - * @param int $x - * @param int $y + * @param int $x + * @param int $y */ public function setPos($x, $y) { - } /** @@ -428,7 +404,6 @@ public function setPos($x, $y) */ public function showCursor() { - } /** @@ -436,7 +411,6 @@ public function showCursor() */ public function hideCursor() { - } /** @@ -468,9 +442,9 @@ public function resetTitle() /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param int $color - * @param null|int $bgColor + * @param string $string + * @param int $color + * @param null|int $bgColor * @return string */ public function colorize($string, $color = null, $bgColor = null) @@ -503,13 +477,12 @@ public function resetColor() { } - /** * Set Console charset to use. * - * @param \Zend\Console\CharsetInterface $charset + * @param Charset\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset) + public function setCharset(Charset\CharsetInterface $charset) { $this->charset = $charset; } @@ -517,7 +490,7 @@ public function setCharset(CharsetInterface $charset) /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return Charset\CharsetInterface $charset */ public function getCharset() { @@ -529,7 +502,7 @@ public function getCharset() } /** - * @return \Zend\Console\Charset\Utf8 + * @return Charset\Utf8 */ public function getDefaultCharset() { @@ -571,34 +544,43 @@ protected function getStringWidth($string) { $width = strlen($string); - if ($this->isUtf8()) { - if (static::$hasMBString === null) { - static::$hasMBString = extension_loaded( 'mbstring' ); - } + if (!$this->isUtf8()) { + return $width; + } - $width = (static::$hasMBString) - ? mb_strlen($string, 'UTF-8' ) - : strlen(utf8_decode($string)); + if (static::$hasMBString === null) { + static::$hasMBString = extension_loaded( 'mbstring' ); } + $width = (static::$hasMBString) + ? mb_strlen($string, 'UTF-8' ) + : strlen(utf8_decode($string)); + return $width; } + /** + * Trim a string in an encoding-safe way + * + * @param mixed $string + * @param mixed $length + * @return int + */ protected function stringTrim($string, $length) { if ($this->isUtf8()) { if (static::$hasMBString === null) { - static::$hasMBString = extension_loaded( 'mbstring' ); + static::$hasMBString = extension_loaded('mbstring'); } if (static::$hasMBString) { - return mb_strlen( $string, 'UTF-8' ); - } else { - return strlen( utf8_decode( $string ) ); + return mb_strlen($string, 'UTF-8'); } - } else { - return strlen( $string ); + + return strlen(utf8_decode($string)); } + + return strlen($string); } /** @@ -609,8 +591,8 @@ protected function stringTrim($string, $length) */ public function readLine($maxLength = 2048) { - $f = fopen('php://stdin','r'); - $line = stream_get_line($f,2048,"\n"); + $f = fopen('php://stdin','r'); + $line = stream_get_line($f, 2048, PHP_EOL); fclose($f); return rtrim($line,"\n\r"); } @@ -631,4 +613,3 @@ public function readChar($mask = null) return $char; } } - diff --git a/src/AdapterInterface.php b/src/Adapter/AdapterInterface.php similarity index 97% rename from src/AdapterInterface.php rename to src/Adapter/AdapterInterface.php index 245d427..676db68 100644 --- a/src/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -8,7 +8,9 @@ * @package Zend_Console */ -namespace Zend\Console; +namespace Zend\Console\Adapter; + +use Zend\Console\Charset\CharsetInterface; /** * @category Zend @@ -238,19 +240,19 @@ public function resetColor(); /** * Set Console charset to use. * - * @param \Zend\Console\CharsetInterface $charset + * @param CharsetInterface $charset */ public function setCharset(CharsetInterface $charset); /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return CharsetInterface $charset */ public function getCharset(); /** - * @return \Zend\Console\CharsetInterface + * @return CharsetInterface */ public function getDefaultCharset(); diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 77299e0..6cb4374 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -10,25 +10,27 @@ namespace Zend\Console\Adapter; -use Zend\Console\AdapterInterface; -use Zend\Console\ColorInterface as Color; -use Zend\Console\CharsetInterface; -use Zend\Console\Exception\BadMethodCallException; use Zend\Console\Charset; -use Zend\Console; +use Zend\Console\Exception; /** + * @todo Add GNU readline support * @category Zend * @package Zend_Console * @subpackage Adapter * @link http://en.wikipedia.org/wiki/ANSI_escape_code */ -class Posix extends AbstractAdapter implements AdapterInterface +class Posix extends AbstractAdapter { + /** + * Whether or not mbstring is enabled + * + * @var null|bool + */ protected static $hasMBString; /** - * @var \Zend\Console\CharsetInterface + * @var Charset\CharsetInterface */ protected $charset; @@ -40,48 +42,48 @@ class Posix extends AbstractAdapter implements AdapterInterface */ protected static $ansiColorMap = array( 'fg' => array( - Color::NORMAL => '22;39m', - Color::RESET => '22;39m', - - Color::BLACK => '0;30', - Color::RED => '0;31', - Color::GREEN => '0;32', - Color::YELLOW => '0;33', - Color::BLUE => '0;34', - Color::MAGENTA => '0;35', - Color::CYAN => '0;36', - Color::WHITE => '0;37', - - Color::GRAY => '1;30', - Color::LIGHT_RED => '1;31', - Color::LIGHT_GREEN => '1;32', - Color::LIGHT_YELLOW => '1;33', - Color::LIGHT_BLUE => '1;34', - Color::LIGHT_MAGENTA => '1;35', - Color::LIGHT_CYAN => '1;36', - Color::LIGHT_WHITE => '1;37', + Color::NORMAL => '22;39m', + Color::RESET => '22;39m', + + Color::BLACK => '0;30', + Color::RED => '0;31', + Color::GREEN => '0;32', + Color::YELLOW => '0;33', + Color::BLUE => '0;34', + Color::MAGENTA => '0;35', + Color::CYAN => '0;36', + Color::WHITE => '0;37', + + Color::GRAY => '1;30', + Color::LIGHT_RED => '1;31', + Color::LIGHT_GREEN => '1;32', + Color::LIGHT_YELLOW => '1;33', + Color::LIGHT_BLUE => '1;34', + Color::LIGHT_MAGENTA => '1;35', + Color::LIGHT_CYAN => '1;36', + Color::LIGHT_WHITE => '1;37', ), 'bg' => array( - Color::NORMAL => '0;49m', - Color::RESET => '0;49m', - - Color::BLACK => '40', - Color::RED => '41', - Color::GREEN => '42', - Color::YELLOW => '43', - Color::BLUE => '44', - Color::MAGENTA => '45', - Color::CYAN => '46', - Color::WHITE => '47', - - Color::GRAY => '40', - Color::LIGHT_RED => '41', - Color::LIGHT_GREEN => '42', - Color::LIGHT_YELLOW => '43', - Color::LIGHT_BLUE => '44', - Color::LIGHT_MAGENTA => '45', - Color::LIGHT_CYAN => '46', - Color::LIGHT_WHITE => '47', + Color::NORMAL => '0;49m', + Color::RESET => '0;49m', + + Color::BLACK => '40', + Color::RED => '41', + Color::GREEN => '42', + Color::YELLOW => '43', + Color::BLUE => '44', + Color::MAGENTA => '45', + Color::CYAN => '46', + Color::WHITE => '47', + + Color::GRAY => '40', + Color::LIGHT_RED => '41', + Color::LIGHT_GREEN => '42', + Color::LIGHT_YELLOW => '43', + Color::LIGHT_BLUE => '44', + Color::LIGHT_MAGENTA => '45', + Color::LIGHT_CYAN => '46', + Color::LIGHT_WHITE => '47', ), ); @@ -134,32 +136,32 @@ public function getHeight() return $height; } - /** - * Try to read env variable - */ + // Try to read env variable if (($result = getenv('LINES')) !== false) { - return $height = (int)$result; + return $height = (int) $result; } - /** - * Try to read console size from "tput" command - */ - $result = exec('tput lines',$output, $return); + // Try to read console size from "tput" command + $result = exec('tput lines', $output, $return); if (!$return && is_numeric($result)) { return $height = (int)$result; } return $height = parent::getHeight(); - } + /** + * Run a mode command and store results + * + * @return void + */ protected function runModeCommand() { - exec('mode',$output,$return); + exec('mode', $output, $return); if ($return || !count($output)) { $this->modeResult = ''; } else { - $this->modeResult = trim(implode('',$output)); + $this->modeResult = trim(implode('', $output)); } } @@ -170,11 +172,9 @@ protected function runModeCommand() */ public function isUtf8() { - /** - * Try to retrieve it from LANG env variable - */ + // Try to retrieve it from LANG env variable if (($lang = getenv('LANG')) !== false) { - return stristr($lang,'utf-8') || stristr($lang,'utf8'); + return stristr($lang, 'utf-8') || stristr($lang, 'utf8'); } return false; @@ -198,52 +198,49 @@ public function hideCursor() /** * Set cursor position - * @param int $x - * @param int $y + * @param int $x + * @param int $y */ public function setPos($x, $y) { - echo "\x1b[".$y.';'.$x.'f'; + echo "\x1b[" . $y . ';' . $x . 'f'; } /** * Prepare a string that will be rendered in color. * - * @param string $string - * @param int $color - * @param null|int $bgColor + * @param string $string + * @param int $color + * @param null|int $bgColor * @return string */ public function colorize($string, $color = null, $bgColor = null) { - /** - * Retrieve ansi color codes - */ + // Retrieve ansi color codes if ($color !== null) { if (!isset(static::$ansiColorMap['fg'][$color])) { - throw new BadMethodCallException( - 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' - ); - } else { - $color = static::$ansiColorMap['fg'][$color]; + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', + $color + )); } + $color = static::$ansiColorMap['fg'][$color]; } + if ($bgColor !== null) { if (!isset(static::$ansiColorMap['bg'][$bgColor])) { - throw new BadMethodCallException( - 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' - ); - } else { - $bgColor = static::$ansiColorMap['bg'][$bgColor]; + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', + $bgColor + )); } + $bgColor = static::$ansiColorMap['bg'][$bgColor]; } - return - ($color !== null ? "\x1b[".$color.'m' : ''). - ($bgColor !== null ? "\x1b[".$bgColor.'m' : ''). - $string. - "\x1b[22;39m\x1b[0;49m" - ; + return ($color !== null ? "\x1b[" . $color . 'm' : '') + . ($bgColor !== null ? "\x1b[" . $bgColor . 'm' : '') + . $string + . "\x1b[22;39m\x1b[0;49m"; } /** @@ -253,20 +250,18 @@ public function colorize($string, $color = null, $bgColor = null) */ public function setColor($color) { - /** - * Retrieve ansi color code - */ + // Retrieve ansi color code if ($color !== null) { if (!isset(static::$ansiColorMap['fg'][$color])) { - throw new BadMethodCallException( - 'Unknown color "'.$color.'". Please use one of Zend\Console\ColorInterface constants.' - ); - } else { - $color = static::$ansiColorMap['fg'][$color]; + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', + $color + )); } + $color = static::$ansiColorMap['fg'][$color]; } - echo "\x1b[".$color.'m'; + echo "\x1b[" . $color . 'm'; } /** @@ -276,19 +271,19 @@ public function setColor($color) */ public function setBgColor($bgColor) { - /** - * Retrieve ansi color code - */ + // Retrieve ansi color code if ($bgColor !== null) { if (!isset(static::$ansiColorMap['bg'][$bgColor])) { - throw new BadMethodCallException( - 'Unknown color "'.$bgColor.'". Please use one of Zend\Console\ColorInterface constants.' - ); - } else { - $bgColor = static::$ansiColorMap['bg'][$bgColor]; + throw new Exception\BadMethodCallException(sprintf( + 'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants', + $bgColor + )); } + + $bgColor = static::$ansiColorMap['bg'][$bgColor]; } - echo "\x1b[".($bgColor).'m'; + + echo "\x1b[" . ($bgColor) . 'm'; } /** @@ -309,16 +304,14 @@ public function resetColor() */ public function getTitle() { - } /** * Set Console charset to use. * - - * @param \Zend\Console\CharsetInterface $charset + * @param Charset\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset) + public function setCharset(Charset\CharsetInterface $charset) { $this->charset = $charset; } @@ -326,7 +319,7 @@ public function setCharset(CharsetInterface $charset) /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return Charset\CharsetInterface $charset */ public function getCharset() { @@ -338,32 +331,30 @@ public function getCharset() } /** - * @return \Zend\Console\CharsetInterface + * @return Charset\CharsetInterface */ public function getDefaultCharset() { if ($this->isUtf8()) { return new Charset\Utf8; - } else { - return new Charset\DECSG(); } + return new Charset\DECSG(); } /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars + * @param string|null $mask A list of allowed chars * @return string */ public function readChar($mask = null) { $this->setTTYMode('-icanon -echo'); - $stream = fopen('php://stdin','rb'); + $stream = fopen('php://stdin', 'rb'); do { $char = fgetc($stream); - } while (!$char || ($mask !== null && !stristr($mask,$char))); - + } while (!$char || ($mask !== null && !stristr($mask, $char))); fclose($stream); $this->restoreTTYMode(); @@ -375,14 +366,14 @@ public function readChar($mask = null) */ public function clear() { - echo "\x1b[2J"; // reset bg color - $this->setPos(1,1); // reset cursor position + echo "\x1b[2J"; // reset bg color + $this->setPos(1, 1); // reset cursor position } /** * Restore TTY (Console) mode to previous value. * - * @return mixed + * @return void */ protected function restoreTTYMode() { @@ -390,31 +381,21 @@ protected function restoreTTYMode() return; } - shell_exec('stty '.escapeshellarg($this->lastTTYMode)); - + shell_exec('stty ' . escapeshellarg($this->lastTTYMode)); } /** * Change TTY (Console) mode * - * @link http://en.wikipedia.org/wiki/Stty + * @link http://en.wikipedia.org/wiki/Stty * @param $mode */ protected function setTTYMode($mode) { - /** - * Store last mode - */ + // Store last mode $this->lastTTYMode = trim(`stty -g`); - /** - * Set new mode - */ + // Set new mode shell_exec('stty '.escapeshellcmd($mode)); } - - /** - * @todo Add GNU readline support - */ } - diff --git a/src/Adapter/Virtual.php b/src/Adapter/Virtual.php index 9a15240..f96f541 100644 --- a/src/Adapter/Virtual.php +++ b/src/Adapter/Virtual.php @@ -10,11 +10,7 @@ namespace Zend\Console\Adapter; -use Zend\Console\AdapterInterface; -use Zend\Console\ColorInterface; -use Zend\Console\CharsetInterface; use Zend\Console\Charset; -use Zend\Console; /** * Virtual buffer adapter @@ -23,10 +19,20 @@ * @package Zend_Console * @subpackage Adapter */ -class Virtual extends AbstractAdapter implements AdapterInterface +class Virtual extends AbstractAdapter { + /** + * Whether or not mbstring is enabled + * + * @var null|bool + */ protected static $hasMBString; + /** + * Results of mode system command + * + * @var mixed + */ protected $modeResult; /** @@ -41,14 +47,12 @@ public function getWidth() return $width; } - /** - * Try to read console size from "mode" command - */ + // Try to read console size from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } - if (preg_match('/Columns\:\s+(\d+)/',$this->modeResult,$matches)) { + if (preg_match('/Columns\:\s+(\d+)/', $this->modeResult, $matches)) { $width = $matches[1]; } else { $width = parent::getWidth(); @@ -69,14 +73,12 @@ public function getHeight() return $height; } - /** - * Try to read console size from "mode" command - */ + // Try to read console size from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } - if (preg_match('/Rows\:\s+(\d+)/',$this->modeResult,$matches)) { + if (preg_match('/Rows\:\s+(\d+)/', $this->modeResult, $matches)) { $height = $matches[1]; } else { $height = parent::getHeight(); @@ -85,13 +87,18 @@ public function getHeight() return $height; } + /** + * Run and store the results of mode command + * + * @return void + */ protected function runProbeCommand() { - exec('mode',$output,$return); + exec('mode', $output, $return); if ($return || !count($output)) { $this->modeResult = ''; } else { - $this->modeResult = trim(implode('',$output)); + $this->modeResult = trim(implode('', $output)); } } @@ -102,15 +109,13 @@ protected function runProbeCommand() */ public function isUtf8() { - /** - * Try to read code page info from "mode" command - */ + // Try to read code page info from "mode" command if ($this->modeResult === null) { $this->runProbeCommand(); } - if (preg_match('/Code page\:\s+(\d+)/',$this->modeResult,$matches)) { - return (int)$matches[1] == 65001; + if (preg_match('/Code page\:\s+(\d+)/', $this->modeResult, $matches)) { + return (int) $matches[1] == 65001; } return false; @@ -118,12 +123,12 @@ public function isUtf8() /** * Set cursor position - * @param int $x - * @param int $y + * + * @param int $x + * @param int $y */ public function setPos($x, $y) { - } /** @@ -133,23 +138,21 @@ public function setPos($x, $y) */ public function getTitle() { - /** - * Try to use powershell to retrieve console window title - */ - exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); + // Try to use powershell to retrieve console window title + exec('powershell -command "write $Host.UI.RawUI.WindowTitle"', $output, $result); if ($result || !$output) { return ''; } - return trim($output,"\r\n"); + return trim($output, "\r\n"); } /** * Set Console charset to use. * - * @param \Zend\Console\CharsetInterface $charset + * @param Charset\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset) + public function setCharset(Charset\CharsetInterface $charset) { $this->charset = $charset; } @@ -157,7 +160,7 @@ public function setCharset(CharsetInterface $charset) /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return Charset\CharsetInterface $charset */ public function getCharset() { @@ -169,16 +172,20 @@ public function getCharset() } /** - * @return \Zend\Console\Charset\AsciiExtended + * @return Charset\AsciiExtended */ public function getDefaultCharset() { return new Charset\AsciiExtended; } + /** + * Switch to UTF mode + * + * @return void + */ protected function switchToUtf8() { - `mode con cp select=65001`; + shell_exec('mode con cp select=65001'); } - } diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index 4d984f1..28b638e 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -10,22 +10,28 @@ namespace Zend\Console\Adapter; -use Zend\Console\AdapterInterface; -use Zend\Console\ColorInterface; -use Zend\Console\CharsetInterface; -use Zend\Console\Exception\RuntimeException; use Zend\Console\Charset; -use Zend\Console; +use Zend\Console\Exception; /** * @category Zend * @package Zend_Console * @subpackage Adapter */ -class Windows extends Virtual implements AdapterInterface +class Windows extends Virtual { + /** + * Whether or not mbstring is enabled + * + * @var null|bool + */ protected static $hasMBString; + /** + * Results of probing system capabilities + * + * @var mixed + */ protected $probeResult; /** @@ -40,14 +46,12 @@ public function getWidth() return $width; } - /** - * Try to read console size from "mode" command - */ + // Try to read console size from "mode" command if ($this->probeResult === null) { $this->runProbeCommand(); } - if (count($this->probeResult) && (int)$this->probeResult[0]) { + if (count($this->probeResult) && (int) $this->probeResult[0]) { $width = (int)$this->probeResult[0]; } else { $width = parent::getWidth(); @@ -68,14 +72,12 @@ public function getHeight() return $height; } - /** - * Try to read console size from "mode" command - */ + // Try to read console size from "mode" command if ($this->probeResult === null) { $this->runProbeCommand(); } - if (count($this->probeResult) && (int)$this->probeResult[1]) { + if (count($this->probeResult) && (int) $this->probeResult[1]) { $height = (int)$this->probeResult[1]; } else { $height = parent::getheight(); @@ -84,13 +86,17 @@ public function getHeight() return $height; } + /** + * Probe for system capabilities and cache results + * + * Run a Windows Powershell command that determines parameters of console window. The command is fed through + * standard input (with echo) to prevent Powershell from creating a sub-thread and hanging PHP when run through + * a debugger/IDE. + * + * @return void + */ protected function runProbeCommand() { - /** - * Run a Windows Powershell command that determines parameters of console window. The command is fed through - * standard input (with echo) to prevent Powershell from creating a sub-thread and hanging PHP when run through - * a debugger/IDE. - */ exec( 'echo $size = $Host.ui.rawui.windowsize; write $($size.width) $($size.height) | powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command -', $output, @@ -110,15 +116,13 @@ protected function runProbeCommand() */ public function isUtf8() { - /** - * Try to read code page info from "mode" command - */ + // Try to read code page info from "mode" command if ($this->probeResult === null) { $this->runProbeCommand(); } - if (preg_match('/Code page\:\s+(\d+)/',$this->probeResult,$matches)) { - return (int)$matches[1] == 65001; + if (preg_match('/Code page\:\s+(\d+)/', $this->probeResult, $matches)) { + return (int) $matches[1] == 65001; } return false; @@ -126,12 +130,11 @@ public function isUtf8() /** * Set cursor position - * @param int $x - * @param int $y + * @param int $x + * @param int $y */ public function setPos($x, $y) { - } /** @@ -141,23 +144,21 @@ public function setPos($x, $y) */ public function getTitle() { - /** - * Try to use powershell to retrieve console window title - */ - exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); + // Try to use powershell to retrieve console window title + exec('powershell -command "write $Host.UI.RawUI.WindowTitle"', $output, $result); if ($result || !$output) { return ''; } - return trim($output,"\r\n"); + return trim($output, "\r\n"); } /** * Set Console charset to use. * - * @param \Zend\Console\CharsetInterface $charset + * @param Charset\CharsetInterface $charset */ - public function setCharset(CharsetInterface $charset) + public function setCharset(Charset\CharsetInterface $charset) { $this->charset = $charset; } @@ -165,7 +166,7 @@ public function setCharset(CharsetInterface $charset) /** * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return Charset\CharsetInterface $charset */ public function getCharset() { @@ -177,16 +178,21 @@ public function getCharset() } /** - * @return \Zend\Console\Charset\AsciiExtended + * @return Charset\AsciiExtended */ public function getDefaultCharset() { return new Charset\AsciiExtended; } + /** + * Switch to utf-8 encoding + * + * @return void + */ protected function switchToUtf8() { - `mode con cp select=65001`; + shell_exec('mode con cp select=65001'); } /** @@ -194,7 +200,7 @@ protected function switchToUtf8() */ public function clear() { - echo str_repeat("\r\n",$this->getHeight()); + echo str_repeat("\r\n", $this->getHeight()); } /** @@ -202,54 +208,48 @@ public function clear() */ public function clearLine() { - echo "\r".str_repeat(' ',$this->getWidth())."\r"; + echo "\r" . str_repeat(' ', $this->getWidth()) . "\r"; } /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars - * @throws \Zend\Console\Exception\RuntimeException + * @param string|null $mask A list of allowed chars + * @throws Exception\RuntimeException * @return string */ public function readChar($mask = null) { - /** - * Decide if we can use `choice` tool - */ + // Decide if we can use `choice` tool $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]+$/D', $mask); if ($useChoice) { - /** - * Use Windows 95+ "choice" command, which allows for reading a single character matching a mask, - * but is limited to lower ASCII range. - */ + // Use Windows 95+ "choice" command, which allows for reading a + // single character matching a mask, but is limited to lower ASCII + // range. do { system('choice /n /cs /c:' . $mask, $return); if ($return == 255 || $return < 1 || $return > strlen($mask)) { - throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); - } else { - /** - * Fetch the char from mask - */ - $char = substr($mask, $return - 1, 1); + throw new Exception\RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); } + // Fetch the char from mask + $char = substr($mask, $return - 1, 1); } while (!$char || ($mask !== null && !stristr($mask, $char))); return $char; } - /** - * Try to use PowerShell, giving it console access. Because PowersShell interpreter can take a short while to - * load, we are emptying the whole keyboard buffer and picking the last key that has been pressed before or - * after PowerShell command has started. The ASCII code for that key is then converted to a character. - */ + // Try to use PowerShell, giving it console access. Because PowersShell + // interpreter can take a short while to load, we are emptying the + // whole keyboard buffer and picking the last key that has been pressed + // before or after PowerShell command has started. The ASCII code for + // that key is then converted to a character. if ($mask === null) { exec( - 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' . - 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}' . - 'write $key.VirtualKeyCode;' . - '"', + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' + . 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}' + . 'write $key.VirtualKeyCode;' + . '"', $result, $return ); @@ -265,35 +265,32 @@ public function readChar($mask = null) return $char; } } else { - /** - * Windows and DOS will return carriage-return char (ASCII 13) when the user presses [ENTER] key, - * but Console Adapter user might have provided a \n Newline (ASCII 10) in the mask, to allow [ENTER]. - * We are going to replace all CR with NL to conform. - */ + // Windows and DOS will return carriage-return char (ASCII 13) when + // the user presses [ENTER] key, but Console Adapter user might + // have provided a \n Newline (ASCII 10) in the mask, to allow [ENTER]. + // We are going to replace all CR with NL to conform. $mask = strtr($mask, "\n", "\r"); - /** - * Prepare a list of ASCII codes from mask chars - */ - $asciiMask = array_map(function($char) - { + // Prepare a list of ASCII codes from mask chars + $asciiMask = array_map(function ($char) { return ord($char); }, str_split($mask)); $asciiMask = array_unique($asciiMask); - /** - * Char mask filtering is now handled by the PowerShell itself, because it's a much faster method than - * invoking PS interpreter after each mismatch. The command should return ASCII code of a matching key. - */ + // Char mask filtering is now handled by the PowerShell itself, + // because it's a much faster method than invoking PS interpreter + // after each mismatch. The command should return ASCII code of a + // matching key. $result = $return = null; + exec( - 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' . - '[int[]] $mask = ' . join(',', $asciiMask) . ';' . - 'do {' . - '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;' . - '} while( !($mask -contains $key) );' . - 'write $key;' . - '"', + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' + . '[int[]] $mask = ' . join(',', $asciiMask) . ';' + . 'do {' + . '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;' + . '} while( !($mask -contains $key) );' + . 'write $key;' + . '"', $result, $return ); @@ -314,11 +311,10 @@ public function readChar($mask = null) } } - /** - * Fall back to standard input, which on Windows does not allow reading a single character. This is a - * limitation of Windows streams implementation (not PHP) and this behavior cannot be changed with a command - * like "stty", known to POSIX systems. - */ + // Fall back to standard input, which on Windows does not allow reading + // a single character. This is a limitation of Windows streams + // implementation (not PHP) and this behavior cannot be changed with a + // command like "stty", known to POSIX systems. $stream = fopen('php://stdin', 'rb'); do { $char = fgetc($stream); @@ -332,16 +328,15 @@ public function readChar($mask = null) /** * Read a single line from the console input. * - * @param int $maxLength Maximum response length + * @param int $maxLength Maximum response length * @return string */ public function readLine($maxLength = 2048) { - $f = fopen('php://stdin','r'); + $f = fopen('php://stdin','r'); $line = trim(fread($f,$maxLength)); fclose($f); return $line; } - } diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index 45370b7..e07f27e 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -10,12 +10,9 @@ namespace Zend\Console\Adapter; -use Zend\Console\AdapterInterface; -use Zend\Console\ColorInterface; -use Zend\Console\CharsetInterface; -use Zend\Console\Exception\RuntimeException; +use Zend\Console\Charset\CharsetInterface; +use Zend\Console\Exception; use Zend\Console\Charset; -use Zend\Console; /** * MS Windows with ANSICON console adapter @@ -35,10 +32,20 @@ * @package Zend_Console * @subpackage Adapter */ -class WindowsAnsicon extends Posix implements AdapterInterface +class WindowsAnsicon extends Posix { + /** + * Whether or not mbstring is enabled + * + * @var null|bool + */ protected static $hasMBString; + /** + * Results of mode command + * + * @var mixed + */ protected $modeResult; /** @@ -53,10 +60,8 @@ public function getWidth() return $width; } - /** - * Try to read console size from ANSICON env var - */ - if (preg_match('/\((\d+)x/',getenv('ANSICON'),$matches)) { + // Try to read console size from ANSICON env var + if (preg_match('/\((\d+)x/', getenv('ANSICON'), $matches)) { $width = $matches[1]; } else { $width = AbstractAdapter::getWidth(); @@ -77,10 +82,8 @@ public function getHeight() return $height; } - /** - * Try to read console size from ANSICON env var - */ - if (preg_match('/\(\d+x(\d+)/',getenv('ANSICON'),$matches)) { + // Try to read console size from ANSICON env var + if (preg_match('/\(\d+x(\d+)/', getenv('ANSICON'), $matches)) { $height = $matches[1]; } else { $height = AbstractAdapter::getHeight(); @@ -88,13 +91,18 @@ public function getHeight() return $height; } + /** + * Run and cache results of mode command + * + * @return void + */ protected function runModeCommand() { - exec('mode',$output,$return); + exec('mode', $output, $return); if ($return || !count($output)) { $this->modeResult = ''; } else { - $this->modeResult = trim(implode('',$output)); + $this->modeResult = trim(implode('', $output)); } } @@ -105,15 +113,13 @@ protected function runModeCommand() */ public function isUtf8() { - /** - * Try to read code page info from "mode" command - */ + // Try to read code page info from "mode" command if ($this->modeResult === null) { $this->runModeCommand(); } - if (preg_match('/Code page\:\s+(\d+)/', $this->modeResult,$matches)) { - return (int)$matches[1] == 65001; + if (preg_match('/Code page\:\s+(\d+)/', $this->modeResult, $matches)) { + return (int) $matches[1] == 65001; } return false; @@ -126,15 +132,13 @@ public function isUtf8() */ public function getTitle() { - /** - * Try to use powershell to retrieve console window title - */ - exec('powershell -command "write $Host.UI.RawUI.WindowTitle"',$output,$result); + // Try to use powershell to retrieve console window title + exec('powershell -command "write $Host.UI.RawUI.WindowTitle"', $output, $result); if ($result || !$output) { return ''; } - return trim($output,"\r\n"); + return trim($output, "\r\n"); } /** @@ -142,7 +146,7 @@ public function getTitle() */ public function clear() { - echo chr(27).'[1J'.chr(27).'[u'; + echo chr(27) . '[1J' . chr(27) . '[u'; } /** @@ -150,14 +154,14 @@ public function clear() */ public function clearLine() { - echo chr(27).'[1K'; + echo chr(27) . '[1K'; } /** * Set Console charset to use. * - * @param \Zend\Console\CharsetInterface $charset + * @param CharsetInterface $charset */ public function setCharset(CharsetInterface $charset) { @@ -168,7 +172,7 @@ public function setCharset(CharsetInterface $charset) * Get charset currently in use by this adapter. * - * @return \Zend\Console\CharsetInterface $charset + * @return CharsetInterface $charset */ public function getCharset() { @@ -180,7 +184,7 @@ public function getCharset() } /** - * @return \Zend\Console\Charset\AsciiExtended + * @return Charset\AsciiExtended */ public function getDefaultCharset() { @@ -190,48 +194,43 @@ public function getDefaultCharset() /** * Read a single character from the console input * - * @param string|null $mask A list of allowed chars - * @throws \Zend\Console\Exception\RuntimeException + * @param string|null $mask A list of allowed chars * @return string + * @throws Exception\RuntimeException */ public function readChar($mask = null) { - /** - * Decide if we can use `choice` tool - */ + // Decide if we can use `choice` tool $useChoice = $mask !== null && preg_match('/^[a-zA-Z0-9]+$/D', $mask); if ($useChoice) { - /** - * Use Windows 98+ "choice" command, which allows for reading a single character matching a mask, - * but is limited to lower ASCII range. - */ + // Use Windows 98+ "choice" command, which allows for reading a + // single character matching a mask, but is limited to lower ASCII + // range. do { - system('choice /n /cs /c:'.$mask,$return); + system('choice /n /cs /c:' . $mask, $return); if ($return == 255 || $return < 1 || $return > strlen($mask)) { - throw new RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); - } else { - /** - * Fetch the char from mask - */ - $char = substr($mask,$return-1,1); + throw new Exception\RuntimeException('"choice" command failed to run. Are you using Windows XP or newer?'); } + + // Fetch the char from mask + $char = substr($mask, $return - 1, 1); } while (!$char || ($mask !== null && !stristr($mask, $char))); return $char; } - /** - * Try to use PowerShell, giving it console access. Because PowersShell interpreter can take a short while to - * load, we are emptying the whole keyboard buffer and picking the last key that has been pressed before or - * after PowerShell command has started. The ASCII code for that key is then converted to a character. - */ + // Try to use PowerShell, giving it console access. Because PowersShell + // interpreter can take a short while to load, we are emptying the + // whole keyboard buffer and picking the last key that has been pressed + // before or after PowerShell command has started. The ASCII code for + // that key is then converted to a character. if ($mask === null) { exec( - 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "'. - 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}'. - 'write $key.VirtualKeyCode;'. - '"', + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' + . 'while ($Host.UI.RawUI.KeyAvailable) {$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\');}' + . 'write $key.VirtualKeyCode;' + . '"', $result, $return ); @@ -239,7 +238,7 @@ public function readChar($mask = null) // Retrieve char from the result. $char = !empty($result) ? implode('', $result) : null; - if(!empty($char) && !$return){ + if (!empty($char) && !$return){ // We have obtained an ASCII code, convert back to a char ... $char = chr($char); @@ -247,45 +246,44 @@ public function readChar($mask = null) return $char; } } else { - /** - * Windows and DOS will return carriage-return char (ASCII 13) when the user presses [ENTER] key, - * but Console Adapter user might have provided a \n Newline (ASCII 10) in the mask, to allow [ENTER]. - * We are going to replace all CR with NL to conform. - */ - $mask = strtr($mask,"\n","\r"); - - /** - * Prepare a list of ASCII codes from mask chars - */ - $asciiMask = array_map(function($char){ + // Windows and DOS will return carriage-return char (ASCII 13) when + // the user presses [ENTER] key, but Console Adapter user might + // have provided a \n Newline (ASCII 10) in the mask, to allow + // [ENTER]. We are going to replace all CR with NL to conform. + $mask = strtr($mask, "\n", "\r"); + + // Prepare a list of ASCII codes from mask chars + $asciiMask = array_map(function ($char) { return ord($char); - },str_split($mask)); + }, str_split($mask)); $asciiMask = array_unique($asciiMask); - /** - * Char mask filtering is now handled by the PowerShell itself, because it's a much faster method than - * invoking PS interpreter after each mismatch. The command should return ASCII code of a matching key. - */ + // Char mask filtering is now handled by the PowerShell itself, + // because it's a much faster method than invoking PS interpreter + // after each mismatch. The command should return ASCII code of a + // matching key. $result = $return = null; exec( - 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "'. - '[int[]] $mask = '.join(',',$asciiMask).';'. - 'do {'. - '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;'. - '} while( !($mask -contains $key) );'. - 'write $key;'. - '"', + 'powershell -NonInteractive -NoProfile -NoLogo -OutputFormat Text -Command "' + . '[int[]] $mask = '.join(',',$asciiMask).';' + . 'do {' + . '$key = $Host.UI.RawUI.ReadKey(\'NoEcho,IncludeKeyDown\').VirtualKeyCode;' + . '} while( !($mask -contains $key) );' + . 'write $key;' + . '"', $result, $return ); - $char = !empty($result) ? trim(implode('',$result)) : null; + $char = !empty($result) ? trim(implode('', $result)) : null; - if(!$return && $char && ($mask === null || in_array($char,$asciiMask))){ - // We have obtained an ASCII code, check if it is a carriage return and normalize it as needed + if (!$return && $char && ($mask === null || in_array($char,$asciiMask))) { + // We have obtained an ASCII code, check if it is a carriage + // return and normalize it as needed if ($char == 13) { $char = 10; } + // Convert to a character $char = chr($char); @@ -294,12 +292,11 @@ public function readChar($mask = null) } } - /** - * Fall back to standard input, which on Windows does not allow reading a single character. This is a - * limitation of Windows streams implementation (not PHP) and this behavior cannot be changed with a command - * like "stty", known to POSIX systems. - */ - $stream = fopen('php://stdin','rb'); + // Fall back to standard input, which on Windows does not allow reading + // a single character. This is a limitation of Windows streams + // implementation (not PHP) and this behavior cannot be changed with a + // command like "stty", known to POSIX systems. + $stream = fopen('php://stdin', 'rb'); do { $char = fgetc($stream); $char = substr(trim($char), 0, 1); @@ -308,5 +305,4 @@ public function readChar($mask = null) return $char; } - } diff --git a/src/Charset/Ascii.php b/src/Charset/Ascii.php index b1d193b..5614127 100644 --- a/src/Charset/Ascii.php +++ b/src/Charset/Ascii.php @@ -10,8 +10,6 @@ namespace Zend\Console\Charset; -use Zend\Console\CharsetInterface; - /** * Basic (low) ASCII line drawing characters. * diff --git a/src/Charset/AsciiExtended.php b/src/Charset/AsciiExtended.php index 7357f1b..b13acaf 100644 --- a/src/Charset/AsciiExtended.php +++ b/src/Charset/AsciiExtended.php @@ -10,8 +10,6 @@ namespace Zend\Console\Charset; -use Zend\Console\CharsetInterface; - /** * Extended ASCII character set (positions 127+, MS DOS & Windows compatible) * diff --git a/src/CharsetInterface.php b/src/Charset/CharsetInterface.php similarity index 92% rename from src/CharsetInterface.php rename to src/Charset/CharsetInterface.php index b1cd2a6..98cd068 100644 --- a/src/CharsetInterface.php +++ b/src/Charset/CharsetInterface.php @@ -8,7 +8,7 @@ * @package Zend_Console */ -namespace Zend\Console; +namespace Zend\Console\Charset; /** * @category Zend diff --git a/src/Charset/DECSG.php b/src/Charset/DECSG.php index ec6b9ff..d86bd2a 100644 --- a/src/Charset/DECSG.php +++ b/src/Charset/DECSG.php @@ -10,8 +10,6 @@ namespace Zend\Console\Charset; -use Zend\Console\CharsetInterface; - /** * DEC Special Graphics (VT100 line drawing) character set * diff --git a/src/Charset/Utf8.php b/src/Charset/Utf8.php index 17afa58..4c1cb74 100644 --- a/src/Charset/Utf8.php +++ b/src/Charset/Utf8.php @@ -10,8 +10,6 @@ namespace Zend\Console\Charset; -use Zend\Console\CharsetInterface; - /** * UTF-8 box drawing * diff --git a/src/Console.php b/src/Console.php index 5ab40f3..5771d3e 100644 --- a/src/Console.php +++ b/src/Console.php @@ -10,8 +10,6 @@ namespace Zend\Console; -use Zend\Console\Exception\InvalidArgumentException; - /** * An static, utility class for interacting with Console enviromen. * Declared abstract to prevent from instantiating. @@ -22,72 +20,67 @@ abstract class Console { /** - * @var \Zend\Console\Adapter + * @var Adapter\AdapterInterface */ protected static $instance; /** - * Instantiate (if needed) and retrieve Console\Adapter instance. - * + * Instantiate (if needed) and retrieve Adapter\AdapterInterface instance. * - * @static - * @param null $forceAdapter Console\Adapter class name (can be absolute namespace or relative to Adapter\) - * @return \Zend\Console\Adapter + * @param null $forceAdapter Adapter\AdapterInterface class name (can be absolute namespace or relative to Adapter\) + * @return Adapter\AdapterInterface */ public static function getInstance($forceAdapter = null, $forceCharset = null) { - /** - * Create instance - */ - if (static::$instance === null) { - if ($forceAdapter !== null) { - /** - * Use the supplied adapter class - */ - if (substr($forceAdapter,0,1) == '\\') { - $className = $forceAdapter; - } elseif (stristr($forceAdapter,'\\')) { - $className = __NAMESPACE__.'\\'.ltrim($forceAdapter,'\\'); - } else { - $className = __NAMESPACE__.'\\Adapter\\'.$forceAdapter; - } - - if (!class_exists($className)) { - throw new InvalidArgumentException('Cannot find Console adapter class '.$className); - } + if (static::$instance instanceof Adapter\AdapterInterface) { + return static::$instance; + } + + // Create instance + + if ($forceAdapter !== null) { + // Use the supplied adapter class + if (substr($forceAdapter, 0, 1) == '\\') { + $className = $forceAdapter; + } elseif (stristr($forceAdapter, '\\')) { + $className = __NAMESPACE__ . '\\' . ltrim($forceAdapter, '\\'); } else { - /** - * Try to detect best instance for console - */ - $className = static::detectBestAdapter(); + $className = __NAMESPACE__ . '\\Adapter\\' . $forceAdapter; } - /** - * Create adapter instance - */ - static::$instance = new $className(); - - /** - * Try to use the supplied charset class - */ - if ($forceCharset !== null) { - if (substr($forceCharset,0,1) == '\\') { - $className = $forceCharset; - } elseif (stristr($forceAdapter,'\\')) { - $className = __NAMESPACE__.'\\'.ltrim($forceCharset,'\\'); - } else { - $className = __NAMESPACE__.'\\Charset\\'.$forceCharset; - } - - if (!class_exists($className)) { - throw new InvalidArgumentException('Cannot find Charset class '.$className); - } - - /** - * Set adapter charset - */ - static::$instance->setCharset(new $className()); + if (!class_exists($className)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Cannot find Console adapter class "%s"', + $className + )); } + } else { + // Try to detect best instance for console + $className = static::detectBestAdapter(); + } + + // Create adapter instance + static::$instance = new $className(); + + // Try to use the supplied charset class + if ($forceCharset !== null) { + if (substr($forceCharset, 0, 1) == '\\') { + $className = $forceCharset; + } elseif (stristr($forceAdapter, '\\')) { + $className = __NAMESPACE__ . '\\' . ltrim($forceCharset, '\\'); + } else { + $className = __NAMESPACE__ . '\\Charset\\' . $forceCharset; + } + + if (!class_exists($className)) { + throw new Exception\InvalidArgumentException(sprintf( + 'Cannot find Charset class "%s"', + $className + )); + } + + // Set adapter charset + static::$instance->setCharset(new $className()); } return static::$instance; @@ -96,18 +89,16 @@ public static function getInstance($forceAdapter = null, $forceCharset = null) /** * Check if currently running under MS Windows * - * @static * @return bool */ public static function isWindows() { - return class_exists('COM',false); + return class_exists('COM', false); } /** * Check if running under MS Windows Ansicon * - * @static * @return bool */ public static function isAnsicon() @@ -118,7 +109,6 @@ public static function isAnsicon() /** * Check if running in a console environment (CLI) * - * @static * @return bool */ public static function isConsole() @@ -127,8 +117,7 @@ public static function isConsole() } /** - * @static - * @return \Zend\Console\Adapter|null + * @return string|null */ public static function detectBestAdapter() { @@ -140,23 +129,22 @@ public static function detectBestAdapter() // Check if we're on windows if (static::isWindows()) { if (static::isAnsicon()) { - $className = __NAMESPACE__.'\Adapter\WindowsAnsicon'; + $className = __NAMESPACE__ . '\Adapter\WindowsAnsicon'; } else { - $className = __NAMESPACE__.'\Adapter\Windows'; + $className = __NAMESPACE__ . '\Adapter\Windows'; } - return new $className(); + return $className; } // Default is a Posix console - $className = __NAMESPACE__.'\Adapter\Posix'; - return new $className(); + $className = __NAMESPACE__ . '\Adapter\Posix'; + return $className; } /** - * Pass-thru static call to current Console\Adapter instance. + * Pass-thru static call to current AdapterInterface instance. * - * @static * @param $funcName * @param $arguments * @return mixed @@ -164,6 +152,6 @@ public static function detectBestAdapter() public static function __callStatic($funcName, $arguments) { $instance = static::getInstance(); - return call_user_func_array(array($instance,$funcName),$arguments); + return call_user_func_array(array($instance, $funcName), $arguments); } } diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index 2a7773b..ec3b57d 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -10,10 +10,9 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; -use Zend\Console\Console; -use Zend\Console\AdapterInterface as ConsoleAdapter; -use Zend\Console\Exception\BadMethodCallException; +use ReflectionClass; +use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter; +use Zend\Console\Exception; /** * @category Zend @@ -23,7 +22,7 @@ abstract class AbstractPrompt implements PromptInterface { /** - * @var Zend\Console\AdapterInterface + * @var ConsoleAdapter */ protected $console; @@ -32,6 +31,11 @@ abstract class AbstractPrompt implements PromptInterface */ protected $lastResponse; + /** + * Show a prompt + * + * @return void + */ abstract public function show(); /** @@ -47,7 +51,7 @@ public function getLastResponse() /** * Return console adapter to use when showing prompt. * - * @return \Zend\Console\AdapterInterface + * @return ConsoleAdapter */ public function getConsole() { @@ -61,7 +65,7 @@ public function getConsole() /** * Set console adapter to use when showing prompt. * - * @param \Zend\Console\AdapterInterface $adapter + * @param ConsoleAdapter $adapter */ public function setConsole(ConsoleAdapter $adapter) { @@ -70,24 +74,24 @@ public function setConsole(ConsoleAdapter $adapter) /** * Create an instance of this prompt, show it and return response. - * + * * This is a convenience method for creating statically creating prompts, i.e.: * * $name = Zend\Console\Prompt\Line::prompt("Enter your name: "); * - * @throws \Zend\Console\Exception\BadMethodCallException * @return mixed + * @throws Exception\BadMethodCallException */ - public static function prompt(){ + public static function prompt() + { if (get_called_class() === __CLASS__) { - throw new BadMethodCallException( - 'Cannot call prompt() on AbstractPrompt class. Use one of Console\Prompt\ subclasses.' + throw new Exception\BadMethodCallException( + 'Cannot call prompt() on AbstractPrompt class. Use one of the Zend\Console\Prompt\ subclasses.' ); } - $refl = new \ReflectionClass(get_called_class()); + $refl = new ReflectionClass(get_called_class()); $instance = $refl->newInstanceArgs(func_get_args()); return $instance->show(); } - } diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 7985141..c937ed6 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -10,14 +10,12 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; - /** * @category Zend * @package Zend_Console * @subpackage Prompt */ -class Char extends AbstractPrompt implements PromptInterface +class Char extends AbstractPrompt { /** * @var string diff --git a/src/Prompt/Confirm.php b/src/Prompt/Confirm.php index e8dcaf3..39bcb84 100644 --- a/src/Prompt/Confirm.php +++ b/src/Prompt/Confirm.php @@ -10,14 +10,12 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; - /** * @category Zend * @package Zend_Console * @subpackage Prompt */ -class Confirm extends Char implements PromptInterface +class Confirm extends Char { /** * @var string diff --git a/src/Prompt/Line.php b/src/Prompt/Line.php index 66e46c8..7f5c582 100644 --- a/src/Prompt/Line.php +++ b/src/Prompt/Line.php @@ -10,14 +10,12 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; - /** * @category Zend * @package Zend_Console * @subpackage Prompt */ -class Line extends AbstractPrompt implements PromptInterface +class Line extends AbstractPrompt { /** * @var string diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index ae82cd0..cd12f54 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -10,14 +10,12 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; - /** * @category Zend * @package Zend_Console * @subpackage Prompt */ -class Number extends Line implements PromptInterface +class Number extends Line { /** * @var string diff --git a/src/PromptInterface.php b/src/Prompt/PromptInterface.php similarity index 83% rename from src/PromptInterface.php rename to src/Prompt/PromptInterface.php index ea13f14..651d242 100644 --- a/src/PromptInterface.php +++ b/src/Prompt/PromptInterface.php @@ -8,9 +8,9 @@ * @package Zend_Console */ -namespace Zend\Console; +namespace Zend\Console\Prompt; -use Zend\Console\AdapterInterface as ConsoleAdapter; +use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter; /** * @category Zend @@ -18,7 +18,6 @@ */ interface PromptInterface { - /** * Show the prompt to user and return the answer. * @@ -36,15 +35,14 @@ public function getLastResponse(); /** * Return console adapter to use when showing prompt. * - * @return \Zend\Console\AdapterInterface + * @return ConsoleAdapter */ public function getConsole(); /** * Set console adapter to use when showing prompt. * - * @param \Zend\Console\AdapterInterface $adapter + * @param ConsoleAdapter $adapter */ public function setConsole(ConsoleAdapter $adapter); - } diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index e2d8b77..90524b6 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -10,15 +10,14 @@ namespace Zend\Console\Prompt; -use Zend\Console\PromptInterface; -use Zend\Console\Exception\BadMethodCallException; +use Zend\Console\Exception; /** * @category Zend * @package Zend_Console * @subpackage Prompt */ -class Select extends Char implements PromptInterface +class Select extends Char { /** * @var string @@ -54,7 +53,7 @@ public function __construct( } if (!count($options)) { - throw new BadMethodCallException( + throw new Exception\BadMethodCallException( 'Cannot construct a "select" prompt without any options' ); } @@ -111,7 +110,7 @@ public function show() public function setOptions($options) { if (!is_array($options) && !$options instanceof \Traversable) { - throw new BadMethodCallException( + throw new Exception\BadMethodCallException( 'Please specify an array or Traversable object as options' ); } From 9536f098e262b41e1f45e35eff3f5171360ac901 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Thu, 2 Aug 2012 22:24:01 +0200 Subject: [PATCH 88/98] Fix fatal errors after recent changes, fix handling of space and 0 in Posix adapter. --- src/Adapter/AbstractAdapter.php | 2 +- src/Adapter/Posix.php | 3 ++- src/Console.php | 13 ++++++++++--- src/Prompt/AbstractPrompt.php | 1 + src/Prompt/Char.php | 2 +- src/Prompt/Select.php | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 823c50a..bd319a1 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -592,7 +592,7 @@ protected function stringTrim($string, $length) public function readLine($maxLength = 2048) { $f = fopen('php://stdin','r'); - $line = stream_get_line($f, 2048, PHP_EOL); + $line = stream_get_line($f, $maxLength, PHP_EOL); fclose($f); return rtrim($line,"\n\r"); } diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index 6cb4374..a1508b4 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -12,6 +12,7 @@ use Zend\Console\Charset; use Zend\Console\Exception; +use Zend\Console\ColorInterface as Color; /** * @todo Add GNU readline support @@ -354,7 +355,7 @@ public function readChar($mask = null) $stream = fopen('php://stdin', 'rb'); do { $char = fgetc($stream); - } while (!$char || ($mask !== null && !stristr($mask, $char))); + } while (strlen($char) !== 1 || ($mask !== null && stristr($mask, $char) === false)); fclose($stream); $this->restoreTTYMode(); diff --git a/src/Console.php b/src/Console.php index 5771d3e..92d3cb8 100644 --- a/src/Console.php +++ b/src/Console.php @@ -11,7 +11,7 @@ namespace Zend\Console; /** - * An static, utility class for interacting with Console enviromen. + * An static, utility class for interacting with Console enviroment. * Declared abstract to prevent from instantiating. * * @category Zend @@ -25,9 +25,15 @@ abstract class Console protected static $instance; /** - * Instantiate (if needed) and retrieve Adapter\AdapterInterface instance. + * Create and return Adapter\AdapterInterface instance. * - * @param null $forceAdapter Adapter\AdapterInterface class name (can be absolute namespace or relative to Adapter\) + * @param null|string $forceAdapter Optional adapter class name. Ccan be absolute namespace or class name + * relative to Zend\Console\Adapter\. If not provided, a best matching + * adapter will be automatically selected. + * @param null|string $forceCharset optional charset name can be absolute namespace or class name relative to + * Zend\Console\Charset\. If not provided, charset will be detected + * automatically. + * @throws Exception\InvalidArgumentException * @return Adapter\AdapterInterface */ public static function getInstance($forceAdapter = null, $forceCharset = null) @@ -117,6 +123,7 @@ public static function isConsole() } /** + * Try to detect best matching adapter * @return string|null */ public static function detectBestAdapter() diff --git a/src/Prompt/AbstractPrompt.php b/src/Prompt/AbstractPrompt.php index ec3b57d..c6c6641 100644 --- a/src/Prompt/AbstractPrompt.php +++ b/src/Prompt/AbstractPrompt.php @@ -11,6 +11,7 @@ namespace Zend\Console\Prompt; use ReflectionClass; +use Zend\Console\Console; use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter; use Zend\Console\Exception; diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index c937ed6..9cef7d4 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -121,7 +121,7 @@ public function show() /** * Check if it is an allowed char */ - if (stristr($this->allowedChars,$char)) { + if (stristr($this->allowedChars,$char) !== false) { if ($this->echo) { echo trim($char)."\n"; } else { diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index 90524b6..bfdbaec 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -105,7 +105,7 @@ public function show() /** * Set allowed options * - * @param array|Traversable $options + * @param array|\Traversable $options */ public function setOptions($options) { From e0d026738a3af7ecc867ea1f8ef6e3a3d2cc3a6a Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Fri, 3 Aug 2012 02:19:04 +0000 Subject: [PATCH 89/98] Fixed typos --- src/Console.php | 2 +- src/Getopt.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console.php b/src/Console.php index 92d3cb8..930f251 100644 --- a/src/Console.php +++ b/src/Console.php @@ -11,7 +11,7 @@ namespace Zend\Console; /** - * An static, utility class for interacting with Console enviroment. + * An static, utility class for interacting with Console environment. * Declared abstract to prevent from instantiating. * * @category Zend diff --git a/src/Getopt.php b/src/Getopt.php index 22293bf..4e0140e 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -148,14 +148,14 @@ class Getopt ); /** - * Stores the command-line arguments for the calling applicaion. + * Stores the command-line arguments for the calling application. * * @var array */ protected $argv = array(); /** - * Stores the name of the calling applicaion. + * Stores the name of the calling application. * * @var string */ From 27cee4b134dc914cd86d098d158ed72f94bb04cc Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Wed, 8 Aug 2012 17:36:13 +0200 Subject: [PATCH 90/98] Cleanup of Console\Prompt\Select, allow Prompt\Char without text. - an extraneous newline was inserted by Select superclass Char, when there was no text. - a non-configurable prompt text has been removed from Select. - with $echo === true, Select will now display the value of option picked. --- src/Prompt/Char.php | 4 +++- src/Prompt/Select.php | 35 +++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Prompt/Char.php b/src/Prompt/Char.php index 9cef7d4..67ce8f5 100644 --- a/src/Prompt/Char.php +++ b/src/Prompt/Char.php @@ -125,7 +125,9 @@ public function show() if ($this->echo) { echo trim($char)."\n"; } else { - echo "\n"; + if ($this->promptText) { + echo "\n"; // skip to next line but only if we had any prompt text + } } break; } diff --git a/src/Prompt/Select.php b/src/Prompt/Select.php index bfdbaec..3fff3b5 100644 --- a/src/Prompt/Select.php +++ b/src/Prompt/Select.php @@ -77,28 +77,43 @@ public function __construct( */ public function show() { - /** - * Show prompt text and available options - */ + // Show prompt text and available options $console = $this->getConsole(); $console->writeLine($this->promptText); foreach ($this->options as $k => $v) { - $console->writeLine(' '.$k.') '.$v); + $console->writeLine(' ' . $k . ') ' . $v); } - /** - * Ask for selection - */ - $mask = implode("",array_keys($this->options)); + // Prepare mask + $mask = implode("", array_keys($this->options)); if ($this->allowEmpty) { $mask .= "\r\n"; } + + // Prepare other params for parent class $this->setAllowedChars($mask); - $oldPrompt = $this->promptText; - $this->promptText = 'Pick one option: '; + $oldPrompt = $this->promptText; + $oldEcho = $this->echo; + $this->echo = false; + $this->promptText = null; + + // Retrieve a single character $response = parent::show(); + + // Restore old params $this->promptText = $oldPrompt; + $this->echo = $oldEcho; + + // Display selected option if echo is enabled + if ($this->echo) { + if (isset($this->options[$response])) { + $console->writeLine($this->options[$response]); + } else { + $console->writeLine(); + } + } + $this->lastResponse = $response; return $response; } From bc46a7b2bf7d955a549a6f6b81ae1dedc1882d21 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Wed, 8 Aug 2012 17:36:45 +0200 Subject: [PATCH 91/98] Fix Adapter\Windows::readLine() should only strip trailing newline char. --- src/Adapter/Windows.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/Windows.php b/src/Adapter/Windows.php index c1eb54b..12571d1 100644 --- a/src/Adapter/Windows.php +++ b/src/Adapter/Windows.php @@ -363,7 +363,7 @@ public function readChar($mask = null) public function readLine($maxLength = 2048) { $f = fopen('php://stdin','r'); - $line = trim(fread($f,$maxLength)); + $line = rtrim(fread($f,$maxLength),"\r\n"); fclose($f); return $line; From 00ef18ac10d7b9813009f9b2ff68213abcf27f8e Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Wed, 8 Aug 2012 17:39:22 +0200 Subject: [PATCH 92/98] Fix Windows detection on PHP 5.4.5+, throw exception with autodetection fail. - PHP versions 5.4.5 and newer, on Windows, do not have COM extension compiled in. Instead it's provided as an optional, loadable extensions. This means we can not rely on this check any more. We are now detecting Windows basing on value of PHP_OS and "OS" environment variable. - Console\Console::getInstance() will now throw RuntimeException when no adapter could automatically be detected (i.e. when running on http server). --- src/Console.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Console.php b/src/Console.php index 930f251..23c4d91 100644 --- a/src/Console.php +++ b/src/Console.php @@ -34,6 +34,7 @@ abstract class Console * Zend\Console\Charset\. If not provided, charset will be detected * automatically. * @throws Exception\InvalidArgumentException + * @throws Exception\RuntimeException * @return Adapter\AdapterInterface */ public static function getInstance($forceAdapter = null, $forceCharset = null) @@ -63,6 +64,11 @@ public static function getInstance($forceAdapter = null, $forceCharset = null) } else { // Try to detect best instance for console $className = static::detectBestAdapter(); + + // Check if we were able to detect console adapter + if (!$className) { + throw new Exception\RuntimeException('Cannot create Console adapter - am I running in a console?'); + } } // Create adapter instance @@ -95,11 +101,15 @@ public static function getInstance($forceAdapter = null, $forceCharset = null) /** * Check if currently running under MS Windows * + * @see http://stackoverflow.com/questions/738823/possible-values-for-php-os * @return bool */ public static function isWindows() { - return class_exists('COM', false); + return + ( defined('PHP_OS') && ( substr_compare(PHP_OS,'win',0,3,true) === 0) ) || + substr_compare(getenv('OS'),'windows',0,7,true) + ; } /** From fa167cb7acab57357ea6f763eb6c3954db1f9246 Mon Sep 17 00:00:00 2001 From: Artur Bodera Date: Wed, 8 Aug 2012 20:18:29 +0200 Subject: [PATCH 93/98] Fix phpdocs - wrong variable names. --- src/Getopt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Getopt.php b/src/Getopt.php index 8004849..4e0140e 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -81,7 +81,7 @@ * e.g. if -b is specified, -a must be specified or else the * usage is invalid. * - * @todo Feature request to implement callables. + * @todo Feature request to implement callbacks. * e.g. if -a is specified, run function 'handleOptionA'(). */ class Getopt From ccb37b355f76e6803726500f812c103e92ffa202 Mon Sep 17 00:00:00 2001 From: RWOverdijk Date: Thu, 9 Aug 2012 09:24:56 +0200 Subject: [PATCH 94/98] Spaces added --- test/GetoptTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/GetoptTest.php b/test/GetoptTest.php index 94b786b..ecb8f26 100644 --- a/test/GetoptTest.php +++ b/test/GetoptTest.php @@ -427,7 +427,7 @@ public function testRegisterArgcArgvOffThrowsException() try { $opts = new GetOpt('abp:'); $this->fail(); - } catch(\Zend\Console\Exception\InvalidArgumentException $e) { + } catch (\Zend\Console\Exception\InvalidArgumentException $e) { $this->assertContains('$_SERVER["argv"]', $e->getMessage()); } From 1d73b092bd79be43540e869ed2a4fa211733dc8c Mon Sep 17 00:00:00 2001 From: RWOverdijk Date: Thu, 9 Aug 2012 10:05:13 +0200 Subject: [PATCH 95/98] missed spaces --- src/Adapter/AbstractAdapter.php | 2 +- src/Adapter/WindowsAnsicon.php | 2 +- src/Prompt/Number.php | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 0c77621..5612209 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -243,7 +243,7 @@ public function writeBox( $this->write(str_repeat($fillChar, $width), $fillColor, $fillBgColor); } } else { - switch ($lineStyle){ + switch ($lineStyle) { case static::LINE_DOUBLE: $lineChar = $charset::LINE_DOUBLE_NS; break; diff --git a/src/Adapter/WindowsAnsicon.php b/src/Adapter/WindowsAnsicon.php index d7f15b1..7be8e4b 100644 --- a/src/Adapter/WindowsAnsicon.php +++ b/src/Adapter/WindowsAnsicon.php @@ -237,7 +237,7 @@ public function readChar($mask = null) // Retrieve char from the result. $char = !empty($result) ? implode('', $result) : null; - if (!empty($char) && !$return){ + if (!empty($char) && !$return) { // We have obtained an ASCII code, convert back to a char ... $char = chr($char); diff --git a/src/Prompt/Number.php b/src/Prompt/Number.php index cd12f54..c154460 100644 --- a/src/Prompt/Number.php +++ b/src/Prompt/Number.php @@ -89,18 +89,18 @@ public function show() $number = parent::show(); if ($number === "" && !$this->allowEmpty) { $valid = false; - } elseif ($number === ""){ + } elseif ($number === "") { $number = null; - } elseif (!is_numeric($number)){ + } elseif (!is_numeric($number)) { $this->getConsole()->writeLine("$number is not a number\n"); $valid = false; - } elseif (!$this->allowFloat && (round($number) != $number) ){ + } elseif (!$this->allowFloat && (round($number) != $number) ) { $this->getConsole()->writeLine("Please enter a non-floating number, i.e. ".round($number)."\n"); $valid = false; - } elseif ($this->max !== null && $number > $this->max){ + } elseif ($this->max !== null && $number > $this->max) { $this->getConsole()->writeLine("Please enter a number not greater than ".$this->max."\n"); $valid = false; - } elseif ($this->min !== null && $number < $this->min){ + } elseif ($this->min !== null && $number < $this->min) { $this->getConsole()->writeLine("Please enter a number not smaller than ".$this->min."\n"); $valid = false; } From 333fff89787e95db5d29335b8b9158b3bfb34aa3 Mon Sep 17 00:00:00 2001 From: tr Date: Mon, 13 Aug 2012 18:28:12 +0100 Subject: [PATCH 96/98] fixing warning that occurs if getenv('OS') returns false on an os --- src/Console.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console.php b/src/Console.php index 23c4d91..604f91f 100644 --- a/src/Console.php +++ b/src/Console.php @@ -108,8 +108,8 @@ public static function isWindows() { return ( defined('PHP_OS') && ( substr_compare(PHP_OS,'win',0,3,true) === 0) ) || - substr_compare(getenv('OS'),'windows',0,7,true) - ; + (getenv('OS') != false && substr_compare(getenv('OS'),'windows',0,7,true)) + ; } /** From 4ab3772104837f16eca85756734c60232331d8e7 Mon Sep 17 00:00:00 2001 From: Michel Hunziker Date: Sat, 1 Sep 2012 20:40:03 +0200 Subject: [PATCH 97/98] Resolve more mismatched phpDoc --- src/Request.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Request.php b/src/Request.php index 588cd9b..feca32a 100644 --- a/src/Request.php +++ b/src/Request.php @@ -39,7 +39,8 @@ class Request extends Message implements RequestInterface /** * Create a new CLI request * - * @param array|null $args Console arguments. If not supplied, $_SERVER['argv'] will be used + * @param array|null $args Console arguments. If not supplied, $_SERVER['argv'] will be used + * @param array|null $env Environment data. If not supplied, $_ENV will be used */ public function __construct(array $args = null, array $env = null) { From 70a32b090c9c212bbc15efd40f9a71ddc7d3be44 Mon Sep 17 00:00:00 2001 From: Michel Hunziker Date: Sat, 1 Sep 2012 22:09:27 +0200 Subject: [PATCH 98/98] Add more missing @throws annotations --- src/Adapter/AbstractAdapter.php | 1 + src/Adapter/Posix.php | 3 +++ src/Getopt.php | 6 ++++-- src/Request.php | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php index 5612209..0512c15 100644 --- a/src/Adapter/AbstractAdapter.php +++ b/src/Adapter/AbstractAdapter.php @@ -136,6 +136,7 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null) * @param int $bgColor (optional) Background color * @param null|int $fillColor (optional) Foreground color of box fill * @param null|int $fillBgColor (optional) Background color of box fill + * @throws Exception\BadMethodCallException if coordinates are invalid */ public function writeBox( $x1, diff --git a/src/Adapter/Posix.php b/src/Adapter/Posix.php index a1508b4..44de626 100644 --- a/src/Adapter/Posix.php +++ b/src/Adapter/Posix.php @@ -213,6 +213,7 @@ public function setPos($x, $y) * @param string $string * @param int $color * @param null|int $bgColor + * @throws Exception\BadMethodCallException * @return string */ public function colorize($string, $color = null, $bgColor = null) @@ -248,6 +249,7 @@ public function colorize($string, $color = null, $bgColor = null) * Change current drawing color. * * @param int $color + * @throws Exception\BadMethodCallException */ public function setColor($color) { @@ -269,6 +271,7 @@ public function setColor($color) * Change current drawing background color * * @param int $bgColor + * @throws Exception\BadMethodCallException */ public function setBgColor($bgColor) { diff --git a/src/Getopt.php b/src/Getopt.php index 273fd37..5308b7f 100644 --- a/src/Getopt.php +++ b/src/Getopt.php @@ -212,6 +212,7 @@ class Getopt * @param array $rules * @param array $argv * @param array $getoptConfig + * @throws Exception\InvalidArgumentException */ public function __construct($rules, $argv = null, $getoptConfig = array()) { @@ -312,7 +313,7 @@ public function __unset($key) * These are appended to those defined when the constructor was called. * * @param array $argv - * @throws \Zend\Console\Exception\ExceptionInterface When not given an array as parameter + * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter * @return \Zend\Console\Getopt Provides a fluent interface */ public function addArguments($argv) @@ -330,7 +331,7 @@ public function addArguments($argv) * These replace any currently defined. * * @param array $argv - * @throws \Zend\Console\Exception\ExceptionInterface When not given an array as parameter + * @throws \Zend\Console\Exception\InvalidArgumentException When not given an array as parameter * @return \Zend\Console\Getopt Provides a fluent interface */ public function setArguments($argv) @@ -802,6 +803,7 @@ protected function _parseSingleOption($flag, &$argv) * or no one numeric option handlers is defined * * @param int $value + * @throws Exception\RuntimeException * @return void */ protected function _setNumericOptionValue($value) diff --git a/src/Request.php b/src/Request.php index feca32a..59c861c 100644 --- a/src/Request.php +++ b/src/Request.php @@ -41,6 +41,7 @@ class Request extends Message implements RequestInterface * * @param array|null $args Console arguments. If not supplied, $_SERVER['argv'] will be used * @param array|null $env Environment data. If not supplied, $_ENV will be used + * @throws Exception\RuntimeException */ public function __construct(array $args = null, array $env = null) {