Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,18 +2,17 @@
/**
* ConsoleOptionParser file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('TaskCollection', 'Console');
@ -27,22 +26,22 @@ App::uses('HelpFormatter', 'Console');
/**
* Handles parsing the ARGV in the command line and provides support
* for GetOpt compatible option definition. Provides a builder pattern implementation
* for GetOpt compatible option definition. Provides a builder pattern implementation
* for creating shell option parsers.
*
* ### Options
*
* Named arguments come in two forms, long and short. Long arguments are preceded
* by two - and give a more verbose option name. i.e. `--version`. Short arguments are
* preceded by one - and are only one character long. They usually match with a long option,
* preceded by one - and are only one character long. They usually match with a long option,
* and provide a more terse alternative.
*
* ### Using Options
*
* Options can be defined with both long and short forms. By using `$parser->addOption()`
* you can define new options. The name of the option is used as its long form, and you
* Options can be defined with both long and short forms. By using `$parser->addOption()`
* you can define new options. The name of the option is used as its long form, and you
* can supply an additional short form, with the `short` option. Short options should
* only be one letter long. Using more than one letter for a short option will raise an exception.
* only be one letter long. Using more than one letter for a short option will raise an exception.
*
* Calling options can be done using syntax similar to most *nix command line tools. Long options
* cane either include an `=` or leave it out.
@ -53,8 +52,8 @@ App::uses('HelpFormatter', 'Console');
*
* `cake myshell command -cn`
*
* Short options can be combined into groups as seen above. Each letter in a group
* will be treated as a separate option. The previous example is equivalent to:
* Short options can be combined into groups as seen above. Each letter in a group
* will be treated as a separate option. The previous example is equivalent to:
*
* `cake myshell command -c -n`
*
@ -64,8 +63,8 @@ App::uses('HelpFormatter', 'Console');
*
* ### Positional arguments
*
* If no positional arguments are defined, all of them will be parsed. If you define positional
* arguments any arguments greater than those defined will cause exceptions. Additionally you can
* If no positional arguments are defined, all of them will be parsed. If you define positional
* arguments any arguments greater than those defined will cause exceptions. Additionally you can
* declare arguments as optional, by setting the required param to false.
*
* `$parser->addArgument('model', array('required' => false));`
@ -73,7 +72,7 @@ App::uses('HelpFormatter', 'Console');
* ### Providing Help text
*
* By providing help text for your positional arguments and named arguments, the ConsoleOptionParser
* can generate a help display for you. You can view the help for shells by using the `--help` or `-h` switch.
* can generate a help display for you. You can view the help for shells by using the `--help` or `-h` switch.
*
* @package Cake.Console
*/
@ -136,8 +135,8 @@ class ConsoleOptionParser {
/**
* Construct an OptionParser so you can define its behavior
*
* @param string $command The command name this parser is for. The command name is used for generating help.
* @param boolean $defaultOptions Whether you want the verbose and quiet options set. Setting
* @param string $command The command name this parser is for. The command name is used for generating help.
* @param bool $defaultOptions Whether you want the verbose and quiet options set. Setting
* this to false will prevent the addition of `--verbose` & `--quiet` options.
*/
public function __construct($command = null, $defaultOptions = true) {
@ -165,8 +164,8 @@ class ConsoleOptionParser {
/**
* Static factory method for creating new OptionParsers so you can chain methods off of them.
*
* @param string $command The command name this parser is for. The command name is used for generating help.
* @param boolean $defaultOptions Whether you want the verbose and quiet options set.
* @param string $command The command name this parser is for. The command name is used for generating help.
* @param bool $defaultOptions Whether you want the verbose and quiet options set.
* @return ConsoleOptionParser
*/
public static function create($command, $defaultOptions = true) {
@ -176,7 +175,7 @@ class ConsoleOptionParser {
/**
* Build a parser from an array. Uses an array like
*
* {{{
* ```
* $spec = array(
* 'description' => 'text',
* 'epilog' => 'text',
@ -190,7 +189,7 @@ class ConsoleOptionParser {
* // list of subcommands to add.
* )
* );
* }}}
* ```
*
* @param array $spec The spec to build the OptionParser with.
* @return ConsoleOptionParser
@ -219,7 +218,7 @@ class ConsoleOptionParser {
* Get or set the command name for shell/task.
*
* @param string $text The text to set, or null if you want to read
* @return mixed If reading, the value of the command. If setting $this will be returned
* @return string|self If reading, the value of the command. If setting $this will be returned.
*/
public function command($text = null) {
if ($text !== null) {
@ -234,7 +233,7 @@ class ConsoleOptionParser {
*
* @param string|array $text The text to set, or null if you want to read. If an array the
* text will be imploded with "\n"
* @return mixed If reading, the value of the description. If setting $this will be returned
* @return string|self If reading, the value of the description. If setting $this will be returned.
*/
public function description($text = null) {
if ($text !== null) {
@ -248,11 +247,11 @@ class ConsoleOptionParser {
}
/**
* Get or set an epilog to the parser. The epilog is added to the end of
* Get or set an epilog to the parser. The epilog is added to the end of
* the options and arguments listing when help is generated.
*
* @param string|array $text Text when setting or null when reading. If an array the text will be imploded with "\n"
* @return mixed If reading, the value of the epilog. If setting $this will be returned.
* @return string|self If reading, the value of the epilog. If setting $this will be returned.
*/
public function epilog($text = null) {
if ($text !== null) {
@ -272,20 +271,20 @@ class ConsoleOptionParser {
* ### Options
*
* - `short` - The single letter variant for this option, leave undefined for none.
* - `help` - Help text for this option. Used when generating help for the option.
* - `help` - Help text for this option. Used when generating help for the option.
* - `default` - The default value for this option. Defaults are added into the parsed params when the
* attached option is not provided or has no value. Using default and boolean together will not work.
* attached option is not provided or has no value. Using default and boolean together will not work.
* are added into the parsed parameters when the option is undefined. Defaults to null.
* - `boolean` - The option uses no value, its just a boolean switch. Defaults to false.
* If an option is defined as boolean, it will always be added to the parsed params. If no present
* If an option is defined as boolean, it will always be added to the parsed params. If no present
* it will be false, if present it will be true.
* - `choices` A list of valid choices for this option. If left empty all values are valid..
* - `choices` A list of valid choices for this option. If left empty all values are valid..
* An exception will be raised when parse() encounters an invalid value.
*
* @param ConsoleInputOption|string $name The long name you want to the value to be parsed out as when options are parsed.
* Will also accept an instance of ConsoleInputOption
* @param array $options An array of parameters that define the behavior of the option
* @return ConsoleOptionParser $this.
* @return self
*/
public function addOption($name, $options = array()) {
if (is_object($name) && $name instanceof ConsoleInputOption) {
@ -300,7 +299,7 @@ class ConsoleOptionParser {
'boolean' => false,
'choices' => array()
);
$options = array_merge($defaults, $options);
$options += $defaults;
$option = new ConsoleInputOption($options);
}
$this->_options[$name] = $option;
@ -320,12 +319,12 @@ class ConsoleOptionParser {
* - `index` The index for the arg, if left undefined the argument will be put
* onto the end of the arguments. If you define the same index twice the first
* option will be overwritten.
* - `choices` A list of valid choices for this argument. If left empty all values are valid..
* - `choices` A list of valid choices for this argument. If left empty all values are valid..
* An exception will be raised when parse() encounters an invalid value.
*
* @param ConsoleInputArgument|string $name The name of the argument. Will also accept an instance of ConsoleInputArgument
* @param ConsoleInputArgument|string $name The name of the argument. Will also accept an instance of ConsoleInputArgument
* @param array $params Parameters for the argument, see above.
* @return ConsoleOptionParser $this.
* @return self
*/
public function addArgument($name, $params = array()) {
if (is_object($name) && $name instanceof ConsoleInputArgument) {
@ -339,7 +338,7 @@ class ConsoleOptionParser {
'required' => false,
'choices' => array()
);
$options = array_merge($defaults, $params);
$options = $params + $defaults;
$index = $options['index'];
unset($options['index']);
$arg = new ConsoleInputArgument($options);
@ -355,7 +354,7 @@ class ConsoleOptionParser {
*
* @param array $args Array of arguments to add.
* @see ConsoleOptionParser::addArgument()
* @return ConsoleOptionParser $this
* @return self
*/
public function addArguments(array $args) {
foreach ($args as $name => $params) {
@ -370,7 +369,7 @@ class ConsoleOptionParser {
*
* @param array $options Array of options to add.
* @see ConsoleOptionParser::addOption()
* @return ConsoleOptionParser $this
* @return self
*/
public function addOptions(array $options) {
foreach ($options as $name => $params) {
@ -386,13 +385,13 @@ class ConsoleOptionParser {
* ### Options
*
* - `help` - Help text for the subcommand.
* - `parser` - A ConsoleOptionParser for the subcommand. This allows you to create method
* specific option parsers. When help is generated for a subcommand, if a parser is present
* - `parser` - A ConsoleOptionParser for the subcommand. This allows you to create method
* specific option parsers. When help is generated for a subcommand, if a parser is present
* it will be used.
*
* @param ConsoleInputSubcommand|string $name Name of the subcommand. Will also accept an instance of ConsoleInputSubcommand
* @param array $options Array of params, see above.
* @return ConsoleOptionParser $this.
* @return self
*/
public function addSubcommand($name, $options = array()) {
if (is_object($name) && $name instanceof ConsoleInputSubcommand) {
@ -404,18 +403,29 @@ class ConsoleOptionParser {
'help' => '',
'parser' => null
);
$options = array_merge($defaults, $options);
$options += $defaults;
$command = new ConsoleInputSubcommand($options);
}
$this->_subcommands[$name] = $command;
return $this;
}
/**
* Remove a subcommand from the option parser.
*
* @param string $name The subcommand name to remove.
* @return self
*/
public function removeSubcommand($name) {
unset($this->_subcommands[$name]);
return $this;
}
/**
* Add multiple subcommands at once.
*
* @param array $commands Array of subcommands.
* @return ConsoleOptionParser $this
* @return self
*/
public function addSubcommands(array $commands) {
foreach ($commands as $name => $params) {
@ -452,14 +462,14 @@ class ConsoleOptionParser {
}
/**
* Parse the argv array into a set of params and args. If $command is not null
* Parse the argv array into a set of params and args. If $command is not null
* and $command is equal to a subcommand that has a parser, that parser will be used
* to parse the $argv
*
* @param array $argv Array of args (argv) to parse.
* @param string $command The subcommand to use. If this parameter is a subcommand, that has a parser,
* @param string $command The subcommand to use. If this parameter is a subcommand, that has a parser,
* That parser will be used to parse $argv instead.
* @return Array array($params, $args)
* @return array array($params, $args)
* @throws ConsoleException When an invalid parameter is encountered.
*/
public function parse($argv, $command = null) {
@ -469,9 +479,9 @@ class ConsoleOptionParser {
$params = $args = array();
$this->_tokens = $argv;
while (($token = array_shift($this->_tokens)) !== null) {
if (substr($token, 0, 2) == '--') {
if (substr($token, 0, 2) === '--') {
$params = $this->_parseLongOption($token, $params);
} elseif (substr($token, 0, 1) == '-') {
} elseif (substr($token, 0, 1) === '-') {
$params = $this->_parseShortOption($token, $params);
} else {
$args = $this->_parseArg($token, $args);
@ -507,12 +517,11 @@ class ConsoleOptionParser {
* @param string $subcommand If present and a valid subcommand that has a linked parser.
* That subcommands help will be shown instead.
* @param string $format Define the output format, can be text or xml
* @param integer $width The width to format user content to. Defaults to 72
* @param int $width The width to format user content to. Defaults to 72
* @return string Generated help.
*/
public function help($subcommand = null, $format = 'text', $width = 72) {
if (
isset($this->_subcommands[$subcommand]) &&
if (isset($this->_subcommands[$subcommand]) &&
$this->_subcommands[$subcommand]->parser() instanceof self
) {
$subparser = $this->_subcommands[$subcommand]->parser();
@ -520,15 +529,15 @@ class ConsoleOptionParser {
return $subparser->help(null, $format, $width);
}
$formatter = new HelpFormatter($this);
if ($format == 'text' || $format === true) {
if ($format === 'text' || $format === true) {
return $formatter->text($width);
} elseif ($format == 'xml') {
} elseif ($format === 'xml') {
return $formatter->xml();
}
}
/**
* Parse the value for a long option out of $this->_tokens. Will handle
* Parse the value for a long option out of $this->_tokens. Will handle
* options with an `=` in them.
*
* @param string $option The option to parse.
@ -598,13 +607,14 @@ class ConsoleOptionParser {
$params[$name] = $value;
return $params;
}
return array();
}
/**
* Check to see if $name has an option (short/long) defined for it.
*
* @param string $name The name of the option.
* @return boolean
* @return bool
*/
protected function _optionExists($name) {
if (substr($name, 0, 2) === '--') {