initial commit
This commit is contained in:
1089
core/vendor/symfony/console/Symfony/Component/Console/Application.php
vendored
Normal file
1089
core/vendor/symfony/console/Symfony/Component/Console/Application.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
19
core/vendor/symfony/console/Symfony/Component/Console/CHANGELOG.md
vendored
Normal file
19
core/vendor/symfony/console/Symfony/Component/Console/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
|
||||
* added ConsoleOutputInterface
|
||||
* added the possibility to disable a command (Command::isEnabled())
|
||||
* added suggestions when a command does not exist
|
||||
* added a --raw option to the list command
|
||||
* added support for STDERR in the console output class (errors are now sent
|
||||
to STDERR)
|
||||
* made the defaults (helper set, commands, input definition) in Application
|
||||
more easily customizable
|
||||
* added support for the shell even if readline is not available
|
||||
* added support for process isolation in Symfony shell via
|
||||
`--process-isolation` switch
|
||||
* added support for `--`, which disables options parsing after that point
|
||||
(tokens will be parsed as arguments)
|
||||
614
core/vendor/symfony/console/Symfony/Component/Console/Command/Command.php
vendored
Normal file
614
core/vendor/symfony/console/Symfony/Component/Console/Command/Command.php
vendored
Normal file
@@ -0,0 +1,614 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
/**
|
||||
* Base class for all commands.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
private $application;
|
||||
private $name;
|
||||
private $aliases;
|
||||
private $definition;
|
||||
private $help;
|
||||
private $description;
|
||||
private $ignoreValidationErrors;
|
||||
private $applicationDefinitionMerged;
|
||||
private $code;
|
||||
private $synopsis;
|
||||
private $helperSet;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the command
|
||||
*
|
||||
* @throws \LogicException When the command name is empty
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->definition = new InputDefinition();
|
||||
$this->ignoreValidationErrors = false;
|
||||
$this->applicationDefinitionMerged = false;
|
||||
$this->aliases = array();
|
||||
|
||||
if (null !== $name) {
|
||||
$this->setName($name);
|
||||
}
|
||||
|
||||
$this->configure();
|
||||
|
||||
if (!$this->name) {
|
||||
throw new \LogicException('The command name cannot be empty.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores validation errors.
|
||||
*
|
||||
* This is mainly useful for the help command.
|
||||
*/
|
||||
public function ignoreValidationErrors()
|
||||
{
|
||||
$this->ignoreValidationErrors = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application instance for this command.
|
||||
*
|
||||
* @param Application $application An Application instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setApplication(Application $application = null)
|
||||
{
|
||||
$this->application = $application;
|
||||
if ($application) {
|
||||
$this->setHelperSet($application->getHelperSet());
|
||||
} else {
|
||||
$this->helperSet = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the helper set.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the helper set.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
return $this->helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the application instance for this command.
|
||||
*
|
||||
* @return Application An Application instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getApplication()
|
||||
{
|
||||
return $this->application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the command is enabled or not in the current environment
|
||||
*
|
||||
* Override this to check for x or y and return false if the command can not
|
||||
* run properly under the current conditions.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the current command.
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the current command.
|
||||
*
|
||||
* This method is not abstract because you can use this class
|
||||
* as a concrete class. In this case, instead of defining the
|
||||
* execute() method, you set the code to execute by passing
|
||||
* a Closure to the setCode() method.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*
|
||||
* @return integer 0 if everything went fine, or an error code
|
||||
*
|
||||
* @throws \LogicException When this abstract method is not implemented
|
||||
* @see setCode()
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
throw new \LogicException('You must override the execute() method in the concrete command class.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Interacts with the user.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
protected function interact(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the command just after the input has been validated.
|
||||
*
|
||||
* This is mainly useful when a lot of commands extends one main command
|
||||
* where some things need to be initialized based on the input arguments and options.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*/
|
||||
protected function initialize(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the command.
|
||||
*
|
||||
* The code to execute is either defined directly with the
|
||||
* setCode() method or by overriding the execute() method
|
||||
* in a sub-class.
|
||||
*
|
||||
* @param InputInterface $input An InputInterface instance
|
||||
* @param OutputInterface $output An OutputInterface instance
|
||||
*
|
||||
* @return integer The command exit code
|
||||
*
|
||||
* @see setCode()
|
||||
* @see execute()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function run(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// force the creation of the synopsis before the merge with the app definition
|
||||
$this->getSynopsis();
|
||||
|
||||
// add the application arguments and options
|
||||
$this->mergeApplicationDefinition();
|
||||
|
||||
// bind the input against the command specific arguments/options
|
||||
try {
|
||||
$input->bind($this->definition);
|
||||
} catch (\Exception $e) {
|
||||
if (!$this->ignoreValidationErrors) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$this->initialize($input, $output);
|
||||
|
||||
if ($input->isInteractive()) {
|
||||
$this->interact($input, $output);
|
||||
}
|
||||
|
||||
$input->validate();
|
||||
|
||||
if ($this->code) {
|
||||
return call_user_func($this->code, $input, $output);
|
||||
}
|
||||
|
||||
return $this->execute($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the code to execute when running this command.
|
||||
*
|
||||
* If this method is used, it overrides the code defined
|
||||
* in the execute() method.
|
||||
*
|
||||
* @param \Closure $code A \Closure
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @see execute()
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setCode(\Closure $code)
|
||||
{
|
||||
$this->code = $code;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the application definition with the command definition.
|
||||
*/
|
||||
private function mergeApplicationDefinition()
|
||||
{
|
||||
if (null === $this->application || true === $this->applicationDefinitionMerged) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentArguments = $this->definition->getArguments();
|
||||
$this->definition->setArguments($this->application->getDefinition()->getArguments());
|
||||
$this->definition->addArguments($currentArguments);
|
||||
|
||||
$this->definition->addOptions($this->application->getDefinition()->getOptions());
|
||||
|
||||
$this->applicationDefinitionMerged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an array of argument and option instances.
|
||||
*
|
||||
* @param array|InputDefinition $definition An array of argument and option instances or a definition instance
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDefinition($definition)
|
||||
{
|
||||
if ($definition instanceof InputDefinition) {
|
||||
$this->definition = $definition;
|
||||
} else {
|
||||
$this->definition->setDefinition($definition);
|
||||
}
|
||||
|
||||
$this->applicationDefinitionMerged = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the InputDefinition attached to this Command.
|
||||
*
|
||||
* @return InputDefinition An InputDefinition instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the InputDefinition to be used to create XML and Text representations of this Command.
|
||||
*
|
||||
* Can be overridden to provide the original command representation when it would otherwise
|
||||
* be changed by merging with the application InputDefinition.
|
||||
*
|
||||
* @return InputDefinition An InputDefinition instance
|
||||
*/
|
||||
protected function getNativeDefinition()
|
||||
{
|
||||
return $this->getDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an argument.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param integer $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (for InputArgument::OPTIONAL mode only)
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addArgument($name, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an option.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $shortcut The shortcut (can be null)
|
||||
* @param integer $mode The option mode: One of the InputOption::VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the command.
|
||||
*
|
||||
* This method can set both the namespace and the name if
|
||||
* you separate them by a colon (:)
|
||||
*
|
||||
* $command->setName('foo:bar');
|
||||
*
|
||||
* @param string $name The command name
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When command name given is empty
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->validateName($name);
|
||||
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command name.
|
||||
*
|
||||
* @return string The command name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description for the command.
|
||||
*
|
||||
* @param string $description The description for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description for the command.
|
||||
*
|
||||
* @return string The description for the command
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the help for the command.
|
||||
*
|
||||
* @param string $help The help for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setHelp($help)
|
||||
{
|
||||
$this->help = $help;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the help for the command.
|
||||
*
|
||||
* @return string The help for the command
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getHelp()
|
||||
{
|
||||
return $this->help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the processed help for the command replacing the %command.name% and
|
||||
* %command.full_name% patterns with the real values dynamically.
|
||||
*
|
||||
* @return string The processed help for the command
|
||||
*/
|
||||
public function getProcessedHelp()
|
||||
{
|
||||
$name = $this->name;
|
||||
|
||||
$placeholders = array(
|
||||
'%command.name%',
|
||||
'%command.full_name%'
|
||||
);
|
||||
$replacements = array(
|
||||
$name,
|
||||
$_SERVER['PHP_SELF'].' '.$name
|
||||
);
|
||||
|
||||
return str_replace($placeholders, $replacements, $this->getHelp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the aliases for the command.
|
||||
*
|
||||
* @param array $aliases An array of aliases for the command
|
||||
*
|
||||
* @return Command The current instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setAliases($aliases)
|
||||
{
|
||||
foreach ($aliases as $alias) {
|
||||
$this->validateName($alias);
|
||||
}
|
||||
|
||||
$this->aliases = $aliases;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the aliases for the command.
|
||||
*
|
||||
* @return array An array of aliases for the command
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the synopsis for the command.
|
||||
*
|
||||
* @return string The synopsis
|
||||
*/
|
||||
public function getSynopsis()
|
||||
{
|
||||
if (null === $this->synopsis) {
|
||||
$this->synopsis = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis()));
|
||||
}
|
||||
|
||||
return $this->synopsis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a helper instance by name.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return mixed The helper value
|
||||
*
|
||||
* @throws \InvalidArgumentException if the helper is not defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getHelper($name)
|
||||
{
|
||||
return $this->helperSet->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a text representation of the command.
|
||||
*
|
||||
* @return string A string representing the command
|
||||
*/
|
||||
public function asText()
|
||||
{
|
||||
$messages = array(
|
||||
'<comment>Usage:</comment>',
|
||||
' '.$this->getSynopsis(),
|
||||
'',
|
||||
);
|
||||
|
||||
if ($this->getAliases()) {
|
||||
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $this->getAliases()).'</info>';
|
||||
}
|
||||
|
||||
$messages[] = $this->getNativeDefinition()->asText();
|
||||
|
||||
if ($help = $this->getProcessedHelp()) {
|
||||
$messages[] = '<comment>Help:</comment>';
|
||||
$messages[] = ' '.str_replace("\n", "\n ", $help)."\n";
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML representation of the command.
|
||||
*
|
||||
* @param Boolean $asDom Whether to return a DOM or an XML string
|
||||
*
|
||||
* @return string|DOMDocument An XML string representing the command
|
||||
*/
|
||||
public function asXml($asDom = false)
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = true;
|
||||
$dom->appendChild($commandXML = $dom->createElement('command'));
|
||||
$commandXML->setAttribute('id', $this->name);
|
||||
$commandXML->setAttribute('name', $this->name);
|
||||
|
||||
$commandXML->appendChild($usageXML = $dom->createElement('usage'));
|
||||
$usageXML->appendChild($dom->createTextNode(sprintf($this->getSynopsis(), '')));
|
||||
|
||||
$commandXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getDescription())));
|
||||
|
||||
$commandXML->appendChild($helpXML = $dom->createElement('help'));
|
||||
$helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $this->getProcessedHelp())));
|
||||
|
||||
$commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
|
||||
foreach ($this->getAliases() as $alias) {
|
||||
$aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
|
||||
$aliasXML->appendChild($dom->createTextNode($alias));
|
||||
}
|
||||
|
||||
$definition = $this->getNativeDefinition()->asXml(true);
|
||||
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true));
|
||||
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true));
|
||||
|
||||
return $asDom ? $dom : $dom->saveXml();
|
||||
}
|
||||
|
||||
private function validateName($name)
|
||||
{
|
||||
if (!preg_match('/^[^\:]+(\:[^\:]+)*$/', $name)) {
|
||||
throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
|
||||
}
|
||||
}
|
||||
}
|
||||
84
core/vendor/symfony/console/Symfony/Component/Console/Command/HelpCommand.php
vendored
Normal file
84
core/vendor/symfony/console/Symfony/Component/Console/Command/HelpCommand.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/**
|
||||
* HelpCommand displays the help for a given command.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class HelpCommand extends Command
|
||||
{
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->ignoreValidationErrors();
|
||||
|
||||
$this
|
||||
->setName('help')
|
||||
->setDefinition(array(
|
||||
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
|
||||
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
|
||||
))
|
||||
->setDescription('Displays help for a command')
|
||||
->setHelp(<<<EOF
|
||||
The <info>%command.name%</info> command displays help for a given command:
|
||||
|
||||
<info>php %command.full_name% list</info>
|
||||
|
||||
You can also output the help as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php %command.full_name% --xml list</info>
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command
|
||||
*
|
||||
* @param Command $command The command to set
|
||||
*/
|
||||
public function setCommand(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (null === $this->command) {
|
||||
$this->command = $this->getApplication()->get($input->getArgument('command_name'));
|
||||
}
|
||||
|
||||
if ($input->getOption('xml')) {
|
||||
$output->writeln($this->command->asXml(), OutputInterface::OUTPUT_RAW);
|
||||
} else {
|
||||
$output->writeln($this->command->asText());
|
||||
}
|
||||
|
||||
$this->command = null;
|
||||
}
|
||||
}
|
||||
87
core/vendor/symfony/console/Symfony/Component/Console/Command/ListCommand.php
vendored
Normal file
87
core/vendor/symfony/console/Symfony/Component/Console/Command/ListCommand.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
|
||||
/**
|
||||
* ListCommand displays the list of all available commands for the application.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ListCommand extends Command
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('list')
|
||||
->setDefinition($this->createDefinition())
|
||||
->setDescription('Lists commands')
|
||||
->setHelp(<<<EOF
|
||||
The <info>%command.name%</info> command lists all commands:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
You can also display the commands for a specific namespace:
|
||||
|
||||
<info>php %command.full_name% test</info>
|
||||
|
||||
You can also output the information as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php %command.full_name% --xml</info>
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
<info>php %command.full_name% --raw</info>
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNativeDefinition()
|
||||
{
|
||||
return $this->createDefinition();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ($input->getOption('xml')) {
|
||||
$output->writeln($this->getApplication()->asXml($input->getArgument('namespace')), OutputInterface::OUTPUT_RAW);
|
||||
} else {
|
||||
$output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw')));
|
||||
}
|
||||
}
|
||||
|
||||
private function createDefinition()
|
||||
{
|
||||
return new InputDefinition(array(
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
|
||||
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
|
||||
));
|
||||
}
|
||||
}
|
||||
248
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatter.php
vendored
Normal file
248
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatter.php
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Formatter;
|
||||
|
||||
/**
|
||||
* Formatter class for console output.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class OutputFormatter implements OutputFormatterInterface
|
||||
{
|
||||
/**
|
||||
* The pattern to phrase the format.
|
||||
*/
|
||||
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?:(?!\\\\?<).)*)#is';
|
||||
|
||||
private $decorated;
|
||||
private $styles = array();
|
||||
private $styleStack;
|
||||
|
||||
/**
|
||||
* Escapes "<" special char in given text.
|
||||
*
|
||||
* @param string $text Text to escape
|
||||
*
|
||||
* @return string Escaped text
|
||||
*/
|
||||
public static function escape($text)
|
||||
{
|
||||
return preg_replace('/([^\\\\]?)</is', '$1\\<', $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes console output formatter.
|
||||
*
|
||||
* @param Boolean $decorated Whether this formatter should actually decorate strings
|
||||
* @param array $styles Array of "name => FormatterStyle" instances
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($decorated = null, array $styles = array())
|
||||
{
|
||||
$this->decorated = (Boolean) $decorated;
|
||||
|
||||
$this->setStyle('error', new OutputFormatterStyle('white', 'red'));
|
||||
$this->setStyle('info', new OutputFormatterStyle('green'));
|
||||
$this->setStyle('comment', new OutputFormatterStyle('yellow'));
|
||||
$this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));
|
||||
|
||||
foreach ($styles as $name => $style) {
|
||||
$this->setStyle($name, $style);
|
||||
}
|
||||
|
||||
$this->styleStack = new OutputFormatterStyleStack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorate the messages or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDecorated($decorated)
|
||||
{
|
||||
$this->decorated = (Boolean) $decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the decorated flag.
|
||||
*
|
||||
* @return Boolean true if the output will decorate messages, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isDecorated()
|
||||
{
|
||||
return $this->decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new style.
|
||||
*
|
||||
* @param string $name The style name
|
||||
* @param OutputFormatterStyleInterface $style The style instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setStyle($name, OutputFormatterStyleInterface $style)
|
||||
{
|
||||
$this->styles[strtolower($name)] = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if output formatter has style with specified name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasStyle($name)
|
||||
{
|
||||
return isset($this->styles[strtolower($name)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets style options from style with specified name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return OutputFormatterStyleInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException When style isn't defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getStyle($name)
|
||||
{
|
||||
if (!$this->hasStyle($name)) {
|
||||
throw new \InvalidArgumentException('Undefined style: '.$name);
|
||||
}
|
||||
|
||||
return $this->styles[strtolower($name)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a message according to the given styles.
|
||||
*
|
||||
* @param string $message The message to style
|
||||
*
|
||||
* @return string The styled message
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function format($message)
|
||||
{
|
||||
$message = preg_replace_callback(self::FORMAT_PATTERN, array($this, 'replaceStyle'), $message);
|
||||
|
||||
return str_replace('\\<', '<', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OutputFormatterStyleStack
|
||||
*/
|
||||
public function getStyleStack()
|
||||
{
|
||||
return $this->styleStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces style of the output.
|
||||
*
|
||||
* @param array $match
|
||||
*
|
||||
* @return string The replaced style
|
||||
*/
|
||||
private function replaceStyle($match)
|
||||
{
|
||||
// we got "\<" escaped char
|
||||
if ('\\' === $match[1]) {
|
||||
return $this->applyCurrentStyle($match[0]);
|
||||
}
|
||||
|
||||
if ('' === $match[3]) {
|
||||
if ('/' === $match[2]) {
|
||||
// we got "</>" tag
|
||||
$this->styleStack->pop();
|
||||
|
||||
return $this->applyCurrentStyle($match[4]);
|
||||
}
|
||||
|
||||
// we got "<>" tag
|
||||
return '<>'.$this->applyCurrentStyle($match[4]);
|
||||
}
|
||||
|
||||
if (isset($this->styles[strtolower($match[3])])) {
|
||||
$style = $this->styles[strtolower($match[3])];
|
||||
} else {
|
||||
$style = $this->createStyleFromString($match[3]);
|
||||
|
||||
if (false === $style) {
|
||||
return $this->applyCurrentStyle($match[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if ('/' === $match[2]) {
|
||||
$this->styleStack->pop($style);
|
||||
} else {
|
||||
$this->styleStack->push($style);
|
||||
}
|
||||
|
||||
return $this->applyCurrentStyle($match[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to create new style instance from string.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return OutputFormatterStyle|Boolean false if string is not format string
|
||||
*/
|
||||
private function createStyleFromString($string)
|
||||
{
|
||||
if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$style = new OutputFormatterStyle();
|
||||
foreach ($matches as $match) {
|
||||
array_shift($match);
|
||||
|
||||
if ('fg' == $match[0]) {
|
||||
$style->setForeground($match[1]);
|
||||
} elseif ('bg' == $match[0]) {
|
||||
$style->setBackground($match[1]);
|
||||
} else {
|
||||
$style->setOption($match[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies current style from stack to text, if must be applied.
|
||||
*
|
||||
* @param string $text Input text
|
||||
*
|
||||
* @return string string Styled text
|
||||
*/
|
||||
private function applyCurrentStyle($text)
|
||||
{
|
||||
return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
|
||||
}
|
||||
}
|
||||
83
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterInterface.php
vendored
Normal file
83
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterInterface.php
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Formatter;
|
||||
|
||||
/**
|
||||
* Formatter interface for console output.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface OutputFormatterInterface
|
||||
{
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorate the messages or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDecorated($decorated);
|
||||
|
||||
/**
|
||||
* Gets the decorated flag.
|
||||
*
|
||||
* @return Boolean true if the output will decorate messages, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isDecorated();
|
||||
|
||||
/**
|
||||
* Sets a new style.
|
||||
*
|
||||
* @param string $name The style name
|
||||
* @param OutputFormatterStyleInterface $style The style instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setStyle($name, OutputFormatterStyleInterface $style);
|
||||
|
||||
/**
|
||||
* Checks if output formatter has style with specified name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasStyle($name);
|
||||
|
||||
/**
|
||||
* Gets style options from style with specified name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return OutputFormatterStyleInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getStyle($name);
|
||||
|
||||
/**
|
||||
* Formats a message according to the given styles.
|
||||
*
|
||||
* @param string $message The message to style
|
||||
*
|
||||
* @return string The styled message
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function format($message);
|
||||
}
|
||||
222
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyle.php
vendored
Normal file
222
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyle.php
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Formatter;
|
||||
|
||||
/**
|
||||
* Formatter style class for defining styles.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class OutputFormatterStyle implements OutputFormatterStyleInterface
|
||||
{
|
||||
private static $availableForegroundColors = array(
|
||||
'black' => 30,
|
||||
'red' => 31,
|
||||
'green' => 32,
|
||||
'yellow' => 33,
|
||||
'blue' => 34,
|
||||
'magenta' => 35,
|
||||
'cyan' => 36,
|
||||
'white' => 37
|
||||
);
|
||||
private static $availableBackgroundColors = array(
|
||||
'black' => 40,
|
||||
'red' => 41,
|
||||
'green' => 42,
|
||||
'yellow' => 43,
|
||||
'blue' => 44,
|
||||
'magenta' => 45,
|
||||
'cyan' => 46,
|
||||
'white' => 47
|
||||
);
|
||||
private static $availableOptions = array(
|
||||
'bold' => 1,
|
||||
'underscore' => 4,
|
||||
'blink' => 5,
|
||||
'reverse' => 7,
|
||||
'conceal' => 8
|
||||
);
|
||||
|
||||
private $foreground;
|
||||
private $background;
|
||||
private $options = array();
|
||||
|
||||
/**
|
||||
* Initializes output formatter style.
|
||||
*
|
||||
* @param string $foreground The style foreground color name
|
||||
* @param string $background The style background color name
|
||||
* @param array $options The style options
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($foreground = null, $background = null, array $options = array())
|
||||
{
|
||||
if (null !== $foreground) {
|
||||
$this->setForeground($foreground);
|
||||
}
|
||||
if (null !== $background) {
|
||||
$this->setBackground($background);
|
||||
}
|
||||
if (count($options)) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets style foreground color.
|
||||
*
|
||||
* @param string $color The color name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the color name isn't defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setForeground($color = null)
|
||||
{
|
||||
if (null === $color) {
|
||||
$this->foreground = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset(static::$availableForegroundColors[$color])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Invalid foreground color specified: "%s". Expected one of (%s)',
|
||||
$color,
|
||||
implode(', ', array_keys(static::$availableForegroundColors))
|
||||
));
|
||||
}
|
||||
|
||||
$this->foreground = static::$availableForegroundColors[$color];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets style background color.
|
||||
*
|
||||
* @param string $color The color name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the color name isn't defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setBackground($color = null)
|
||||
{
|
||||
if (null === $color) {
|
||||
$this->background = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset(static::$availableBackgroundColors[$color])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Invalid background color specified: "%s". Expected one of (%s)',
|
||||
$color,
|
||||
implode(', ', array_keys(static::$availableBackgroundColors))
|
||||
));
|
||||
}
|
||||
|
||||
$this->background = static::$availableBackgroundColors[$color];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets some specific style option.
|
||||
*
|
||||
* @param string $option The option name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the option name isn't defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setOption($option)
|
||||
{
|
||||
if (!isset(static::$availableOptions[$option])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Invalid option specified: "%s". Expected one of (%s)',
|
||||
$option,
|
||||
implode(', ', array_keys(static::$availableOptions))
|
||||
));
|
||||
}
|
||||
|
||||
if (false === array_search(static::$availableOptions[$option], $this->options)) {
|
||||
$this->options[] = static::$availableOptions[$option];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets some specific style option.
|
||||
*
|
||||
* @param string $option The option name
|
||||
*
|
||||
* @throws \InvalidArgumentException When the option name isn't defined
|
||||
*
|
||||
*/
|
||||
public function unsetOption($option)
|
||||
{
|
||||
if (!isset(static::$availableOptions[$option])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Invalid option specified: "%s". Expected one of (%s)',
|
||||
$option,
|
||||
implode(', ', array_keys(static::$availableOptions))
|
||||
));
|
||||
}
|
||||
|
||||
$pos = array_search(static::$availableOptions[$option], $this->options);
|
||||
if (false !== $pos) {
|
||||
unset($this->options[$pos]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets multiple style options at once.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array();
|
||||
|
||||
foreach ($options as $option) {
|
||||
$this->setOption($option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the style to a given text.
|
||||
*
|
||||
* @param string $text The text to style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function apply($text)
|
||||
{
|
||||
$codes = array();
|
||||
|
||||
if (null !== $this->foreground) {
|
||||
$codes[] = $this->foreground;
|
||||
}
|
||||
if (null !== $this->background) {
|
||||
$codes[] = $this->background;
|
||||
}
|
||||
if (count($this->options)) {
|
||||
$codes = array_merge($codes, $this->options);
|
||||
}
|
||||
|
||||
if (0 === count($codes)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
return sprintf("\033[%sm%s\033[0m", implode(';', $codes), $text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Formatter;
|
||||
|
||||
/**
|
||||
* Formatter style interface for defining styles.
|
||||
*
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface OutputFormatterStyleInterface
|
||||
{
|
||||
/**
|
||||
* Sets style foreground color.
|
||||
*
|
||||
* @param string $color The color name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setForeground($color = null);
|
||||
|
||||
/**
|
||||
* Sets style background color.
|
||||
*
|
||||
* @param string $color The color name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setBackground($color = null);
|
||||
|
||||
/**
|
||||
* Sets some specific style option.
|
||||
*
|
||||
* @param string $option The option name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setOption($option);
|
||||
|
||||
/**
|
||||
* Unsets some specific style option.
|
||||
*
|
||||
* @param string $option The option name
|
||||
*/
|
||||
public function unsetOption($option);
|
||||
|
||||
/**
|
||||
* Sets multiple style options at once.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function setOptions(array $options);
|
||||
|
||||
/**
|
||||
* Applies the style to a given text.
|
||||
*
|
||||
* @param string $text The text to style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function apply($text);
|
||||
}
|
||||
121
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php
vendored
Normal file
121
core/vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Formatter;
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
class OutputFormatterStyleStack
|
||||
{
|
||||
/**
|
||||
* @var OutputFormatterStyleInterface[]
|
||||
*/
|
||||
private $styles;
|
||||
|
||||
/**
|
||||
* @var OutputFormatterStyleInterface
|
||||
*/
|
||||
private $emptyStyle;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param OutputFormatterStyleInterface $emptyStyle
|
||||
*/
|
||||
public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
|
||||
{
|
||||
$this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets stack (ie. empty internal arrays).
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->styles = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a style in the stack.
|
||||
*
|
||||
* @param OutputFormatterStyleInterface $style
|
||||
*/
|
||||
public function push(OutputFormatterStyleInterface $style)
|
||||
{
|
||||
$this->styles[] = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops a style from the stack.
|
||||
*
|
||||
* @param OutputFormatterStyleInterface $style
|
||||
*
|
||||
* @return OutputFormatterStyleInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException When style tags incorrectly nested
|
||||
*/
|
||||
public function pop(OutputFormatterStyleInterface $style = null)
|
||||
{
|
||||
if (empty($this->styles)) {
|
||||
return $this->emptyStyle;
|
||||
}
|
||||
|
||||
if (null === $style) {
|
||||
return array_pop($this->styles);
|
||||
}
|
||||
|
||||
foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
|
||||
if ($style->apply('') === $stackedStyle->apply('')) {
|
||||
$this->styles = array_slice($this->styles, 0, $index);
|
||||
|
||||
return $stackedStyle;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Incorrectly nested style tag found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes current style with stacks top codes.
|
||||
*
|
||||
* @return OutputFormatterStyle
|
||||
*/
|
||||
public function getCurrent()
|
||||
{
|
||||
if (empty($this->styles)) {
|
||||
return $this->emptyStyle;
|
||||
}
|
||||
|
||||
return $this->styles[count($this->styles)-1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OutputFormatterStyleInterface $emptyStyle
|
||||
*
|
||||
* @return OutputFormatterStyleStack
|
||||
*/
|
||||
public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
|
||||
{
|
||||
$this->emptyStyle = $emptyStyle;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OutputFormatterStyleInterface
|
||||
*/
|
||||
public function getEmptyStyle()
|
||||
{
|
||||
return $this->emptyStyle;
|
||||
}
|
||||
}
|
||||
141
core/vendor/symfony/console/Symfony/Component/Console/Helper/DialogHelper.php
vendored
Normal file
141
core/vendor/symfony/console/Symfony/Component/Console/Helper/DialogHelper.php
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* The Dialog class provides helpers to interact with the user.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class DialogHelper extends Helper
|
||||
{
|
||||
private $inputStream;
|
||||
|
||||
/**
|
||||
* Asks a question to the user.
|
||||
*
|
||||
* @param OutputInterface $output An Output instance
|
||||
* @param string|array $question The question to ask
|
||||
* @param string $default The default answer if none is given by the user
|
||||
*
|
||||
* @return string The user answer
|
||||
*
|
||||
* @throws \RuntimeException If there is no data to read in the input stream
|
||||
*/
|
||||
public function ask(OutputInterface $output, $question, $default = null)
|
||||
{
|
||||
$output->write($question);
|
||||
|
||||
$ret = fgets($this->inputStream ?: STDIN, 4096);
|
||||
if (false === $ret) {
|
||||
throw new \RuntimeException('Aborted');
|
||||
}
|
||||
$ret = trim($ret);
|
||||
|
||||
return strlen($ret) > 0 ? $ret : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks a confirmation to the user.
|
||||
*
|
||||
* The question will be asked until the user answers by nothing, yes, or no.
|
||||
*
|
||||
* @param OutputInterface $output An Output instance
|
||||
* @param string|array $question The question to ask
|
||||
* @param Boolean $default The default answer if the user enters nothing
|
||||
*
|
||||
* @return Boolean true if the user has confirmed, false otherwise
|
||||
*/
|
||||
public function askConfirmation(OutputInterface $output, $question, $default = true)
|
||||
{
|
||||
$answer = 'z';
|
||||
while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
|
||||
$answer = $this->ask($output, $question);
|
||||
}
|
||||
|
||||
if (false === $default) {
|
||||
return $answer && 'y' == strtolower($answer[0]);
|
||||
}
|
||||
|
||||
return !$answer || 'y' == strtolower($answer[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks for a value and validates the response.
|
||||
*
|
||||
* The validator receives the data to validate. It must return the
|
||||
* validated data when the data is valid and throw an exception
|
||||
* otherwise.
|
||||
*
|
||||
* @param OutputInterface $output An Output instance
|
||||
* @param string|array $question The question to ask
|
||||
* @param callback $validator A PHP callback
|
||||
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
||||
* @param string $default The default answer if none is given by the user
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception When any of the validators return an error
|
||||
*/
|
||||
public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null)
|
||||
{
|
||||
$error = null;
|
||||
while (false === $attempts || $attempts--) {
|
||||
if (null !== $error) {
|
||||
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
|
||||
}
|
||||
|
||||
$value = $this->ask($output, $question, $default);
|
||||
|
||||
try {
|
||||
return call_user_func($validator, $value);
|
||||
} catch (\Exception $error) {
|
||||
}
|
||||
}
|
||||
|
||||
throw $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the input stream to read from when interacting with the user.
|
||||
*
|
||||
* This is mainly useful for testing purpose.
|
||||
*
|
||||
* @param resource $stream The input stream
|
||||
*/
|
||||
public function setInputStream($stream)
|
||||
{
|
||||
$this->inputStream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's input stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputStream()
|
||||
{
|
||||
return $this->inputStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's canonical name.
|
||||
*
|
||||
* @return string The helper name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'dialog';
|
||||
}
|
||||
}
|
||||
102
core/vendor/symfony/console/Symfony/Component/Console/Helper/FormatterHelper.php
vendored
Normal file
102
core/vendor/symfony/console/Symfony/Component/Console/Helper/FormatterHelper.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
|
||||
/**
|
||||
* The Formatter class provides helpers to format messages.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class FormatterHelper extends Helper
|
||||
{
|
||||
/**
|
||||
* Formats a message within a section.
|
||||
*
|
||||
* @param string $section The section name
|
||||
* @param string $message The message
|
||||
* @param string $style The style to apply to the section
|
||||
*
|
||||
* @return string The format section
|
||||
*/
|
||||
public function formatSection($section, $message, $style = 'info')
|
||||
{
|
||||
return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a message as a block of text.
|
||||
*
|
||||
* @param string|array $messages The message to write in the block
|
||||
* @param string $style The style to apply to the whole block
|
||||
* @param Boolean $large Whether to return a large block
|
||||
*
|
||||
* @return string The formatter message
|
||||
*/
|
||||
public function formatBlock($messages, $style, $large = false)
|
||||
{
|
||||
$messages = (array) $messages;
|
||||
|
||||
$len = 0;
|
||||
$lines = array();
|
||||
foreach ($messages as $message) {
|
||||
$message = OutputFormatter::escape($message);
|
||||
$lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
|
||||
$len = max($this->strlen($message) + ($large ? 4 : 2), $len);
|
||||
}
|
||||
|
||||
$messages = $large ? array(str_repeat(' ', $len)) : array();
|
||||
foreach ($lines as $line) {
|
||||
$messages[] = $line.str_repeat(' ', $len - $this->strlen($line));
|
||||
}
|
||||
if ($large) {
|
||||
$messages[] = str_repeat(' ', $len);
|
||||
}
|
||||
|
||||
foreach ($messages as &$message) {
|
||||
$message = sprintf('<%s>%s</%s>', $style, $message, $style);
|
||||
}
|
||||
|
||||
return implode("\n", $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of a string, using mb_strlen if it is available.
|
||||
*
|
||||
* @param string $string The string to check its length
|
||||
*
|
||||
* @return integer The length of the string
|
||||
*/
|
||||
private function strlen($string)
|
||||
{
|
||||
if (!function_exists('mb_strlen')) {
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
if (false === $encoding = mb_detect_encoding($string)) {
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
return mb_strlen($string, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the helper's canonical name.
|
||||
*
|
||||
* @return string The canonical name of the helper
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'formatter';
|
||||
}
|
||||
}
|
||||
42
core/vendor/symfony/console/Symfony/Component/Console/Helper/Helper.php
vendored
Normal file
42
core/vendor/symfony/console/Symfony/Component/Console/Helper/Helper.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
/**
|
||||
* Helper is the base class for all helper classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Helper implements HelperInterface
|
||||
{
|
||||
protected $helperSet = null;
|
||||
|
||||
/**
|
||||
* Sets the helper set associated with this helper.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet = null)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the helper set associated with this helper.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
return $this->helperSet;
|
||||
}
|
||||
}
|
||||
49
core/vendor/symfony/console/Symfony/Component/Console/Helper/HelperInterface.php
vendored
Normal file
49
core/vendor/symfony/console/Symfony/Component/Console/Helper/HelperInterface.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
/**
|
||||
* HelperInterface is the interface all helpers must implement.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface HelperInterface
|
||||
{
|
||||
/**
|
||||
* Sets the helper set associated with this helper.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet = null);
|
||||
|
||||
/**
|
||||
* Gets the helper set associated with this helper.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getHelperSet();
|
||||
|
||||
/**
|
||||
* Returns the canonical name of this helper.
|
||||
*
|
||||
* @return string The canonical name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getName();
|
||||
}
|
||||
104
core/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php
vendored
Normal file
104
core/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Helper;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
/**
|
||||
* HelperSet represents a set of helpers to be used with a command.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class HelperSet
|
||||
{
|
||||
private $helpers;
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Helper[] $helpers An array of helper.
|
||||
*/
|
||||
public function __construct(array $helpers = array())
|
||||
{
|
||||
$this->helpers = array();
|
||||
foreach ($helpers as $alias => $helper) {
|
||||
$this->set($helper, is_int($alias) ? null : $alias);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a helper.
|
||||
*
|
||||
* @param HelperInterface $helper The helper instance
|
||||
* @param string $alias An alias
|
||||
*/
|
||||
public function set(HelperInterface $helper, $alias = null)
|
||||
{
|
||||
$this->helpers[$helper->getName()] = $helper;
|
||||
if (null !== $alias) {
|
||||
$this->helpers[$alias] = $helper;
|
||||
}
|
||||
|
||||
$helper->setHelperSet($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the helper if defined.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return Boolean true if the helper is defined, false otherwise
|
||||
*/
|
||||
public function has($name)
|
||||
{
|
||||
return isset($this->helpers[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a helper value.
|
||||
*
|
||||
* @param string $name The helper name
|
||||
*
|
||||
* @return HelperInterface The helper instance
|
||||
*
|
||||
* @throws \InvalidArgumentException if the helper is not defined
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!$this->has($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
|
||||
}
|
||||
|
||||
return $this->helpers[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command associated with this helper set.
|
||||
*
|
||||
* @param Command $command A Command instance
|
||||
*/
|
||||
public function setCommand(Command $command = null)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command associated with this helper set.
|
||||
*
|
||||
* @return Command A Command instance
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->command;
|
||||
}
|
||||
}
|
||||
313
core/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php
vendored
Normal file
313
core/vendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* ArgvInput represents an input coming from the CLI arguments.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new ArgvInput();
|
||||
*
|
||||
* By default, the `$_SERVER['argv']` array is used for the input values.
|
||||
*
|
||||
* This can be overridden by explicitly passing the input values in the constructor:
|
||||
*
|
||||
* $input = new ArgvInput($_SERVER['argv']);
|
||||
*
|
||||
* If you pass it yourself, don't forget that the first element of the array
|
||||
* is the name of the running application.
|
||||
*
|
||||
* When passing an argument to the constructor, be sure that it respects
|
||||
* the same rules as the argv one. It's almost always better to use the
|
||||
* `StringInput` when you want to provide your own input.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @see http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
|
||||
* @see http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ArgvInput extends Input
|
||||
{
|
||||
private $tokens;
|
||||
private $parsed;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $argv An array of parameters from the CLI (in the argv format)
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct(array $argv = null, InputDefinition $definition = null)
|
||||
{
|
||||
if (null === $argv) {
|
||||
$argv = $_SERVER['argv'];
|
||||
}
|
||||
|
||||
// strip the application name
|
||||
array_shift($argv);
|
||||
|
||||
$this->tokens = $argv;
|
||||
|
||||
parent::__construct($definition);
|
||||
}
|
||||
|
||||
protected function setTokens(array $tokens)
|
||||
{
|
||||
$this->tokens = $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
protected function parse()
|
||||
{
|
||||
$parseOptions = true;
|
||||
$this->parsed = $this->tokens;
|
||||
while (null !== $token = array_shift($this->parsed)) {
|
||||
if ($parseOptions && '' == $token) {
|
||||
$this->parseArgument($token);
|
||||
} elseif ($parseOptions && '--' == $token) {
|
||||
$parseOptions = false;
|
||||
} elseif ($parseOptions && 0 === strpos($token, '--')) {
|
||||
$this->parseLongOption($token);
|
||||
} elseif ($parseOptions && '-' === $token[0]) {
|
||||
$this->parseShortOption($token);
|
||||
} else {
|
||||
$this->parseArgument($token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a short option.
|
||||
*
|
||||
* @param string $token The current token.
|
||||
*/
|
||||
private function parseShortOption($token)
|
||||
{
|
||||
$name = substr($token, 1);
|
||||
|
||||
if (strlen($name) > 1) {
|
||||
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
|
||||
// an option with a value (with no space)
|
||||
$this->addShortOption($name[0], substr($name, 1));
|
||||
} else {
|
||||
$this->parseShortOptionSet($name);
|
||||
}
|
||||
} else {
|
||||
$this->addShortOption($name, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a short option set.
|
||||
*
|
||||
* @param string $name The current token
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function parseShortOptionSet($name)
|
||||
{
|
||||
$len = strlen($name);
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if (!$this->definition->hasShortcut($name[$i])) {
|
||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOptionForShortcut($name[$i]);
|
||||
if ($option->acceptValue()) {
|
||||
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
|
||||
|
||||
break;
|
||||
} else {
|
||||
$this->addLongOption($option->getName(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a long option.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*/
|
||||
private function parseLongOption($token)
|
||||
{
|
||||
$name = substr($token, 2);
|
||||
|
||||
if (false !== $pos = strpos($name, '=')) {
|
||||
$this->addLongOption(substr($name, 0, $pos), substr($name, $pos + 1));
|
||||
} else {
|
||||
$this->addLongOption($name, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an argument.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*
|
||||
* @throws \RuntimeException When too many arguments are given
|
||||
*/
|
||||
private function parseArgument($token)
|
||||
{
|
||||
$c = count($this->arguments);
|
||||
|
||||
// if input is expecting another argument, add it
|
||||
if ($this->definition->hasArgument($c)) {
|
||||
$arg = $this->definition->getArgument($c);
|
||||
$this->arguments[$arg->getName()] = $arg->isArray()? array($token) : $token;
|
||||
|
||||
// if last argument isArray(), append token to last argument
|
||||
} elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
|
||||
$arg = $this->definition->getArgument($c - 1);
|
||||
$this->arguments[$arg->getName()][] = $token;
|
||||
|
||||
// unexpected argument
|
||||
} else {
|
||||
throw new \RuntimeException('Too many arguments.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function addShortOption($shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function addLongOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOption($name);
|
||||
|
||||
if (null === $value && $option->acceptValue()) {
|
||||
// if option accepts an optional or mandatory argument
|
||||
// let's see if there is one provided
|
||||
$next = array_shift($this->parsed);
|
||||
if ('-' !== $next[0]) {
|
||||
$value = $next;
|
||||
} else {
|
||||
array_unshift($this->parsed, $next);
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
if ($option->isValueRequired()) {
|
||||
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
|
||||
}
|
||||
|
||||
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
||||
}
|
||||
|
||||
if ($option->isArray()) {
|
||||
$this->options[$name][] = $value;
|
||||
} else {
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->tokens as $token) {
|
||||
if ($token && '-' === $token[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contain a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
public function hasParameterOption($values)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
foreach ($this->tokens as $v) {
|
||||
if (in_array($v, $values)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a raw option (not parsed).
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
* @param mixed $default The default value to return if no result is found
|
||||
*
|
||||
* @return mixed The option value
|
||||
*/
|
||||
public function getParameterOption($values, $default = false)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
$tokens = $this->tokens;
|
||||
while ($token = array_shift($tokens)) {
|
||||
foreach ($values as $value) {
|
||||
if (0 === strpos($token, $value)) {
|
||||
if (false !== $pos = strpos($token, '=')) {
|
||||
return substr($token, $pos + 1);
|
||||
}
|
||||
|
||||
return array_shift($tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
190
core/vendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.php
vendored
Normal file
190
core/vendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.php
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* ArrayInput represents an input provided as an array.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ArrayInput extends Input
|
||||
{
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $parameters An array of parameters
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct(array $parameters, InputDefinition $definition = null)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
|
||||
parent::__construct($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ($key && '-' === $key[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contain a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The values to look for in the raw parameters (can be an array)
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
public function hasParameterOption($values)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
foreach ($this->parameters as $k => $v) {
|
||||
if (!is_int($k)) {
|
||||
$v = $k;
|
||||
}
|
||||
|
||||
if (in_array($v, $values)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a raw option (not parsed).
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
* @param mixed $default The default value to return if no result is found
|
||||
*
|
||||
* @return mixed The option value
|
||||
*/
|
||||
public function getParameterOption($values, $default = false)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
foreach ($this->parameters as $k => $v) {
|
||||
if (is_int($k) && in_array($v, $values)) {
|
||||
return true;
|
||||
} elseif (in_array($k, $values)) {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
protected function parse()
|
||||
{
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if (0 === strpos($key, '--')) {
|
||||
$this->addLongOption(substr($key, 2), $value);
|
||||
} elseif ('-' === $key[0]) {
|
||||
$this->addShortOption(substr($key, 1), $value);
|
||||
} else {
|
||||
$this->addArgument($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
private function addShortOption($shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
* @throws \InvalidArgumentException When a required value is missing
|
||||
*/
|
||||
private function addLongOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$option = $this->definition->getOption($name);
|
||||
|
||||
if (null === $value) {
|
||||
if ($option->isValueRequired()) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
|
||||
}
|
||||
|
||||
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an argument value.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param mixed $value The value for the argument
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
private function addArgument($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->arguments[$name] = $value;
|
||||
}
|
||||
}
|
||||
211
core/vendor/symfony/console/Symfony/Component/Console/Input/Input.php
vendored
Normal file
211
core/vendor/symfony/console/Symfony/Component/Console/Input/Input.php
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* Input is the base class for all concrete Input classes.
|
||||
*
|
||||
* Three concrete classes are provided by default:
|
||||
*
|
||||
* * `ArgvInput`: The input comes from the CLI arguments (argv)
|
||||
* * `StringInput`: The input is provided as a string
|
||||
* * `ArrayInput`: The input is provided as an array
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class Input implements InputInterface
|
||||
{
|
||||
protected $definition;
|
||||
protected $options;
|
||||
protected $arguments;
|
||||
protected $interactive = true;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function __construct(InputDefinition $definition = null)
|
||||
{
|
||||
if (null === $definition) {
|
||||
$this->definition = new InputDefinition();
|
||||
} else {
|
||||
$this->bind($definition);
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the current Input instance with the given arguments and options.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function bind(InputDefinition $definition)
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->options = array();
|
||||
$this->definition = $definition;
|
||||
|
||||
$this->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes command line arguments.
|
||||
*/
|
||||
abstract protected function parse();
|
||||
|
||||
/**
|
||||
* Validates the input.
|
||||
*
|
||||
* @throws \RuntimeException When not enough arguments are given
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
|
||||
throw new \RuntimeException('Not enough arguments.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the input is interactive.
|
||||
*
|
||||
* @return Boolean Returns true if the input is interactive
|
||||
*/
|
||||
public function isInteractive()
|
||||
{
|
||||
return $this->interactive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the input interactivity.
|
||||
*
|
||||
* @param Boolean $interactive If the input should be interactive
|
||||
*/
|
||||
public function setInteractive($interactive)
|
||||
{
|
||||
$this->interactive = (Boolean) $interactive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument values.
|
||||
*
|
||||
* @return array An array of argument values
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument value for a given argument name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
*
|
||||
* @return mixed The argument value
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function getArgument($name)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an argument value by name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param string $value The argument value
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function setArgument($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->arguments[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return Boolean true if the InputArgument object exists, false otherwise
|
||||
*/
|
||||
public function hasArgument($name)
|
||||
{
|
||||
return $this->definition->hasArgument($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options values.
|
||||
*
|
||||
* @return array An array of option values
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return array_merge($this->definition->getOptionDefaults(), $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the option value for a given option name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
*
|
||||
* @return mixed The option value
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an option value by name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $value The option value
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return $this->definition->hasOption($name);
|
||||
}
|
||||
}
|
||||
132
core/vendor/symfony/console/Symfony/Component/Console/Input/InputArgument.php
vendored
Normal file
132
core/vendor/symfony/console/Symfony/Component/Console/Input/InputArgument.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* Represents a command line argument.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class InputArgument
|
||||
{
|
||||
const REQUIRED = 1;
|
||||
const OPTIONAL = 2;
|
||||
const IS_ARRAY = 4;
|
||||
|
||||
private $name;
|
||||
private $mode;
|
||||
private $default;
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param integer $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (for self::OPTIONAL mode only)
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument mode is not valid
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($name, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
if (null === $mode) {
|
||||
$mode = self::OPTIONAL;
|
||||
} elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
|
||||
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
$this->mode = $mode;
|
||||
$this->description = $description;
|
||||
|
||||
$this->setDefault($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the argument name.
|
||||
*
|
||||
* @return string The argument name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the argument is required.
|
||||
*
|
||||
* @return Boolean true if parameter mode is self::REQUIRED, false otherwise
|
||||
*/
|
||||
public function isRequired()
|
||||
{
|
||||
return self::REQUIRED === (self::REQUIRED & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the argument can take multiple values.
|
||||
*
|
||||
* @return Boolean true if mode is self::IS_ARRAY, false otherwise
|
||||
*/
|
||||
public function isArray()
|
||||
{
|
||||
return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param mixed $default The default value
|
||||
*
|
||||
* @throws \LogicException When incorrect default value is given
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
if (self::REQUIRED === $this->mode && null !== $default) {
|
||||
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
|
||||
}
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
} elseif (!is_array($default)) {
|
||||
throw new \LogicException('A default value for an array argument must be an array.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return mixed The default value
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description text.
|
||||
*
|
||||
* @return string The description text
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
531
core/vendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.php
vendored
Normal file
531
core/vendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.php
vendored
Normal file
@@ -0,0 +1,531 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* A InputDefinition represents a set of valid command line arguments and options.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $definition = new InputDefinition(array(
|
||||
* new InputArgument('name', InputArgument::REQUIRED),
|
||||
* new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
|
||||
* ));
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class InputDefinition
|
||||
{
|
||||
private $arguments;
|
||||
private $requiredCount;
|
||||
private $hasAnArrayArgument = false;
|
||||
private $hasOptional;
|
||||
private $options;
|
||||
private $shortcuts;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $definition An array of InputArgument and InputOption instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct(array $definition = array())
|
||||
{
|
||||
$this->setDefinition($definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the definition of the input.
|
||||
*
|
||||
* @param array $definition The definition array
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDefinition(array $definition)
|
||||
{
|
||||
$arguments = array();
|
||||
$options = array();
|
||||
foreach ($definition as $item) {
|
||||
if ($item instanceof InputOption) {
|
||||
$options[] = $item;
|
||||
} else {
|
||||
$arguments[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setArguments($arguments);
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputArgument objects.
|
||||
*
|
||||
* @param array $arguments An array of InputArgument objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setArguments($arguments = array())
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->requiredCount = 0;
|
||||
$this->hasOptional = false;
|
||||
$this->hasAnArrayArgument = false;
|
||||
$this->addArguments($arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of InputArgument objects.
|
||||
*
|
||||
* @param InputArgument[] $arguments An array of InputArgument objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addArguments($arguments = array())
|
||||
{
|
||||
if (null !== $arguments) {
|
||||
foreach ($arguments as $argument) {
|
||||
$this->addArgument($argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an InputArgument object.
|
||||
*
|
||||
* @param InputArgument $argument An InputArgument object
|
||||
*
|
||||
* @throws \LogicException When incorrect argument is given
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addArgument(InputArgument $argument)
|
||||
{
|
||||
if (isset($this->arguments[$argument->getName()])) {
|
||||
throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
|
||||
}
|
||||
|
||||
if ($this->hasAnArrayArgument) {
|
||||
throw new \LogicException('Cannot add an argument after an array argument.');
|
||||
}
|
||||
|
||||
if ($argument->isRequired() && $this->hasOptional) {
|
||||
throw new \LogicException('Cannot add a required argument after an optional one.');
|
||||
}
|
||||
|
||||
if ($argument->isArray()) {
|
||||
$this->hasAnArrayArgument = true;
|
||||
}
|
||||
|
||||
if ($argument->isRequired()) {
|
||||
++$this->requiredCount;
|
||||
} else {
|
||||
$this->hasOptional = true;
|
||||
}
|
||||
|
||||
$this->arguments[$argument->getName()] = $argument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an InputArgument by name or by position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return InputArgument An InputArgument object
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getArgument($name)
|
||||
{
|
||||
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
||||
|
||||
if (!$this->hasArgument($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
return $arguments[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return Boolean true if the InputArgument object exists, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasArgument($name)
|
||||
{
|
||||
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
||||
|
||||
return isset($arguments[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of InputArgument objects.
|
||||
*
|
||||
* @return array An array of InputArgument objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of InputArguments.
|
||||
*
|
||||
* @return integer The number of InputArguments
|
||||
*/
|
||||
public function getArgumentCount()
|
||||
{
|
||||
return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of required InputArguments.
|
||||
*
|
||||
* @return integer The number of required InputArguments
|
||||
*/
|
||||
public function getArgumentRequiredCount()
|
||||
{
|
||||
return $this->requiredCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default values.
|
||||
*
|
||||
* @return array An array of default values
|
||||
*/
|
||||
public function getArgumentDefaults()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->arguments as $argument) {
|
||||
$values[$argument->getName()] = $argument->getDefault();
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InputOption objects.
|
||||
*
|
||||
* @param array $options An array of InputOption objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
{
|
||||
$this->options = array();
|
||||
$this->shortcuts = array();
|
||||
$this->addOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an array of InputOption objects.
|
||||
*
|
||||
* @param InputOption[] $options An array of InputOption objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addOptions($options = array())
|
||||
{
|
||||
foreach ($options as $option) {
|
||||
$this->addOption($option);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an InputOption object.
|
||||
*
|
||||
* @param InputOption $option An InputOption object
|
||||
*
|
||||
* @throws \LogicException When option given already exist
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addOption(InputOption $option)
|
||||
{
|
||||
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
|
||||
throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
|
||||
} elseif (isset($this->shortcuts[$option->getShortcut()]) && !$option->equals($this->options[$this->shortcuts[$option->getShortcut()]])) {
|
||||
throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $option->getShortcut()));
|
||||
}
|
||||
|
||||
$this->options[$option->getName()] = $option;
|
||||
if ($option->getShortcut()) {
|
||||
$this->shortcuts[$option->getShortcut()] = $option->getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an InputOption by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return InputOption A InputOption object
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
if (!$this->hasOption($name)) {
|
||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
return $this->options[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return isset($this->options[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of InputOption objects.
|
||||
*
|
||||
* @return array An array of InputOption objects
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by shortcut.
|
||||
*
|
||||
* @param string $name The InputOption shortcut
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasShortcut($name)
|
||||
{
|
||||
return isset($this->shortcuts[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an InputOption by shortcut.
|
||||
*
|
||||
* @param string $shortcut the Shortcut name
|
||||
*
|
||||
* @return InputOption An InputOption object
|
||||
*/
|
||||
public function getOptionForShortcut($shortcut)
|
||||
{
|
||||
return $this->getOption($this->shortcutToName($shortcut));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of default values.
|
||||
*
|
||||
* @return array An array of all default values
|
||||
*/
|
||||
public function getOptionDefaults()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->options as $option) {
|
||||
$values[$option->getName()] = $option->getDefault();
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the InputOption name given a shortcut.
|
||||
*
|
||||
* @param string $shortcut The shortcut
|
||||
*
|
||||
* @return string The InputOption name
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given does not exist
|
||||
*/
|
||||
private function shortcutToName($shortcut)
|
||||
{
|
||||
if (!isset($this->shortcuts[$shortcut])) {
|
||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
}
|
||||
|
||||
return $this->shortcuts[$shortcut];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the synopsis.
|
||||
*
|
||||
* @return string The synopsis
|
||||
*/
|
||||
public function getSynopsis()
|
||||
{
|
||||
$elements = array();
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
|
||||
$elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
|
||||
}
|
||||
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : ''));
|
||||
|
||||
if ($argument->isArray()) {
|
||||
$elements[] = sprintf('... [%sN]', $argument->getName());
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ', $elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual representation of the InputDefinition.
|
||||
*
|
||||
* @return string A string representing the InputDefinition
|
||||
*/
|
||||
public function asText()
|
||||
{
|
||||
// find the largest option or argument name
|
||||
$max = 0;
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$nameLength = strlen($option->getName()) + 2;
|
||||
if ($option->getShortcut()) {
|
||||
$nameLength += strlen($option->getShortcut()) + 3;
|
||||
}
|
||||
|
||||
$max = max($max, $nameLength);
|
||||
}
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$max = max($max, strlen($argument->getName()));
|
||||
}
|
||||
++$max;
|
||||
|
||||
$text = array();
|
||||
|
||||
if ($this->getArguments()) {
|
||||
$text[] = '<comment>Arguments:</comment>';
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
|
||||
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
|
||||
} else {
|
||||
$default = '';
|
||||
}
|
||||
|
||||
$description = str_replace("\n", "\n".str_pad('', $max + 2, ' '), $argument->getDescription());
|
||||
|
||||
$text[] = sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $description, $default);
|
||||
}
|
||||
|
||||
$text[] = '';
|
||||
}
|
||||
|
||||
if ($this->getOptions()) {
|
||||
$text[] = '<comment>Options:</comment>';
|
||||
|
||||
foreach ($this->getOptions() as $option) {
|
||||
if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
|
||||
$default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
|
||||
} else {
|
||||
$default = '';
|
||||
}
|
||||
|
||||
$multiple = $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '';
|
||||
$description = str_replace("\n", "\n".str_pad('', $max + 2, ' '), $option->getDescription());
|
||||
|
||||
$optionMax = $max - strlen($option->getName()) - 2;
|
||||
$text[] = sprintf(" <info>%s</info> %-${optionMax}s%s%s%s",
|
||||
'--'.$option->getName(),
|
||||
$option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
|
||||
$description,
|
||||
$default,
|
||||
$multiple
|
||||
);
|
||||
}
|
||||
|
||||
$text[] = '';
|
||||
}
|
||||
|
||||
return implode("\n", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML representation of the InputDefinition.
|
||||
*
|
||||
* @param Boolean $asDom Whether to return a DOM or an XML string
|
||||
*
|
||||
* @return string|DOMDocument An XML string representing the InputDefinition
|
||||
*/
|
||||
public function asXml($asDom = false)
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||
$dom->formatOutput = true;
|
||||
$dom->appendChild($definitionXML = $dom->createElement('definition'));
|
||||
|
||||
$definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
|
||||
foreach ($this->getArguments() as $argument) {
|
||||
$argumentsXML->appendChild($argumentXML = $dom->createElement('argument'));
|
||||
$argumentXML->setAttribute('name', $argument->getName());
|
||||
$argumentXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
|
||||
$argumentXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
|
||||
$argumentXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
|
||||
|
||||
$argumentXML->appendChild($defaultsXML = $dom->createElement('defaults'));
|
||||
$defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
|
||||
foreach ($defaults as $default) {
|
||||
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
|
||||
$defaultXML->appendChild($dom->createTextNode($default));
|
||||
}
|
||||
}
|
||||
|
||||
$definitionXML->appendChild($optionsXML = $dom->createElement('options'));
|
||||
foreach ($this->getOptions() as $option) {
|
||||
$optionsXML->appendChild($optionXML = $dom->createElement('option'));
|
||||
$optionXML->setAttribute('name', '--'.$option->getName());
|
||||
$optionXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
|
||||
$optionXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
|
||||
$optionXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
|
||||
$optionXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
|
||||
$optionXML->appendChild($descriptionXML = $dom->createElement('description'));
|
||||
$descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
|
||||
|
||||
if ($option->acceptValue()) {
|
||||
$optionXML->appendChild($defaultsXML = $dom->createElement('defaults'));
|
||||
$defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
|
||||
foreach ($defaults as $default) {
|
||||
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
|
||||
$defaultXML->appendChild($dom->createTextNode($default));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $asDom ? $dom : $dom->saveXml();
|
||||
}
|
||||
|
||||
private function formatDefaultValue($default)
|
||||
{
|
||||
return json_encode($default);
|
||||
}
|
||||
}
|
||||
152
core/vendor/symfony/console/Symfony/Component/Console/Input/InputInterface.php
vendored
Normal file
152
core/vendor/symfony/console/Symfony/Component/Console/Input/InputInterface.php
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* InputInterface is the interface implemented by all input classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface InputInterface
|
||||
{
|
||||
/**
|
||||
* Returns the first argument from the raw parameters (not parsed).
|
||||
*
|
||||
* @return string The value of the first argument or null otherwise
|
||||
*/
|
||||
public function getFirstArgument();
|
||||
|
||||
/**
|
||||
* Returns true if the raw parameters (not parsed) contain a value.
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The values to look for in the raw parameters (can be an array)
|
||||
*
|
||||
* @return Boolean true if the value is contained in the raw parameters
|
||||
*/
|
||||
public function hasParameterOption($values);
|
||||
|
||||
/**
|
||||
* Returns the value of a raw option (not parsed).
|
||||
*
|
||||
* This method is to be used to introspect the input parameters
|
||||
* before they have been validated. It must be used carefully.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
* @param mixed $default The default value to return if no result is found
|
||||
*
|
||||
* @return mixed The option value
|
||||
*/
|
||||
public function getParameterOption($values, $default = false);
|
||||
|
||||
/**
|
||||
* Binds the current Input instance with the given arguments and options.
|
||||
*
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*/
|
||||
public function bind(InputDefinition $definition);
|
||||
|
||||
/**
|
||||
* Validates if arguments given are correct.
|
||||
*
|
||||
* Throws an exception when not enough arguments are given.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function validate();
|
||||
|
||||
/**
|
||||
* Returns all the given arguments merged with the default values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArguments();
|
||||
|
||||
/**
|
||||
* Gets argument by name.
|
||||
*
|
||||
* @param string $name The name of the argument
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getArgument($name);
|
||||
|
||||
/**
|
||||
* Sets an argument value by name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param string $value The argument value
|
||||
*
|
||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
public function setArgument($name, $value);
|
||||
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|integer $name The InputArgument name or position
|
||||
*
|
||||
* @return Boolean true if the InputArgument object exists, false otherwise
|
||||
*/
|
||||
public function hasArgument($name);
|
||||
|
||||
/**
|
||||
* Returns all the given options merged with the default values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions();
|
||||
|
||||
/**
|
||||
* Gets an option by name.
|
||||
*
|
||||
* @param string $name The name of the option
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($name);
|
||||
|
||||
/**
|
||||
* Sets an option value by name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $value The option value
|
||||
*
|
||||
* @throws \InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
public function setOption($name, $value);
|
||||
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return Boolean true if the InputOption object exists, false otherwise
|
||||
*/
|
||||
public function hasOption($name);
|
||||
|
||||
/**
|
||||
* Is this input means interactive?
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function isInteractive();
|
||||
|
||||
/**
|
||||
* Sets the input interactivity.
|
||||
*
|
||||
* @param Boolean $interactive If the input should be interactive
|
||||
*/
|
||||
public function setInteractive($interactive);
|
||||
}
|
||||
209
core/vendor/symfony/console/Symfony/Component/Console/Input/InputOption.php
vendored
Normal file
209
core/vendor/symfony/console/Symfony/Component/Console/Input/InputOption.php
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* Represents a command line option.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class InputOption
|
||||
{
|
||||
const VALUE_NONE = 1;
|
||||
const VALUE_REQUIRED = 2;
|
||||
const VALUE_OPTIONAL = 4;
|
||||
const VALUE_IS_ARRAY = 8;
|
||||
|
||||
private $name;
|
||||
private $shortcut;
|
||||
private $mode;
|
||||
private $default;
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string $shortcut The shortcut (can be null)
|
||||
* @param integer $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
||||
*
|
||||
* @throws \InvalidArgumentException If option mode is invalid or incompatible
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
|
||||
{
|
||||
if (0 === strpos($name, '--')) {
|
||||
$name = substr($name, 2);
|
||||
}
|
||||
|
||||
if (empty($name)) {
|
||||
throw new \InvalidArgumentException('An option name cannot be empty.');
|
||||
}
|
||||
|
||||
if (empty($shortcut)) {
|
||||
$shortcut = null;
|
||||
}
|
||||
|
||||
if (null !== $shortcut) {
|
||||
if ('-' === $shortcut[0]) {
|
||||
$shortcut = substr($shortcut, 1);
|
||||
}
|
||||
|
||||
if (empty($shortcut)) {
|
||||
throw new \InvalidArgumentException('An option shortcut cannot be empty.');
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $mode) {
|
||||
$mode = self::VALUE_NONE;
|
||||
} elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
|
||||
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
$this->shortcut = $shortcut;
|
||||
$this->mode = $mode;
|
||||
$this->description = $description;
|
||||
|
||||
if ($this->isArray() && !$this->acceptValue()) {
|
||||
throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
|
||||
}
|
||||
|
||||
$this->setDefault($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the option shortcut.
|
||||
*
|
||||
* @return string The shortcut
|
||||
*/
|
||||
public function getShortcut()
|
||||
{
|
||||
return $this->shortcut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the option name.
|
||||
*
|
||||
* @return string The name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option accepts a value.
|
||||
*
|
||||
* @return Boolean true if value mode is not self::VALUE_NONE, false otherwise
|
||||
*/
|
||||
public function acceptValue()
|
||||
{
|
||||
return $this->isValueRequired() || $this->isValueOptional();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option requires a value.
|
||||
*
|
||||
* @return Boolean true if value mode is self::VALUE_REQUIRED, false otherwise
|
||||
*/
|
||||
public function isValueRequired()
|
||||
{
|
||||
return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option takes an optional value.
|
||||
*
|
||||
* @return Boolean true if value mode is self::VALUE_OPTIONAL, false otherwise
|
||||
*/
|
||||
public function isValueOptional()
|
||||
{
|
||||
return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the option can take multiple values.
|
||||
*
|
||||
* @return Boolean true if mode is self::VALUE_IS_ARRAY, false otherwise
|
||||
*/
|
||||
public function isArray()
|
||||
{
|
||||
return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param mixed $default The default value
|
||||
*
|
||||
* @throws \LogicException When incorrect default value is given
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
|
||||
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
|
||||
}
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
} elseif (!is_array($default)) {
|
||||
throw new \LogicException('A default value for an array option must be an array.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->default = $this->acceptValue() ? $default : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return mixed The default value
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description text.
|
||||
*
|
||||
* @return string The description text
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given option equals this one
|
||||
*
|
||||
* @param InputOption $option option to compare
|
||||
* @return Boolean
|
||||
*/
|
||||
public function equals(InputOption $option)
|
||||
{
|
||||
return $option->getName() === $this->getName()
|
||||
&& $option->getShortcut() === $this->getShortcut()
|
||||
&& $option->getDefault() === $this->getDefault()
|
||||
&& $option->isArray() === $this->isArray()
|
||||
&& $option->isValueRequired() === $this->isValueRequired()
|
||||
&& $option->isValueOptional() === $this->isValueOptional()
|
||||
;
|
||||
}
|
||||
}
|
||||
81
core/vendor/symfony/console/Symfony/Component/Console/Input/StringInput.php
vendored
Normal file
81
core/vendor/symfony/console/Symfony/Component/Console/Input/StringInput.php
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
/**
|
||||
* StringInput represents an input provided as a string.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new StringInput('foo --bar="foobar"');
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class StringInput extends ArgvInput
|
||||
{
|
||||
const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $input An array of parameters from the CLI (in the argv format)
|
||||
* @param InputDefinition $definition A InputDefinition instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($input, InputDefinition $definition = null)
|
||||
{
|
||||
parent::__construct(array(), $definition);
|
||||
|
||||
$this->setTokens($this->tokenize($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenizes a string.
|
||||
*
|
||||
* @param string $input The input to tokenize
|
||||
*
|
||||
* @return array An array of tokens
|
||||
*
|
||||
* @throws \InvalidArgumentException When unable to parse input (should never happen)
|
||||
*/
|
||||
private function tokenize($input)
|
||||
{
|
||||
$input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
|
||||
|
||||
$tokens = array();
|
||||
$length = strlen($input);
|
||||
$cursor = 0;
|
||||
while ($cursor < $length) {
|
||||
if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
|
||||
} elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
|
||||
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
|
||||
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes($match[1]);
|
||||
} else {
|
||||
// should never happen
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$cursor += strlen($match[0]);
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
19
core/vendor/symfony/console/Symfony/Component/Console/LICENSE
vendored
Normal file
19
core/vendor/symfony/console/Symfony/Component/Console/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2004-2012 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
104
core/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php
vendored
Normal file
104
core/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
|
||||
/**
|
||||
* ConsoleOutput is the default class for all CLI output. It uses STDOUT.
|
||||
*
|
||||
* This class is a convenient wrapper around `StreamOutput`.
|
||||
*
|
||||
* $output = new ConsoleOutput();
|
||||
*
|
||||
* This is equivalent to:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('php://stdout', 'w'));
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
|
||||
{
|
||||
private $stderr;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
|
||||
* self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
* @param OutputFormatter $formatter Output formatter instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
||||
{
|
||||
$outputStream = 'php://stdout';
|
||||
if (!$this->hasStdoutSupport()) {
|
||||
$outputStream = 'php://output';
|
||||
}
|
||||
|
||||
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
|
||||
|
||||
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
|
||||
}
|
||||
|
||||
public function setDecorated($decorated)
|
||||
{
|
||||
parent::setDecorated($decorated);
|
||||
$this->stderr->setDecorated($decorated);
|
||||
}
|
||||
|
||||
public function setFormatter(OutputFormatterInterface $formatter)
|
||||
{
|
||||
parent::setFormatter($formatter);
|
||||
$this->stderr->setFormatter($formatter);
|
||||
}
|
||||
|
||||
public function setVerbosity($level)
|
||||
{
|
||||
parent::setVerbosity($level);
|
||||
$this->stderr->setVerbosity($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OutputInterface
|
||||
*/
|
||||
public function getErrorOutput()
|
||||
{
|
||||
return $this->stderr;
|
||||
}
|
||||
|
||||
public function setErrorOutput(OutputInterface $error)
|
||||
{
|
||||
$this->stderr = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if current environment supports writing console output to
|
||||
* STDOUT.
|
||||
*
|
||||
* IBM iSeries (OS400) exhibits character-encoding issues when writing to
|
||||
* STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
|
||||
* output.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function hasStdoutSupport()
|
||||
{
|
||||
return ('OS400' != php_uname('s'));
|
||||
}
|
||||
}
|
||||
30
core/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutputInterface.php
vendored
Normal file
30
core/vendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutputInterface.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* ConsoleOutputInterface is the interface implemented by ConsoleOutput class.
|
||||
* This adds information about stderr output stream.
|
||||
*
|
||||
* @author Dariusz Górecki <darek.krk@gmail.com>
|
||||
*/
|
||||
interface ConsoleOutputInterface extends OutputInterface
|
||||
{
|
||||
/**
|
||||
* @return OutputInterface
|
||||
*/
|
||||
public function getErrorOutput();
|
||||
|
||||
public function setErrorOutput(OutputInterface $error);
|
||||
}
|
||||
34
core/vendor/symfony/console/Symfony/Component/Console/Output/NullOutput.php
vendored
Normal file
34
core/vendor/symfony/console/Symfony/Component/Console/Output/NullOutput.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
/**
|
||||
* NullOutput suppresses all output.
|
||||
*
|
||||
* $output = new NullOutput();
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class NullOutput extends Output
|
||||
{
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*/
|
||||
protected function doWrite($message, $newline)
|
||||
{
|
||||
}
|
||||
}
|
||||
180
core/vendor/symfony/console/Symfony/Component/Console/Output/Output.php
vendored
Normal file
180
core/vendor/symfony/console/Symfony/Component/Console/Output/Output.php
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
|
||||
/**
|
||||
* Base class for output classes.
|
||||
*
|
||||
* There are three levels of verbosity:
|
||||
*
|
||||
* * normal: no option passed (normal output - information)
|
||||
* * verbose: -v (more output - debug)
|
||||
* * quiet: -q (no output)
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
abstract class Output implements OutputInterface
|
||||
{
|
||||
private $verbosity;
|
||||
private $formatter;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
* @param OutputFormatterInterface $formatter Output formatter instance
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
||||
{
|
||||
$this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
|
||||
$this->formatter = null === $formatter ? new OutputFormatter() : $formatter;
|
||||
$this->formatter->setDecorated((Boolean) $decorated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets output formatter.
|
||||
*
|
||||
* @param OutputFormatterInterface $formatter
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setFormatter(OutputFormatterInterface $formatter)
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current output formatter instance.
|
||||
*
|
||||
* @return OutputFormatterInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getFormatter()
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorate the messages or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDecorated($decorated)
|
||||
{
|
||||
$this->formatter->setDecorated((Boolean) $decorated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the decorated flag.
|
||||
*
|
||||
* @return Boolean true if the output will decorate messages, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isDecorated()
|
||||
{
|
||||
return $this->formatter->isDecorated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the verbosity of the output.
|
||||
*
|
||||
* @param integer $level The level of verbosity
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setVerbosity($level)
|
||||
{
|
||||
$this->verbosity = (int) $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current verbosity of the output.
|
||||
*
|
||||
* @return integer The current level of verbosity
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getVerbosity()
|
||||
{
|
||||
return $this->verbosity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output and adds a newline at the end.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param integer $type The type of output
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function writeln($messages, $type = 0)
|
||||
{
|
||||
$this->write($messages, true, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
* @param integer $type The type of output
|
||||
*
|
||||
* @throws \InvalidArgumentException When unknown output type is given
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function write($messages, $newline = false, $type = 0)
|
||||
{
|
||||
if (self::VERBOSITY_QUIET === $this->verbosity) {
|
||||
return;
|
||||
}
|
||||
|
||||
$messages = (array) $messages;
|
||||
|
||||
foreach ($messages as $message) {
|
||||
switch ($type) {
|
||||
case OutputInterface::OUTPUT_NORMAL:
|
||||
$message = $this->formatter->format($message);
|
||||
break;
|
||||
case OutputInterface::OUTPUT_RAW:
|
||||
break;
|
||||
case OutputInterface::OUTPUT_PLAIN:
|
||||
$message = strip_tags($this->formatter->format($message));
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
|
||||
}
|
||||
|
||||
$this->doWrite($message, $newline);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*/
|
||||
abstract protected function doWrite($message, $newline);
|
||||
}
|
||||
109
core/vendor/symfony/console/Symfony/Component/Console/Output/OutputInterface.php
vendored
Normal file
109
core/vendor/symfony/console/Symfony/Component/Console/Output/OutputInterface.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||
|
||||
/**
|
||||
* OutputInterface is the interface implemented by all Output classes.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
interface OutputInterface
|
||||
{
|
||||
const VERBOSITY_QUIET = 0;
|
||||
const VERBOSITY_NORMAL = 1;
|
||||
const VERBOSITY_VERBOSE = 2;
|
||||
|
||||
const OUTPUT_NORMAL = 0;
|
||||
const OUTPUT_RAW = 1;
|
||||
const OUTPUT_PLAIN = 2;
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
|
||||
*
|
||||
* @throws \InvalidArgumentException When unknown output type is given
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function write($messages, $newline = false, $type = 0);
|
||||
|
||||
/**
|
||||
* Writes a message to the output and adds a newline at the end.
|
||||
*
|
||||
* @param string|array $messages The message as an array of lines of a single string
|
||||
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function writeln($messages, $type = 0);
|
||||
|
||||
/**
|
||||
* Sets the verbosity of the output.
|
||||
*
|
||||
* @param integer $level The level of verbosity
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setVerbosity($level);
|
||||
|
||||
/**
|
||||
* Gets the current verbosity of the output.
|
||||
*
|
||||
* @return integer The current level of verbosity
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getVerbosity();
|
||||
|
||||
/**
|
||||
* Sets the decorated flag.
|
||||
*
|
||||
* @param Boolean $decorated Whether to decorate the messages or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setDecorated($decorated);
|
||||
|
||||
/**
|
||||
* Gets the decorated flag.
|
||||
*
|
||||
* @return Boolean true if the output will decorate messages, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isDecorated();
|
||||
|
||||
/**
|
||||
* Sets output formatter.
|
||||
*
|
||||
* @param OutputFormatterInterface $formatter
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setFormatter(OutputFormatterInterface $formatter);
|
||||
|
||||
/**
|
||||
* Returns current output formatter instance.
|
||||
*
|
||||
* @return OutputFormatterInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getFormatter();
|
||||
}
|
||||
113
core/vendor/symfony/console/Symfony/Component/Console/Output/StreamOutput.php
vendored
Normal file
113
core/vendor/symfony/console/Symfony/Component/Console/Output/StreamOutput.php
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Output;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||
|
||||
/**
|
||||
* StreamOutput writes the output to a given stream.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('php://stdout', 'w'));
|
||||
*
|
||||
* As `StreamOutput` can use any stream, you can also use a file:
|
||||
*
|
||||
* $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class StreamOutput extends Output
|
||||
{
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mixed $stream A stream resource
|
||||
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
|
||||
* self::VERBOSITY_VERBOSE)
|
||||
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
|
||||
* @param OutputFormatter $formatter Output formatter instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When first argument is not a real stream
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
||||
{
|
||||
if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
|
||||
throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
|
||||
}
|
||||
|
||||
$this->stream = $stream;
|
||||
|
||||
if (null === $decorated) {
|
||||
$decorated = $this->hasColorSupport($decorated);
|
||||
}
|
||||
|
||||
parent::__construct($verbosity, $decorated, $formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stream attached to this StreamOutput instance.
|
||||
*
|
||||
* @return resource A stream resource
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to the output.
|
||||
*
|
||||
* @param string $message A message to write to the output
|
||||
* @param Boolean $newline Whether to add a newline or not
|
||||
*
|
||||
* @throws \RuntimeException When unable to write output (should never happen)
|
||||
*/
|
||||
protected function doWrite($message, $newline)
|
||||
{
|
||||
if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// should never happen
|
||||
throw new \RuntimeException('Unable to write output.');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
fflush($this->stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the stream supports colorization.
|
||||
*
|
||||
* Colorization is disabled if not supported by the stream:
|
||||
*
|
||||
* - windows without ansicon
|
||||
* - non tty consoles
|
||||
*
|
||||
* @return Boolean true if the stream supports colorization, false otherwise
|
||||
*/
|
||||
protected function hasColorSupport()
|
||||
{
|
||||
// @codeCoverageIgnoreStart
|
||||
if (DIRECTORY_SEPARATOR == '\\') {
|
||||
return false !== getenv('ANSICON');
|
||||
}
|
||||
|
||||
return function_exists('posix_isatty') && @posix_isatty($this->stream);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
55
core/vendor/symfony/console/Symfony/Component/Console/README.md
vendored
Normal file
55
core/vendor/symfony/console/Symfony/Component/Console/README.md
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
Console Component
|
||||
=================
|
||||
|
||||
Console eases the creation of beautiful and testable command line interfaces.
|
||||
|
||||
The Application object manages the CLI application:
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$console = new Application();
|
||||
$console->run();
|
||||
|
||||
The ``run()`` method parses the arguments and options passed on the command
|
||||
line and executes the right command.
|
||||
|
||||
Registering a new command can easily be done via the ``register()`` method,
|
||||
which returns a ``Command`` instance:
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
$console
|
||||
->register('ls')
|
||||
->setDefinition(array(
|
||||
new InputArgument('dir', InputArgument::REQUIRED, 'Directory name'),
|
||||
))
|
||||
->setDescription('Displays the files in the given directory')
|
||||
->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$dir = $input->getArgument('dir');
|
||||
|
||||
$output->writeln(sprintf('Dir listing for <info>%s</info>', $dir));
|
||||
})
|
||||
;
|
||||
|
||||
You can also register new commands via classes.
|
||||
|
||||
The component provides a lot of features like output coloring, input and
|
||||
output abstractions (so that you can easily unit-test your commands),
|
||||
validation, automatic help messages, ...
|
||||
|
||||
Tests
|
||||
---------
|
||||
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
phpunit
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
[The Console Component](http://symfony.com/doc/current/components/console.html)
|
||||
|
||||
[How to create a Console Command](http://symfony.com/doc/current/cookbook/console/console_command.html)
|
||||
207
core/vendor/symfony/console/Symfony/Component/Console/Shell.php
vendored
Normal file
207
core/vendor/symfony/console/Symfony/Component/Console/Shell.php
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Process\ProcessBuilder;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
|
||||
/**
|
||||
* A Shell wraps an Application to add shell capabilities to it.
|
||||
*
|
||||
* Support for history and completion only works with a PHP compiled
|
||||
* with readline support (either --with-readline or --with-libedit)
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Martin Hasoň <martin.hason@gmail.com>
|
||||
*/
|
||||
class Shell
|
||||
{
|
||||
private $application;
|
||||
private $history;
|
||||
private $output;
|
||||
private $hasReadline;
|
||||
private $prompt;
|
||||
private $processIsolation;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* If there is no readline support for the current PHP executable
|
||||
* a \RuntimeException exception is thrown.
|
||||
*
|
||||
* @param Application $application An application instance
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->hasReadline = function_exists('readline');
|
||||
$this->application = $application;
|
||||
$this->history = getenv('HOME').'/.history_'.$application->getName();
|
||||
$this->output = new ConsoleOutput();
|
||||
$this->prompt = $application->getName().' > ';
|
||||
$this->processIsolation = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the shell.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->application->setAutoExit(false);
|
||||
$this->application->setCatchExceptions(true);
|
||||
|
||||
if ($this->hasReadline) {
|
||||
readline_read_history($this->history);
|
||||
readline_completion_function(array($this, 'autocompleter'));
|
||||
}
|
||||
|
||||
$this->output->writeln($this->getHeader());
|
||||
$php = null;
|
||||
if ($this->processIsolation) {
|
||||
$finder = new PhpExecutableFinder();
|
||||
$php = $finder->find();
|
||||
$this->output->writeln(<<<EOF
|
||||
<info>Running with process isolation, you should consider this:</info>
|
||||
* each command is executed as separate process,
|
||||
* commands don't support interactivity, all params must be passed explicitly,
|
||||
* commands output is not colorized.
|
||||
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$command = $this->readline();
|
||||
|
||||
if (false === $command) {
|
||||
$this->output->writeln("\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->hasReadline) {
|
||||
readline_add_history($command);
|
||||
readline_write_history($this->history);
|
||||
}
|
||||
|
||||
if ($this->processIsolation) {
|
||||
$pb = new ProcessBuilder();
|
||||
|
||||
$process = $pb
|
||||
->add($php)
|
||||
->add($_SERVER['argv'][0])
|
||||
->add($command)
|
||||
->inheritEnvironmentVariables(true)
|
||||
->getProcess()
|
||||
;
|
||||
|
||||
$output = $this->output;
|
||||
$process->run(function($type, $data) use ($output) {
|
||||
$output->writeln($data);
|
||||
});
|
||||
|
||||
$ret = $process->getExitCode();
|
||||
} else {
|
||||
$ret = $this->application->run(new StringInput($command), $this->output);
|
||||
}
|
||||
|
||||
if (0 !== $ret) {
|
||||
$this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shell header.
|
||||
*
|
||||
* @return string The header string
|
||||
*/
|
||||
protected function getHeader()
|
||||
{
|
||||
return <<<EOF
|
||||
|
||||
Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
|
||||
|
||||
At the prompt, type <comment>help</comment> for some help,
|
||||
or <comment>list</comment> to get a list of available commands.
|
||||
|
||||
To exit the shell, type <comment>^D</comment>.
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to return autocompletion for the current entered text.
|
||||
*
|
||||
* @param string $text The last segment of the entered text
|
||||
*
|
||||
* @return Boolean|array A list of guessed strings or true
|
||||
*/
|
||||
private function autocompleter($text)
|
||||
{
|
||||
$info = readline_info();
|
||||
$text = substr($info['line_buffer'], 0, $info['end']);
|
||||
|
||||
if ($info['point'] !== $info['end']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// task name?
|
||||
if (false === strpos($text, ' ') || !$text) {
|
||||
return array_keys($this->application->all());
|
||||
}
|
||||
|
||||
// options and arguments?
|
||||
try {
|
||||
$command = $this->application->find(substr($text, 0, strpos($text, ' ')));
|
||||
} catch (\Exception $e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$list = array('--help');
|
||||
foreach ($command->getDefinition()->getOptions() as $option) {
|
||||
$list[] = '--'.$option->getName();
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a single line from standard input.
|
||||
*
|
||||
* @return string The single line from standard input
|
||||
*/
|
||||
private function readline()
|
||||
{
|
||||
if ($this->hasReadline) {
|
||||
$line = readline($this->prompt);
|
||||
} else {
|
||||
$this->output->write($this->prompt);
|
||||
$line = fgets(STDIN, 1024);
|
||||
$line = (!$line && strlen($line) == 0) ? false : rtrim($line);
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
public function getProcessIsolation()
|
||||
{
|
||||
return $this->processIsolation;
|
||||
}
|
||||
|
||||
public function setProcessIsolation($processIsolation)
|
||||
{
|
||||
$this->processIsolation = (Boolean) $processIsolation;
|
||||
}
|
||||
}
|
||||
104
core/vendor/symfony/console/Symfony/Component/Console/Tester/ApplicationTester.php
vendored
Normal file
104
core/vendor/symfony/console/Symfony/Component/Console/Tester/ApplicationTester.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tester;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/**
|
||||
* Eases the testing of console applications.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ApplicationTester
|
||||
{
|
||||
private $application;
|
||||
private $input;
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Application $application An Application instance to test.
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->application = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the application.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * interactive: Sets the input interactive flag
|
||||
* * decorated: Sets the output decorated flag
|
||||
* * verbosity: Sets the output verbosity flag
|
||||
*
|
||||
* @param array $input An array of arguments and options
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return integer The command exit code
|
||||
*/
|
||||
public function run(array $input, $options = array())
|
||||
{
|
||||
$this->input = new ArrayInput($input);
|
||||
if (isset($options['interactive'])) {
|
||||
$this->input->setInteractive($options['interactive']);
|
||||
}
|
||||
|
||||
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
|
||||
if (isset($options['decorated'])) {
|
||||
$this->output->setDecorated($options['decorated']);
|
||||
}
|
||||
if (isset($options['verbosity'])) {
|
||||
$this->output->setVerbosity($options['verbosity']);
|
||||
}
|
||||
|
||||
return $this->application->run($this->input, $this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display returned by the last execution of the application.
|
||||
*
|
||||
* @return string The display
|
||||
*/
|
||||
public function getDisplay()
|
||||
{
|
||||
rewind($this->output->getStream());
|
||||
|
||||
return stream_get_contents($this->output->getStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input instance used by the last execution of the application.
|
||||
*
|
||||
* @return InputInterface The current input instance
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output instance used by the last execution of the application.
|
||||
*
|
||||
* @return OutputInterface The current output instance
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
102
core/vendor/symfony/console/Symfony/Component/Console/Tester/CommandTester.php
vendored
Normal file
102
core/vendor/symfony/console/Symfony/Component/Console/Tester/CommandTester.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tester;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/**
|
||||
* Eases the testing of console commands.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class CommandTester
|
||||
{
|
||||
private $command;
|
||||
private $input;
|
||||
private $output;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Command $command A Command instance to test.
|
||||
*/
|
||||
public function __construct(Command $command)
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command.
|
||||
*
|
||||
* Available options:
|
||||
*
|
||||
* * interactive: Sets the input interactive flag
|
||||
* * decorated: Sets the output decorated flag
|
||||
* * verbosity: Sets the output verbosity flag
|
||||
*
|
||||
* @param array $input An array of arguments and options
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @return integer The command exit code
|
||||
*/
|
||||
public function execute(array $input, array $options = array())
|
||||
{
|
||||
$this->input = new ArrayInput($input);
|
||||
if (isset($options['interactive'])) {
|
||||
$this->input->setInteractive($options['interactive']);
|
||||
}
|
||||
|
||||
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
|
||||
if (isset($options['decorated'])) {
|
||||
$this->output->setDecorated($options['decorated']);
|
||||
}
|
||||
if (isset($options['verbosity'])) {
|
||||
$this->output->setVerbosity($options['verbosity']);
|
||||
}
|
||||
|
||||
return $this->command->run($this->input, $this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display returned by the last execution of the command.
|
||||
*
|
||||
* @return string The display
|
||||
*/
|
||||
public function getDisplay()
|
||||
{
|
||||
rewind($this->output->getStream());
|
||||
|
||||
return stream_get_contents($this->output->getStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input instance used by the last execution of the command.
|
||||
*
|
||||
* @return InputInterface The current input instance
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the output instance used by the last execution of the command.
|
||||
*
|
||||
* @return OutputInterface The current output instance
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
516
core/vendor/symfony/console/Symfony/Component/Console/Tests/ApplicationTest.php
vendored
Normal file
516
core/vendor/symfony/console/Symfony/Component/Console/Tests/ApplicationTest.php
vendored
Normal file
@@ -0,0 +1,516 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
class ApplicationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = realpath(__DIR__.'/Fixtures/');
|
||||
require_once self::$fixturesPath.'/FooCommand.php';
|
||||
require_once self::$fixturesPath.'/Foo1Command.php';
|
||||
require_once self::$fixturesPath.'/Foo2Command.php';
|
||||
require_once self::$fixturesPath.'/Foo3Command.php';
|
||||
}
|
||||
|
||||
protected function normalizeLineBreaks($text)
|
||||
{
|
||||
return str_replace(PHP_EOL, "\n", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the dynamic placeholders of the command help text with a static version.
|
||||
* The placeholder %command.full_name% includes the script path that is not predictable
|
||||
* and can not be tested against.
|
||||
*/
|
||||
protected function ensureStaticCommandHelp(Application $application)
|
||||
{
|
||||
foreach ($application->all() as $command) {
|
||||
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$application = new Application('foo', 'bar');
|
||||
$this->assertEquals('foo', $application->getName(), '__construct() takes the application name as its first argument');
|
||||
$this->assertEquals('bar', $application->getVersion(), '__construct() takes the application version as its first argument');
|
||||
$this->assertEquals(array('help', 'list'), array_keys($application->all()), '__construct() registered the help and list commands by default');
|
||||
}
|
||||
|
||||
public function testSetGetName()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setName('foo');
|
||||
$this->assertEquals('foo', $application->getName(), '->setName() sets the name of the application');
|
||||
}
|
||||
|
||||
public function testSetGetVersion()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setVersion('bar');
|
||||
$this->assertEquals('bar', $application->getVersion(), '->setVersion() sets the version of the application');
|
||||
}
|
||||
|
||||
public function testGetLongVersion()
|
||||
{
|
||||
$application = new Application('foo', 'bar');
|
||||
$this->assertEquals('<info>foo</info> version <comment>bar</comment>', $application->getLongVersion(), '->getLongVersion() returns the long version of the application');
|
||||
}
|
||||
|
||||
public function testHelp()
|
||||
{
|
||||
$application = new Application();
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_gethelp.txt', $this->normalizeLineBreaks($application->getHelp()), '->setHelp() returns a help message');
|
||||
}
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
$application = new Application();
|
||||
$commands = $application->all();
|
||||
$this->assertEquals('Symfony\\Component\\Console\\Command\\HelpCommand', get_class($commands['help']), '->all() returns the registered commands');
|
||||
|
||||
$application->add(new \FooCommand());
|
||||
$commands = $application->all('foo');
|
||||
$this->assertEquals(1, count($commands), '->all() takes a namespace as its first argument');
|
||||
}
|
||||
|
||||
public function testRegister()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = $application->register('foo');
|
||||
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add($foo = new \FooCommand());
|
||||
$commands = $application->all();
|
||||
$this->assertEquals($foo, $commands['foo:bar'], '->add() registers a command');
|
||||
|
||||
$application = new Application();
|
||||
$application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
|
||||
$commands = $application->all();
|
||||
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
|
||||
}
|
||||
|
||||
public function testHasGet()
|
||||
{
|
||||
$application = new Application();
|
||||
$this->assertTrue($application->has('list'), '->has() returns true if a named command is registered');
|
||||
$this->assertFalse($application->has('afoobar'), '->has() returns false if a named command is not registered');
|
||||
|
||||
$application->add($foo = new \FooCommand());
|
||||
$this->assertTrue($application->has('afoobar'), '->has() returns true if an alias is registered');
|
||||
$this->assertEquals($foo, $application->get('foo:bar'), '->get() returns a command by name');
|
||||
$this->assertEquals($foo, $application->get('afoobar'), '->get() returns a command by alias');
|
||||
|
||||
try {
|
||||
$application->get('foofoo');
|
||||
$this->fail('->get() throws an \InvalidArgumentException if the command does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws an \InvalidArgumentException if the command does not exist');
|
||||
$this->assertEquals('The command "foofoo" does not exist.', $e->getMessage(), '->get() throws an \InvalidArgumentException if the command does not exist');
|
||||
}
|
||||
|
||||
$application = new Application();
|
||||
$application->add($foo = new \FooCommand());
|
||||
// simulate --help
|
||||
$r = new \ReflectionObject($application);
|
||||
$p = $r->getProperty('wantHelps');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($application, true);
|
||||
$command = $application->get('foo:bar');
|
||||
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($command), '->get() returns the help command if --help is provided as the input');
|
||||
}
|
||||
|
||||
public function testGetNamespaces()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand());
|
||||
$application->add(new \Foo1Command());
|
||||
$this->assertEquals(array('foo'), $application->getNamespaces(), '->getNamespaces() returns an array of unique used namespaces');
|
||||
}
|
||||
|
||||
public function testFindNamespace()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand());
|
||||
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
|
||||
$this->assertEquals('foo', $application->findNamespace('f'), '->findNamespace() finds a namespace given an abbreviation');
|
||||
$application->add(new \Foo2Command());
|
||||
$this->assertEquals('foo', $application->findNamespace('foo'), '->findNamespace() returns the given namespace if it exists');
|
||||
try {
|
||||
$application->findNamespace('f');
|
||||
$this->fail('->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
|
||||
$this->assertEquals('The namespace "f" is ambiguous (foo, foo1).', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if the abbreviation is ambiguous');
|
||||
}
|
||||
|
||||
try {
|
||||
$application->findNamespace('bar');
|
||||
$this->fail('->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
|
||||
$this->assertEquals('There are no commands defined in the "bar" namespace.', $e->getMessage(), '->findNamespace() throws an \InvalidArgumentException if no command is in the given namespace');
|
||||
}
|
||||
}
|
||||
|
||||
public function testFind()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand());
|
||||
$this->assertEquals('FooCommand', get_class($application->find('foo:bar')), '->find() returns a command if its name exists');
|
||||
$this->assertEquals('Symfony\Component\Console\Command\HelpCommand', get_class($application->find('h')), '->find() returns a command if its name exists');
|
||||
$this->assertEquals('FooCommand', get_class($application->find('f:bar')), '->find() returns a command if the abbreviation for the namespace exists');
|
||||
$this->assertEquals('FooCommand', get_class($application->find('f:b')), '->find() returns a command if the abbreviation for the namespace and the command name exist');
|
||||
$this->assertEquals('FooCommand', get_class($application->find('a')), '->find() returns a command if the abbreviation exists for an alias');
|
||||
|
||||
$application->add(new \Foo1Command());
|
||||
$application->add(new \Foo2Command());
|
||||
|
||||
try {
|
||||
$application->find('f');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
|
||||
$this->assertRegExp('/Command "f" is not defined./', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a namespace');
|
||||
}
|
||||
|
||||
try {
|
||||
$application->find('a');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
|
||||
$this->assertEquals('Command "a" is ambiguous (afoobar, afoobar1 and 1 more).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for an alias');
|
||||
}
|
||||
|
||||
try {
|
||||
$application->find('foo:b');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
|
||||
$this->assertEquals('Command "foo:b" is ambiguous (foo:bar, foo:bar1).', $e->getMessage(), '->find() throws an \InvalidArgumentException if the abbreviation is ambiguous for a command');
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAlternativeExceptionMessage()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand());
|
||||
|
||||
// Command + singular
|
||||
try {
|
||||
$application->find('foo:baR');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
}
|
||||
|
||||
// Namespace + singular
|
||||
try {
|
||||
$application->find('foO:bar');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
$this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative');
|
||||
}
|
||||
|
||||
|
||||
$application->add(new \Foo1Command());
|
||||
$application->add(new \Foo2Command());
|
||||
|
||||
// Command + plural
|
||||
try {
|
||||
$application->find('foo:baR');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
}
|
||||
|
||||
// Namespace + plural
|
||||
try {
|
||||
$application->find('foo2:bar');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAlternativeCommands()
|
||||
{
|
||||
$application = new Application();
|
||||
|
||||
$application->add(new \FooCommand());
|
||||
$application->add(new \Foo1Command());
|
||||
$application->add(new \Foo2Command());
|
||||
|
||||
try {
|
||||
$application->find($commandName = 'Unknown command');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
|
||||
$this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without alternatives');
|
||||
}
|
||||
|
||||
try {
|
||||
$application->find($commandName = 'foo');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
|
||||
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
$this->assertRegExp('/foo:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar"');
|
||||
$this->assertRegExp('/foo1:bar/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo1:bar"');
|
||||
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
|
||||
}
|
||||
|
||||
// Test if "foo1" command throw an "\InvalidArgumentException" and does not contain
|
||||
// "foo:bar" as alternative because "foo1" is too far from "foo:bar"
|
||||
try {
|
||||
$application->find($commandName = 'foo1');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
|
||||
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
||||
$this->assertFalse(strpos($e->getMessage(), 'foo:bar'), '->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative');
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAlternativeNamespace()
|
||||
{
|
||||
$application = new Application();
|
||||
|
||||
$application->add(new \FooCommand());
|
||||
$application->add(new \Foo1Command());
|
||||
$application->add(new \Foo2Command());
|
||||
$application->add(new \foo3Command());
|
||||
|
||||
try {
|
||||
$application->find('Unknown-namespace:Unknown-command');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
|
||||
$this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, without alternatives');
|
||||
}
|
||||
|
||||
try {
|
||||
$application->find('foo2:command');
|
||||
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
|
||||
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative');
|
||||
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"');
|
||||
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
|
||||
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetCatchExceptions()
|
||||
{
|
||||
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
||||
$application->setAutoExit(false);
|
||||
$application->expects($this->any())
|
||||
->method('getTerminalWidth')
|
||||
->will($this->returnValue(120));
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$application->setCatchExceptions(true);
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->setCatchExceptions() sets the catch exception flag');
|
||||
|
||||
$application->setCatchExceptions(false);
|
||||
try {
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->fail('->setCatchExceptions() sets the catch exception flag');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag');
|
||||
$this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag');
|
||||
}
|
||||
}
|
||||
|
||||
public function testAsText()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand);
|
||||
$this->ensureStaticCommandHelp($application);
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext1.txt', $this->normalizeLineBreaks($application->asText()), '->asText() returns a text representation of the application');
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_astext2.txt', $this->normalizeLineBreaks($application->asText('foo')), '->asText() returns a text representation of the application');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooCommand);
|
||||
$this->ensureStaticCommandHelp($application);
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml1.txt', $application->asXml(), '->asXml() returns an XML representation of the application');
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/application_asxml2.txt', $application->asXml('foo'), '->asXml() returns an XML representation of the application');
|
||||
}
|
||||
|
||||
public function testRenderException()
|
||||
{
|
||||
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
||||
$application->setAutoExit(false);
|
||||
$application->expects($this->any())
|
||||
->method('getTerminalWidth')
|
||||
->will($this->returnValue(120));
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exception');
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
|
||||
$this->assertContains('Exception trace', $tester->getDisplay(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
|
||||
|
||||
$tester->run(array('command' => 'list', '--foo' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
|
||||
|
||||
$application->add(new \Foo3Command);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');
|
||||
|
||||
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
||||
$application->setAutoExit(false);
|
||||
$application->expects($this->any())
|
||||
->method('getTerminalWidth')
|
||||
->will($this->returnValue(32));
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
|
||||
$application->setAutoExit(false);
|
||||
$application->expects($this->any())
|
||||
->method('getTerminalWidth')
|
||||
->will($this->returnValue(32));
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->renderException() wraps messages when they are bigger than the terminal');
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$application->add($command = new \Foo1Command());
|
||||
$_SERVER['argv'] = array('cli.php', 'foo:bar1');
|
||||
|
||||
ob_start();
|
||||
$application->run();
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertSame('Symfony\Component\Console\Input\ArgvInput', get_class($command->input), '->run() creates an ArgvInput by default if none is given');
|
||||
$this->assertSame('Symfony\Component\Console\Output\ConsoleOutput', get_class($command->output), '->run() creates a ConsoleOutput by default if none is given');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
|
||||
$this->ensureStaticCommandHelp($application);
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array(), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run1.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the list command if no argument is passed');
|
||||
|
||||
$tester->run(array('--help' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if --help is passed');
|
||||
|
||||
$tester->run(array('-h' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() runs the help command if -h is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '--help' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if --help is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '-h' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run3.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the help if -h is passed');
|
||||
|
||||
$tester->run(array('--ansi' => true));
|
||||
$this->assertTrue($tester->getOutput()->isDecorated(), '->run() forces color output if --ansi is passed');
|
||||
|
||||
$tester->run(array('--no-ansi' => true));
|
||||
$this->assertFalse($tester->getOutput()->isDecorated(), '->run() forces color output to be disabled if --no-ansi is passed');
|
||||
|
||||
$tester->run(array('--version' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if --version is passed');
|
||||
|
||||
$tester->run(array('-V' => true), array('decorated' => false));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $this->normalizeLineBreaks($tester->getDisplay()), '->run() displays the program version if -v is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '--quiet' => true));
|
||||
$this->assertSame('', $tester->getDisplay(), '->run() removes all output if --quiet is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '-q' => true));
|
||||
$this->assertSame('', $tester->getDisplay(), '->run() removes all output if -q is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '--verbose' => true));
|
||||
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose is passed');
|
||||
|
||||
$tester->run(array('command' => 'list', '-v' => true));
|
||||
$this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$application->add(new \FooCommand());
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->run(array('command' => 'foo:bar', '--no-interaction' => true), array('decorated' => false));
|
||||
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if --no-interaction is passed');
|
||||
|
||||
$tester->run(array('command' => 'foo:bar', '-n' => true), array('decorated' => false));
|
||||
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @dataProvider getAddingAlreadySetDefinitionElementData
|
||||
*/
|
||||
public function testAddingAlreadySetDefinitionElementData($def)
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
$application
|
||||
->register('foo')
|
||||
->setDefinition(array($def))
|
||||
->setCode(function (InputInterface $input, OutputInterface $output) {})
|
||||
;
|
||||
|
||||
$input = new ArrayInput(array('command' => 'foo'));
|
||||
$output = new NullOutput();
|
||||
$application->run($input, $output);
|
||||
}
|
||||
|
||||
public function getAddingAlreadySetDefinitionElementData()
|
||||
{
|
||||
return array(
|
||||
array(new InputArgument('command', InputArgument::REQUIRED)),
|
||||
array(new InputOption('quiet', '', InputOption::VALUE_NONE)),
|
||||
array(new InputOption('query', 'q', InputOption::VALUE_NONE)),
|
||||
);
|
||||
}
|
||||
}
|
||||
253
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/CommandTest.php
vendored
Normal file
253
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/CommandTest.php
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class CommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $fixturesPath;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixturesPath = __DIR__.'/../Fixtures/';
|
||||
require_once self::$fixturesPath.'/TestCommand.php';
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
try {
|
||||
$command = new Command();
|
||||
$this->fail('__construct() throws a \LogicException if the name is null');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\LogicException', $e, '__construct() throws a \LogicException if the name is null');
|
||||
$this->assertEquals('The command name cannot be empty.', $e->getMessage(), '__construct() throws a \LogicException if the name is null');
|
||||
}
|
||||
$command = new Command('foo:bar');
|
||||
$this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument');
|
||||
}
|
||||
|
||||
public function testSetApplication()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application);
|
||||
$this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application');
|
||||
}
|
||||
|
||||
public function testSetGetDefinition()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->setDefinition($definition = new InputDefinition());
|
||||
$this->assertEquals($command, $ret, '->setDefinition() implements a fluent interface');
|
||||
$this->assertEquals($definition, $command->getDefinition(), '->setDefinition() sets the current InputDefinition instance');
|
||||
$command->setDefinition(array(new InputArgument('foo'), new InputOption('bar')));
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->setDefinition() also takes an array of InputArguments and InputOptions as an argument');
|
||||
$command->setDefinition(new InputDefinition());
|
||||
}
|
||||
|
||||
public function testAddArgument()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->addArgument('foo');
|
||||
$this->assertEquals($command, $ret, '->addArgument() implements a fluent interface');
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->addArgument() adds an argument to the command');
|
||||
}
|
||||
|
||||
public function testAddOption()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->addOption('foo');
|
||||
$this->assertEquals($command, $ret, '->addOption() implements a fluent interface');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('foo'), '->addOption() adds an option to the command');
|
||||
}
|
||||
|
||||
public function testGetNamespaceGetNameSetName()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals('namespace:name', $command->getName(), '->getName() returns the command name');
|
||||
$command->setName('foo');
|
||||
$this->assertEquals('foo', $command->getName(), '->setName() sets the command name');
|
||||
|
||||
$ret = $command->setName('foobar:bar');
|
||||
$this->assertEquals($command, $ret, '->setName() implements a fluent interface');
|
||||
$this->assertEquals('foobar:bar', $command->getName(), '->setName() sets the command name');
|
||||
|
||||
try {
|
||||
$command->setName('');
|
||||
$this->fail('->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
$this->assertEquals('Command name "" is invalid.', $e->getMessage(), '->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
}
|
||||
|
||||
try {
|
||||
$command->setName('foo:');
|
||||
$this->fail('->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
$this->assertEquals('Command name "foo:" is invalid.', $e->getMessage(), '->setName() throws an \InvalidArgumentException if the name is empty');
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSetDescription()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals('description', $command->getDescription(), '->getDescription() returns the description');
|
||||
$ret = $command->setDescription('description1');
|
||||
$this->assertEquals($command, $ret, '->setDescription() implements a fluent interface');
|
||||
$this->assertEquals('description1', $command->getDescription(), '->setDescription() sets the description');
|
||||
}
|
||||
|
||||
public function testGetSetHelp()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals('help', $command->getHelp(), '->getHelp() returns the help');
|
||||
$ret = $command->setHelp('help1');
|
||||
$this->assertEquals($command, $ret, '->setHelp() implements a fluent interface');
|
||||
$this->assertEquals('help1', $command->getHelp(), '->setHelp() sets the help');
|
||||
}
|
||||
|
||||
public function testGetProcessedHelp()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$command->setHelp('The %command.name% command does... Example: php %command.full_name%.');
|
||||
$this->assertContains('The namespace:name command does...', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.name% correctly');
|
||||
$this->assertNotContains('%command.full_name%', $command->getProcessedHelp(), '->getProcessedHelp() replaces %command.full_name%');
|
||||
}
|
||||
|
||||
public function testGetSetAliases()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$this->assertEquals(array('name'), $command->getAliases(), '->getAliases() returns the aliases');
|
||||
$ret = $command->setAliases(array('name1'));
|
||||
$this->assertEquals($command, $ret, '->setAliases() implements a fluent interface');
|
||||
$this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases');
|
||||
}
|
||||
|
||||
public function testGetSynopsis()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$command->addOption('foo');
|
||||
$command->addArgument('foo');
|
||||
$this->assertEquals('namespace:name [--foo] [foo]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
|
||||
}
|
||||
|
||||
public function testGetHelper()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application);
|
||||
$formatterHelper = new FormatterHelper();
|
||||
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->getHelper() returns the correct helper');
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$application = new Application();
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application);
|
||||
$formatterHelper = new FormatterHelper();
|
||||
$this->assertEquals($formatterHelper->getName(), $command->getHelper('formatter')->getName(), '->__get() returns the correct helper');
|
||||
}
|
||||
|
||||
public function testMergeApplicationDefinition()
|
||||
{
|
||||
$application1 = new Application();
|
||||
$application1->getDefinition()->addArguments(array(new InputArgument('foo')));
|
||||
$application1->getDefinition()->addOptions(array(new InputOption('bar')));
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication($application1);
|
||||
$command->setDefinition($definition = new InputDefinition(array(new InputArgument('bar'), new InputOption('foo'))));
|
||||
|
||||
$r = new \ReflectionObject($command);
|
||||
$m = $r->getMethod('mergeApplicationDefinition');
|
||||
$m->setAccessible(true);
|
||||
$m->invoke($command);
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
|
||||
$this->assertTrue($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options');
|
||||
$this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options');
|
||||
|
||||
$m->invoke($command);
|
||||
$this->assertEquals(3, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments and options');
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$tester = new CommandTester($command);
|
||||
try {
|
||||
$tester->execute(array('--bar' => true));
|
||||
$this->fail('->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
|
||||
$this->assertEquals('The "--bar" option does not exist.', $e->getMessage(), '->run() throws a \InvalidArgumentException when the input does not validate the current InputDefinition');
|
||||
}
|
||||
|
||||
$tester->execute(array(), array('interactive' => true));
|
||||
$this->assertEquals('interact called'.PHP_EOL.'execute called'.PHP_EOL, $tester->getDisplay(), '->run() calls the interact() method if the input is interactive');
|
||||
|
||||
$tester->execute(array(), array('interactive' => false));
|
||||
$this->assertEquals('execute called'.PHP_EOL, $tester->getDisplay(), '->run() does not call the interact() method if the input is not interactive');
|
||||
|
||||
$command = new Command('foo');
|
||||
try {
|
||||
$command->run(new StringInput(''), new NullOutput());
|
||||
$this->fail('->run() throws a \LogicException if the execute() method has not been overridden and no code has been provided');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\LogicException', $e, '->run() throws a \LogicException if the execute() method has not been overridden and no code has been provided');
|
||||
$this->assertEquals('You must override the execute() method in the concrete command class.', $e->getMessage(), '->run() throws a \LogicException if the execute() method has not been overridden and no code has been provided');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetCode()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$ret = $command->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$output->writeln('from the code...');
|
||||
});
|
||||
$this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
$this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testAsText()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array('command' => $command->getName()));
|
||||
$this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
{
|
||||
$command = new \TestCommand();
|
||||
$command->setApplication(new Application());
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array('command' => $command->getName()));
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
|
||||
}
|
||||
}
|
||||
42
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/HelpCommandTest.php
vendored
Normal file
42
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/HelpCommandTest.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Command\HelpCommand;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
class HelpCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testExecute()
|
||||
{
|
||||
$command = new HelpCommand();
|
||||
|
||||
$commandTester = new CommandTester($command);
|
||||
$command->setCommand(new ListCommand());
|
||||
$commandTester->execute(array());
|
||||
$this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
|
||||
$command->setCommand(new ListCommand());
|
||||
$commandTester->execute(array('--xml' => true));
|
||||
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
|
||||
|
||||
$application = new Application();
|
||||
$commandTester = new CommandTester($application->get('help'));
|
||||
$commandTester->execute(array('command_name' => 'list'));
|
||||
$this->assertRegExp('/list \[--xml\] \[--raw\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
|
||||
|
||||
$commandTester->execute(array('command_name' => 'list', '--xml' => true));
|
||||
$this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
|
||||
}
|
||||
}
|
||||
38
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/ListCommandTest.php
vendored
Normal file
38
core/vendor/symfony/console/Symfony/Component/Console/Tests/Command/ListCommandTest.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
class ListCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testExecute()
|
||||
{
|
||||
$application = new Application();
|
||||
|
||||
$commandTester = new CommandTester($command = $application->get('list'));
|
||||
$commandTester->execute(array('command' => $command->getName()), array('decorated' => false));
|
||||
$this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
|
||||
|
||||
$commandTester->execute(array('command' => $command->getName(), '--xml' => true));
|
||||
$this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
|
||||
|
||||
$commandTester->execute(array('command' => $command->getName(), '--raw' => true));
|
||||
$output = <<<EOF
|
||||
help Displays help for a command
|
||||
list Lists commands
|
||||
|
||||
EOF;
|
||||
$this->assertEquals(str_replace("\n", PHP_EOL, $output), $commandTester->getDisplay(), 'boo');
|
||||
}
|
||||
}
|
||||
26
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php
vendored
Normal file
26
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Foo1Command extends Command
|
||||
{
|
||||
public $input;
|
||||
public $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('foo:bar1')
|
||||
->setDescription('The foo:bar1 command')
|
||||
->setAliases(array('afoobar1'))
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
}
|
||||
}
|
||||
21
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php
vendored
Normal file
21
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Foo2Command extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('foo1:bar')
|
||||
->setDescription('The foo1:bar command')
|
||||
->setAliases(array('afoobar2'))
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
}
|
||||
}
|
||||
25
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php
vendored
Normal file
25
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Foo3Command extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('foo3:bar')
|
||||
->setDescription('The foo3:bar command')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
try {
|
||||
throw new \Exception("First exception");
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception("Second exception", 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/FooCommand.php
vendored
Normal file
33
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/FooCommand.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class FooCommand extends Command
|
||||
{
|
||||
public $input;
|
||||
public $output;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('foo:bar')
|
||||
->setDescription('The foo:bar command')
|
||||
->setAliases(array('afoobar'))
|
||||
;
|
||||
}
|
||||
|
||||
protected function interact(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('interact called');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
|
||||
$output->writeln('called');
|
||||
}
|
||||
}
|
||||
28
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/TestCommand.php
vendored
Normal file
28
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/TestCommand.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class TestCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('namespace:name')
|
||||
->setAliases(array('name'))
|
||||
->setDescription('description')
|
||||
->setHelp('help')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('execute called');
|
||||
}
|
||||
|
||||
protected function interact(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('interact called');
|
||||
}
|
||||
}
|
||||
20
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt
vendored
Normal file
20
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<info>Console Tool</info>
|
||||
|
||||
<comment>Usage:</comment>
|
||||
[options] command [arguments]
|
||||
|
||||
<comment>Options:</comment>
|
||||
<info>--help</info> <info>-h</info> Display this help message.
|
||||
<info>--quiet</info> <info>-q</info> Do not output any message.
|
||||
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
|
||||
<info>--version</info> <info>-V</info> Display this application version.
|
||||
<info>--ansi</info> Force ANSI output.
|
||||
<info>--no-ansi</info> Disable ANSI output.
|
||||
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
|
||||
|
||||
<comment>Available commands:</comment>
|
||||
<info>afoobar </info> The foo:bar command
|
||||
<info>help </info> Displays help for a command
|
||||
<info>list </info> Lists commands
|
||||
<comment>foo</comment>
|
||||
<info>foo:bar </info> The foo:bar command
|
||||
16
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt
vendored
Normal file
16
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<info>Console Tool</info>
|
||||
|
||||
<comment>Usage:</comment>
|
||||
[options] command [arguments]
|
||||
|
||||
<comment>Options:</comment>
|
||||
<info>--help</info> <info>-h</info> Display this help message.
|
||||
<info>--quiet</info> <info>-q</info> Do not output any message.
|
||||
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
|
||||
<info>--version</info> <info>-V</info> Display this application version.
|
||||
<info>--ansi</info> Force ANSI output.
|
||||
<info>--no-ansi</info> Disable ANSI output.
|
||||
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
|
||||
|
||||
<comment>Available commands for the "foo" namespace:</comment>
|
||||
<info>foo:bar </info> The foo:bar command
|
||||
83
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt
vendored
Normal file
83
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<symfony>
|
||||
<commands>
|
||||
<command id="help" name="help">
|
||||
<usage>help [--xml] [command_name]</usage>
|
||||
<description>Displays help for a command</description>
|
||||
<help>The <info>help</info> command displays help for a given command:
|
||||
|
||||
<info>php app/console help list</info>
|
||||
|
||||
You can also output the help as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php app/console help --xml list</info></help>
|
||||
<aliases />
|
||||
<arguments>
|
||||
<argument name="command_name" is_required="0" is_array="0">
|
||||
<description>The command name</description>
|
||||
<defaults>
|
||||
<default>help</default>
|
||||
</defaults>
|
||||
</argument>
|
||||
</arguments>
|
||||
<options>
|
||||
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>To output help as XML</description>
|
||||
</option>
|
||||
</options>
|
||||
</command>
|
||||
<command id="list" name="list">
|
||||
<usage>list [--xml] [--raw] [namespace]</usage>
|
||||
<description>Lists commands</description>
|
||||
<help>The <info>list</info> command lists all commands:
|
||||
|
||||
<info>php app/console list</info>
|
||||
|
||||
You can also display the commands for a specific namespace:
|
||||
|
||||
<info>php app/console list test</info>
|
||||
|
||||
You can also output the information as XML by using the <comment>--xml</comment> option:
|
||||
|
||||
<info>php app/console list --xml</info>
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
<info>php app/console list --raw</info></help>
|
||||
<aliases/>
|
||||
<arguments>
|
||||
<argument name="namespace" is_required="0" is_array="0">
|
||||
<description>The namespace name</description>
|
||||
<defaults/>
|
||||
</argument>
|
||||
</arguments>
|
||||
<options>
|
||||
<option name="--xml" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>To output help as XML</description>
|
||||
</option>
|
||||
<option name="--raw" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>To output raw command list</description>
|
||||
</option>
|
||||
</options>
|
||||
</command>
|
||||
<command id="foo:bar" name="foo:bar">
|
||||
<usage>foo:bar</usage>
|
||||
<description>The foo:bar command</description>
|
||||
<help/>
|
||||
<aliases>
|
||||
<alias>afoobar</alias>
|
||||
</aliases>
|
||||
<arguments/>
|
||||
<options/>
|
||||
</command>
|
||||
</commands>
|
||||
<namespaces>
|
||||
<namespace id="_global">
|
||||
<command>help</command>
|
||||
<command>list</command>
|
||||
</namespace>
|
||||
<namespace id="foo">
|
||||
<command>foo:bar</command>
|
||||
</namespace>
|
||||
</namespaces>
|
||||
</symfony>
|
||||
15
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt
vendored
Normal file
15
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<symfony>
|
||||
<commands namespace="foo">
|
||||
<command id="foo:bar" name="foo:bar">
|
||||
<usage>foo:bar</usage>
|
||||
<description>The foo:bar command</description>
|
||||
<help/>
|
||||
<aliases>
|
||||
<alias>afoobar</alias>
|
||||
</aliases>
|
||||
<arguments/>
|
||||
<options/>
|
||||
</command>
|
||||
</commands>
|
||||
</symfony>
|
||||
13
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_gethelp.txt
vendored
Normal file
13
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_gethelp.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<info>Console Tool</info>
|
||||
|
||||
<comment>Usage:</comment>
|
||||
[options] command [arguments]
|
||||
|
||||
<comment>Options:</comment>
|
||||
<info>--help</info> <info>-h</info> Display this help message.
|
||||
<info>--quiet</info> <info>-q</info> Do not output any message.
|
||||
<info>--verbose</info> <info>-v</info> Increase verbosity of messages.
|
||||
<info>--version</info> <info>-V</info> Display this application version.
|
||||
<info>--ansi</info> Force ANSI output.
|
||||
<info>--no-ansi</info> Disable ANSI output.
|
||||
<info>--no-interaction</info> <info>-n</info> Do not ask any interactive question.
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
|
||||
[InvalidArgumentException]
|
||||
Command "foo" is not defined.
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
|
||||
[InvalidArgumentException]
|
||||
The "--foo" option does not exist.
|
||||
|
||||
|
||||
|
||||
list [--xml] [--raw] [namespace]
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
|
||||
[Exception]
|
||||
Second exception
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Exception]
|
||||
First exception
|
||||
|
||||
|
||||
|
||||
foo3:bar
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
|
||||
[InvalidArgumentException]
|
||||
Command "foo" is not define
|
||||
d.
|
||||
|
||||
|
||||
|
||||
17
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run1.txt
vendored
Normal file
17
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run1.txt
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
Console Tool
|
||||
|
||||
Usage:
|
||||
[options] command [arguments]
|
||||
|
||||
Options:
|
||||
--help -h Display this help message.
|
||||
--quiet -q Do not output any message.
|
||||
--verbose -v Increase verbosity of messages.
|
||||
--version -V Display this application version.
|
||||
--ansi Force ANSI output.
|
||||
--no-ansi Disable ANSI output.
|
||||
--no-interaction -n Do not ask any interactive question.
|
||||
|
||||
Available commands:
|
||||
help Displays help for a command
|
||||
list Lists commands
|
||||
26
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run2.txt
vendored
Normal file
26
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run2.txt
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
Usage:
|
||||
help [--xml] [command_name]
|
||||
|
||||
Arguments:
|
||||
command The command to execute
|
||||
command_name The command name (default: "help")
|
||||
|
||||
Options:
|
||||
--xml To output help as XML
|
||||
--help (-h) Display this help message.
|
||||
--quiet (-q) Do not output any message.
|
||||
--verbose (-v) Increase verbosity of messages.
|
||||
--version (-V) Display this application version.
|
||||
--ansi Force ANSI output.
|
||||
--no-ansi Disable ANSI output.
|
||||
--no-interaction (-n) Do not ask any interactive question.
|
||||
|
||||
Help:
|
||||
The help command displays help for a given command:
|
||||
|
||||
php app/console help list
|
||||
|
||||
You can also output the help as XML by using the --xml option:
|
||||
|
||||
php app/console help --xml list
|
||||
|
||||
27
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run3.txt
vendored
Normal file
27
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run3.txt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Usage:
|
||||
list [--xml] [--raw] [namespace]
|
||||
|
||||
Arguments:
|
||||
namespace The namespace name
|
||||
|
||||
Options:
|
||||
--xml To output help as XML
|
||||
--raw To output raw command list
|
||||
|
||||
Help:
|
||||
The list command lists all commands:
|
||||
|
||||
php app/console list
|
||||
|
||||
You can also display the commands for a specific namespace:
|
||||
|
||||
php app/console list test
|
||||
|
||||
You can also output the information as XML by using the --xml option:
|
||||
|
||||
php app/console list --xml
|
||||
|
||||
It's also possible to get raw list of commands (useful for embedding command runner):
|
||||
|
||||
php app/console list --raw
|
||||
|
||||
1
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run4.txt
vendored
Normal file
1
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/application_run4.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Console Tool
|
||||
18
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/command_astext.txt
vendored
Normal file
18
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/command_astext.txt
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<comment>Usage:</comment>
|
||||
namespace:name
|
||||
|
||||
<comment>Aliases:</comment> <info>name</info>
|
||||
<comment>Arguments:</comment>
|
||||
<info>command </info> The command to execute
|
||||
|
||||
<comment>Options:</comment>
|
||||
<info>--help</info> (-h) Display this help message.
|
||||
<info>--quiet</info> (-q) Do not output any message.
|
||||
<info>--verbose</info> (-v) Increase verbosity of messages.
|
||||
<info>--version</info> (-V) Display this application version.
|
||||
<info>--ansi</info> Force ANSI output.
|
||||
<info>--no-ansi</info> Disable ANSI output.
|
||||
<info>--no-interaction</info> (-n) Do not ask any interactive question.
|
||||
|
||||
<comment>Help:</comment>
|
||||
help
|
||||
38
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt
vendored
Normal file
38
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<command id="namespace:name" name="namespace:name">
|
||||
<usage>namespace:name</usage>
|
||||
<description>description</description>
|
||||
<help>help</help>
|
||||
<aliases>
|
||||
<alias>name</alias>
|
||||
</aliases>
|
||||
<arguments>
|
||||
<argument name="command" is_required="1" is_array="0">
|
||||
<description>The command to execute</description>
|
||||
<defaults/>
|
||||
</argument>
|
||||
</arguments>
|
||||
<options>
|
||||
<option name="--help" shortcut="-h" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Display this help message.</description>
|
||||
</option>
|
||||
<option name="--quiet" shortcut="-q" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Do not output any message.</description>
|
||||
</option>
|
||||
<option name="--verbose" shortcut="-v" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Increase verbosity of messages.</description>
|
||||
</option>
|
||||
<option name="--version" shortcut="-V" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Display this application version.</description>
|
||||
</option>
|
||||
<option name="--ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Force ANSI output.</description>
|
||||
</option>
|
||||
<option name="--no-ansi" shortcut="" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Disable ANSI output.</description>
|
||||
</option>
|
||||
<option name="--no-interaction" shortcut="-n" accept_value="0" is_value_required="0" is_multiple="0">
|
||||
<description>Do not ask any interactive question.</description>
|
||||
</option>
|
||||
</options>
|
||||
</command>
|
||||
11
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt
vendored
Normal file
11
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<comment>Arguments:</comment>
|
||||
<info>foo </info> The foo argument
|
||||
<info>baz </info> The baz argument<comment> (default: true)</comment>
|
||||
<info>bar </info> The bar argument<comment> (default: ["bar"])</comment>
|
||||
|
||||
<comment>Options:</comment>
|
||||
<info>--foo</info> (-f) The foo option
|
||||
<info>--baz</info> The baz option<comment> (default: false)</comment>
|
||||
<info>--bar</info> (-b) The bar option<comment> (default: "bar")</comment>
|
||||
<info>--qux</info> The qux option<comment> (default: ["foo","bar"])</comment><comment> (multiple values allowed)</comment>
|
||||
<info>--qux2</info> The qux2 option<comment> (default: {"foo":"bar"})</comment><comment> (multiple values allowed)</comment>
|
||||
39
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt
vendored
Normal file
39
core/vendor/symfony/console/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<definition>
|
||||
<arguments>
|
||||
<argument name="foo" is_required="0" is_array="0">
|
||||
<description>The foo argument</description>
|
||||
<defaults/>
|
||||
</argument>
|
||||
<argument name="baz" is_required="0" is_array="0">
|
||||
<description>The baz argument</description>
|
||||
<defaults>
|
||||
<default>true</default>
|
||||
</defaults>
|
||||
</argument>
|
||||
<argument name="bar" is_required="0" is_array="1">
|
||||
<description>The bar argument</description>
|
||||
<defaults>
|
||||
<default>bar</default>
|
||||
</defaults>
|
||||
</argument>
|
||||
</arguments>
|
||||
<options>
|
||||
<option name="--foo" shortcut="-f" accept_value="1" is_value_required="1" is_multiple="0">
|
||||
<description>The foo option</description>
|
||||
<defaults/>
|
||||
</option>
|
||||
<option name="--baz" shortcut="" accept_value="1" is_value_required="0" is_multiple="0">
|
||||
<description>The baz option</description>
|
||||
<defaults>
|
||||
<default>false</default>
|
||||
</defaults>
|
||||
</option>
|
||||
<option name="--bar" shortcut="-b" accept_value="1" is_value_required="0" is_multiple="0">
|
||||
<description>The bar option</description>
|
||||
<defaults>
|
||||
<default>bar</default>
|
||||
</defaults>
|
||||
</option>
|
||||
</options>
|
||||
</definition>
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Formatter;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class OutputFormatterStyleStackTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testPush()
|
||||
{
|
||||
$stack = new OutputFormatterStyleStack();
|
||||
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
|
||||
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
|
||||
|
||||
$this->assertEquals($s2, $stack->getCurrent());
|
||||
|
||||
$stack->push($s3 = new OutputFormatterStyle('green', 'red'));
|
||||
|
||||
$this->assertEquals($s3, $stack->getCurrent());
|
||||
}
|
||||
|
||||
public function testPop()
|
||||
{
|
||||
$stack = new OutputFormatterStyleStack();
|
||||
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
|
||||
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
|
||||
|
||||
$this->assertEquals($s2, $stack->pop());
|
||||
$this->assertEquals($s1, $stack->pop());
|
||||
}
|
||||
|
||||
public function testPopEmpty()
|
||||
{
|
||||
$stack = new OutputFormatterStyleStack();
|
||||
$style = new OutputFormatterStyle();
|
||||
|
||||
$this->assertEquals($style, $stack->pop());
|
||||
}
|
||||
|
||||
public function testPopNotLast()
|
||||
{
|
||||
$stack = new OutputFormatterStyleStack();
|
||||
$stack->push($s1 = new OutputFormatterStyle('white', 'black'));
|
||||
$stack->push($s2 = new OutputFormatterStyle('yellow', 'blue'));
|
||||
$stack->push($s3 = new OutputFormatterStyle('green', 'red'));
|
||||
|
||||
$this->assertEquals($s2, $stack->pop($s2));
|
||||
$this->assertEquals($s1, $stack->pop());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidPop()
|
||||
{
|
||||
$stack = new OutputFormatterStyleStack();
|
||||
$stack->push(new OutputFormatterStyle('white', 'black'));
|
||||
$stack->pop(new OutputFormatterStyle('yellow', 'blue'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Formatter;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$style = new OutputFormatterStyle('green', 'black', array('bold', 'underscore'));
|
||||
$this->assertEquals("\033[32;40;1;4mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style = new OutputFormatterStyle('red', null, array('blink'));
|
||||
$this->assertEquals("\033[31;5mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style = new OutputFormatterStyle(null, 'white');
|
||||
$this->assertEquals("\033[47mfoo\033[0m", $style->apply('foo'));
|
||||
}
|
||||
|
||||
public function testForeground()
|
||||
{
|
||||
$style = new OutputFormatterStyle();
|
||||
|
||||
$style->setForeground('black');
|
||||
$this->assertEquals("\033[30mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->setForeground('blue');
|
||||
$this->assertEquals("\033[34mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$style->setForeground('undefined-color');
|
||||
}
|
||||
|
||||
public function testBackground()
|
||||
{
|
||||
$style = new OutputFormatterStyle();
|
||||
|
||||
$style->setBackground('black');
|
||||
$this->assertEquals("\033[40mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->setBackground('yellow');
|
||||
$this->assertEquals("\033[43mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$style->setBackground('undefined-color');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$style = new OutputFormatterStyle();
|
||||
|
||||
$style->setOptions(array('reverse', 'conceal'));
|
||||
$this->assertEquals("\033[7;8mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->setOption('bold');
|
||||
$this->assertEquals("\033[7;8;1mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->unsetOption('reverse');
|
||||
$this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->setOption('bold');
|
||||
$this->assertEquals("\033[8;1mfoo\033[0m", $style->apply('foo'));
|
||||
|
||||
$style->setOptions(array('bold'));
|
||||
$this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));
|
||||
}
|
||||
}
|
||||
212
core/vendor/symfony/console/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php
vendored
Normal file
212
core/vendor/symfony/console/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Formatter;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class FormatterStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmptyTag()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
$this->assertEquals("foo<>bar", $formatter->format('foo<>bar'));
|
||||
}
|
||||
|
||||
public function testLGCharEscaping()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertEquals("foo<bar", $formatter->format('foo\\<bar'));
|
||||
$this->assertEquals("<info>some info</info>", $formatter->format('\\<info>some info\\</info>'));
|
||||
$this->assertEquals("\\<info>some info\\</info>", OutputFormatter::escape('<info>some info</info>'));
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[33mSymfony\\Component\\Console does work very well!\033[0m",
|
||||
$formatter->format('<comment>Symfony\Component\Console does work very well!</comment>')
|
||||
);
|
||||
}
|
||||
|
||||
public function testBundledStyles()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertTrue($formatter->hasStyle('error'));
|
||||
$this->assertTrue($formatter->hasStyle('info'));
|
||||
$this->assertTrue($formatter->hasStyle('comment'));
|
||||
$this->assertTrue($formatter->hasStyle('question'));
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[37;41msome error\033[0m",
|
||||
$formatter->format('<error>some error</error>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[32msome info\033[0m",
|
||||
$formatter->format('<info>some info</info>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[33msome comment\033[0m",
|
||||
$formatter->format('<comment>some comment</comment>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[30;46msome question\033[0m",
|
||||
$formatter->format('<question>some question</question>')
|
||||
);
|
||||
}
|
||||
|
||||
public function testNestedStyles()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[37;41msome \033[0m\033[32msome info\033[0m\033[37;41m error\033[0m",
|
||||
$formatter->format('<error>some <info>some info</info> error</error>')
|
||||
);
|
||||
}
|
||||
|
||||
public function testDeepNestedStyles()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[37;41merror\033[0m\033[32minfo\033[0m\033[33mcomment\033[0m\033[37;41merror\033[0m",
|
||||
$formatter->format('<error>error<info>info<comment>comment</info>error</error>')
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewStyle()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$style = new OutputFormatterStyle('blue', 'white');
|
||||
$formatter->setStyle('test', $style);
|
||||
|
||||
$this->assertEquals($style, $formatter->getStyle('test'));
|
||||
$this->assertNotEquals($style, $formatter->getStyle('info'));
|
||||
|
||||
$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<test>some custom msg</test>'));
|
||||
}
|
||||
|
||||
public function testRedefineStyle()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$style = new OutputFormatterStyle('blue', 'white');
|
||||
$formatter->setStyle('info', $style);
|
||||
|
||||
$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<info>some custom msg</info>'));
|
||||
}
|
||||
|
||||
public function testInlineStyle()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('<fg=blue;bg=red>some text</>'));
|
||||
$this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('<fg=blue;bg=red>some text</fg=blue;bg=red>'));
|
||||
}
|
||||
|
||||
public function testNonStyleTag()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled\033[0m", $formatter->format('<info>some <tag> styled</info>'));
|
||||
}
|
||||
|
||||
public function testNotDecoratedFormatter()
|
||||
{
|
||||
$formatter = new OutputFormatter(false);
|
||||
|
||||
$this->assertTrue($formatter->hasStyle('error'));
|
||||
$this->assertTrue($formatter->hasStyle('info'));
|
||||
$this->assertTrue($formatter->hasStyle('comment'));
|
||||
$this->assertTrue($formatter->hasStyle('question'));
|
||||
|
||||
$this->assertEquals(
|
||||
"some error", $formatter->format('<error>some error</error>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"some info", $formatter->format('<info>some info</info>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"some comment", $formatter->format('<comment>some comment</comment>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"some question", $formatter->format('<question>some question</question>')
|
||||
);
|
||||
|
||||
$formatter->setDecorated(true);
|
||||
|
||||
$this->assertEquals(
|
||||
"\033[37;41msome error\033[0m", $formatter->format('<error>some error</error>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[32msome info\033[0m", $formatter->format('<info>some info</info>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[33msome comment\033[0m", $formatter->format('<comment>some comment</comment>')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"\033[30;46msome question\033[0m", $formatter->format('<question>some question</question>')
|
||||
);
|
||||
}
|
||||
|
||||
public function testContentWithLineBreaks()
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
|
||||
$this->assertEquals(<<<EOF
|
||||
\033[32m
|
||||
some text\033[0m
|
||||
EOF
|
||||
, $formatter->format(<<<EOF
|
||||
<info>
|
||||
some text</info>
|
||||
EOF
|
||||
));
|
||||
|
||||
$this->assertEquals(<<<EOF
|
||||
\033[32msome text
|
||||
\033[0m
|
||||
EOF
|
||||
, $formatter->format(<<<EOF
|
||||
<info>some text
|
||||
</info>
|
||||
EOF
|
||||
));
|
||||
|
||||
$this->assertEquals(<<<EOF
|
||||
\033[32m
|
||||
some text
|
||||
\033[0m
|
||||
EOF
|
||||
, $formatter->format(<<<EOF
|
||||
<info>
|
||||
some text
|
||||
</info>
|
||||
EOF
|
||||
));
|
||||
|
||||
$this->assertEquals(<<<EOF
|
||||
\033[32m
|
||||
some text
|
||||
more text
|
||||
\033[0m
|
||||
EOF
|
||||
, $formatter->format(<<<EOF
|
||||
<info>
|
||||
some text
|
||||
more text
|
||||
</info>
|
||||
EOF
|
||||
));
|
||||
}
|
||||
}
|
||||
93
core/vendor/symfony/console/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php
vendored
Normal file
93
core/vendor/symfony/console/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\DialogHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class DialogHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testAsk()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n8AM\n"));
|
||||
|
||||
$this->assertEquals('2PM', $dialog->ask($this->getOutputStream(), 'What time is it?', '2PM'));
|
||||
$this->assertEquals('8AM', $dialog->ask($output = $this->getOutputStream(), 'What time is it?', '2PM'));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('What time is it?', stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAskConfirmation()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n\n"));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?'));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("y\nyes\n"));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
$this->assertTrue($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', false));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("n\nno\n"));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', true));
|
||||
$this->assertFalse($dialog->askConfirmation($this->getOutputStream(), 'Do you like French fries?', true));
|
||||
}
|
||||
|
||||
public function testAskAndValidate()
|
||||
{
|
||||
$dialog = new DialogHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question ='What color was the white horse of Henry IV?';
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
return $color;
|
||||
};
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\nblack\n"));
|
||||
$this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
$this->assertEquals('black', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
|
||||
try {
|
||||
$this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white'));
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals($error, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
{
|
||||
$stream = fopen('php://memory', 'r+', false);
|
||||
fputs($stream, $input);
|
||||
rewind($stream);
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
||||
protected function getOutputStream()
|
||||
{
|
||||
return new StreamOutput(fopen('php://memory', 'r+', false));
|
||||
}
|
||||
}
|
||||
84
core/vendor/symfony/console/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php
vendored
Normal file
84
core/vendor/symfony/console/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
|
||||
class FormatterHelperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFormatSection()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<info>[cli]</info> Some text to display',
|
||||
$formatter->formatSection('cli', 'Some text to display'),
|
||||
'::formatSection() formats a message in a section'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlock()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> Some text to display </error>',
|
||||
$formatter->formatBlock('Some text to display', 'error'),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> Some text to display </error>' . "\n" .
|
||||
'<error> foo bar </error>',
|
||||
$formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>' . "\n" .
|
||||
'<error> Some text to display </error>' . "\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('Some text to display', 'error', true),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlockWithDiacriticLetters()
|
||||
{
|
||||
if (!extension_loaded('mbstring')) {
|
||||
$this->markTestSkipped('This test requires mbstring to work.');
|
||||
}
|
||||
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>' . "\n" .
|
||||
'<error> Du texte à afficher </error>' . "\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('Du texte à afficher', 'error', true),
|
||||
'::formatBlock() formats a message in a block'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBlockLGEscaping()
|
||||
{
|
||||
$formatter = new FormatterHelper();
|
||||
|
||||
$this->assertEquals(
|
||||
'<error> </error>' . "\n" .
|
||||
'<error> \<info>some info\</info> </error>' . "\n" .
|
||||
'<error> </error>',
|
||||
$formatter->formatBlock('<info>some info</info>', 'error', true),
|
||||
'::formatBlock() escapes \'<\' chars'
|
||||
);
|
||||
}
|
||||
}
|
||||
217
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
vendored
Normal file
217
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ArgvInputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$_SERVER['argv'] = array('cli.php', 'foo');
|
||||
$input = new ArgvInput();
|
||||
$r = new \ReflectionObject($input);
|
||||
$p = $r->getProperty('tokens');
|
||||
$p->setAccessible(true);
|
||||
|
||||
$this->assertEquals(array('foo'), $p->getValue($input), '__construct() automatically get its input from the argv server variable');
|
||||
}
|
||||
|
||||
public function testParser()
|
||||
{
|
||||
$input = new ArgvInput(array('cli.php', 'foo'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
|
||||
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() is stateless');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--foo'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo'))));
|
||||
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses long options without a value');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--foo=bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a = separator)');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--foo', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a required value (with a space separator)');
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '--foo'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->fail('->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
}
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-f'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'))));
|
||||
$this->assertEquals(array('foo' => true), $input->getOptions(), '->parse() parses short options without a value');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with no separator)');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-f', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options with a required value (with a space separator)');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-f', '-b', 'foo'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b'))));
|
||||
$this->assertEquals(array('foo' => null, 'bar' => true), $input->getOptions(), '->parse() parses short options with an optional value which is not present');
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '-f'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->fail('->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws a \RuntimeException if no value is passed to an option when it is required');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '-ffoo'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))));
|
||||
$this->fail('->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
$this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', 'foo', 'bar'));
|
||||
$input->bind(new InputDefinition());
|
||||
$this->fail('->parse() throws a \RuntimeException if too many arguments are passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if too many arguments are passed');
|
||||
$this->assertEquals('Too many arguments.', $e->getMessage(), '->parse() throws a \RuntimeException if too many arguments are passed');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '--foo'));
|
||||
$input->bind(new InputDefinition());
|
||||
$this->fail('->parse() throws a \RuntimeException if an unknown long option is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if an unknown long option is passed');
|
||||
$this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if an unknown long option is passed');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '-f'));
|
||||
$input->bind(new InputDefinition());
|
||||
$this->fail('->parse() throws a \RuntimeException if an unknown short option is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if an unknown short option is passed');
|
||||
$this->assertEquals('The "-f" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if an unknown short option is passed');
|
||||
}
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fb'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b'))));
|
||||
$this->assertEquals(array('foo' => true, 'bar' => true), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fb', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED))));
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has a required value');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fb', 'bar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fbbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
|
||||
$this->assertEquals(array('foo' => true, 'bar' => 'bar'), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fbbar'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL))));
|
||||
$this->assertEquals(array('foo' => 'bbar', 'bar' => null), $input->getOptions(), '->parse() parses short options when they are aggregated as a single one and one of them takes a value');
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', 'foo', 'bar', 'baz', 'bat'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::IS_ARRAY))));
|
||||
$this->assertEquals(array('name' => array('foo', 'bar', 'baz', 'bat')), $input->getArguments(), '->parse() parses array arguments');
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->assertNotEquals('Too many arguments.', $e->getMessage(), '->parse() parses array arguments');
|
||||
}
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--name=foo', '--name=bar', '--name=baz'));
|
||||
$input->bind(new InputDefinition(array(new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY))));
|
||||
$this->assertEquals(array('name' => array('foo', 'bar', 'baz')), $input->getOptions());
|
||||
|
||||
try {
|
||||
$input = new ArgvInput(array('cli.php', '-1'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('number'))));
|
||||
$this->fail('->parse() throws a \RuntimeException if an unknown option is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->parse() parses arguments with leading dashes as options without having encountered a double-dash sequence');
|
||||
$this->assertEquals('The "-1" option does not exist.', $e->getMessage(), '->parse() parses arguments with leading dashes as options without having encountered a double-dash sequence');
|
||||
}
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--', '-1'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('number'))));
|
||||
$this->assertEquals(array('number' => '-1'), $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-f', 'bar', '--', '-1'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('number'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses arguments with leading dashes as options before having encountered a double-dash sequence');
|
||||
$this->assertEquals(array('number' => '-1'), $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-f', 'bar', ''));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('empty'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL))));
|
||||
$this->assertEquals(array('empty' => ''), $input->getArguments(), '->parse() parses empty string arguments');
|
||||
}
|
||||
|
||||
public function testGetFirstArgument()
|
||||
{
|
||||
$input = new ArgvInput(array('cli.php', '-fbbar'));
|
||||
$this->assertEquals('', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '-fbbar', 'foo'));
|
||||
$this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
|
||||
}
|
||||
|
||||
public function testHasParameterOption()
|
||||
{
|
||||
$input = new ArgvInput(array('cli.php', '-f', 'foo'));
|
||||
$this->assertTrue($input->hasParameterOption('-f'), '->hasParameterOption() returns true if the given short option is in the raw input');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', '--foo', 'foo'));
|
||||
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if the given short option is in the raw input');
|
||||
|
||||
$input = new ArgvInput(array('cli.php', 'foo'));
|
||||
$this->assertFalse($input->hasParameterOption('--foo'), '->hasParameterOption() returns false if the given short option is not in the raw input');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGetParameterOptionValues
|
||||
*/
|
||||
public function testGetParameterOptionEqualSign($argv, $key, $expected)
|
||||
{
|
||||
$input = new ArgvInput($argv);
|
||||
$this->assertEquals($expected, $input->getParameterOption($key), '->getParameterOption() returns the expected value');
|
||||
}
|
||||
|
||||
public function provideGetParameterOptionValues()
|
||||
{
|
||||
return array(
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'dev'),
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'dev'),
|
||||
);
|
||||
}
|
||||
}
|
||||
90
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/ArrayInputTest.php
vendored
Normal file
90
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/ArrayInputTest.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ArrayInputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetFirstArgument()
|
||||
{
|
||||
$input = new ArrayInput(array());
|
||||
$this->assertNull($input->getFirstArgument(), '->getFirstArgument() returns null if no argument were passed');
|
||||
$input = new ArrayInput(array('name' => 'Fabien'));
|
||||
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
|
||||
$input = new ArrayInput(array('--foo' => 'bar', 'name' => 'Fabien'));
|
||||
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
|
||||
}
|
||||
|
||||
public function testHasParameterOption()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
|
||||
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
|
||||
$this->assertFalse($input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');
|
||||
|
||||
$input = new ArrayInput(array('--foo'));
|
||||
$this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
|
||||
}
|
||||
|
||||
public function testParse()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments');
|
||||
|
||||
try {
|
||||
$input = new ArrayInput(array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
|
||||
$this->assertEquals('The "foo" argument does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid argument is passed');
|
||||
}
|
||||
|
||||
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo'))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options');
|
||||
|
||||
$input = new ArrayInput(array('--foo' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses long options with a default value');
|
||||
|
||||
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals(array('foo' => 'default'), $input->getOptions(), '->parse() parses long options with a default value');
|
||||
|
||||
try {
|
||||
$input = new ArrayInput(array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))));
|
||||
$this->fail('->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
|
||||
$this->assertEquals('The "--foo" option requires a value.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if a required option is passed without a value');
|
||||
}
|
||||
|
||||
try {
|
||||
$input = new ArrayInput(array('--foo' => 'foo'), new InputDefinition());
|
||||
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
$this->assertEquals('The "--foo" option does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
}
|
||||
|
||||
$input = new ArrayInput(array('-f' => 'bar'), new InputDefinition(array(new InputOption('foo', 'f'))));
|
||||
$this->assertEquals(array('foo' => 'bar'), $input->getOptions(), '->parse() parses short options');
|
||||
|
||||
try {
|
||||
$input = new ArrayInput(array('-o' => 'foo'), new InputDefinition());
|
||||
$this->fail('->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
$this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
}
|
||||
}
|
||||
}
|
||||
104
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputArgumentTest.php
vendored
Normal file
104
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputArgumentTest.php
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class InputArgumentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$argument = new InputArgument('foo');
|
||||
$this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument');
|
||||
|
||||
// mode argument
|
||||
$argument = new InputArgument('foo');
|
||||
$this->assertFalse($argument->isRequired(), '__construct() gives a "InputArgument::OPTIONAL" mode by default');
|
||||
|
||||
$argument = new InputArgument('foo', null);
|
||||
$this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
|
||||
$this->assertFalse($argument->isRequired(), '__construct() can take "InputArgument::OPTIONAL" as its mode');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::REQUIRED);
|
||||
$this->assertTrue($argument->isRequired(), '__construct() can take "InputArgument::REQUIRED" as its mode');
|
||||
|
||||
try {
|
||||
$argument = new InputArgument('foo', 'ANOTHER_ONE');
|
||||
$this->fail('__construct() throws an Exception if the mode is not valid');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
|
||||
$this->assertEquals('Argument mode "ANOTHER_ONE" is not valid.', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
$argument = new InputArgument('foo', -1);
|
||||
$this->fail('__construct() throws an Exception if the mode is not valid');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
|
||||
$this->assertEquals('Argument mode "-1" is not valid.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testIsArray()
|
||||
{
|
||||
$argument = new InputArgument('foo', InputArgument::IS_ARRAY);
|
||||
$this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
|
||||
$this->assertTrue($argument->isArray(), '->isArray() returns true if the argument can be an array');
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL);
|
||||
$this->assertFalse($argument->isArray(), '->isArray() returns false if the argument can not be an array');
|
||||
}
|
||||
|
||||
public function testGetDescription()
|
||||
{
|
||||
$argument = new InputArgument('foo', null, 'Some description');
|
||||
$this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description');
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
|
||||
$this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value');
|
||||
}
|
||||
|
||||
public function testSetDefault()
|
||||
{
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
|
||||
$argument->setDefault(null);
|
||||
$this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
|
||||
$argument->setDefault('another');
|
||||
$this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
|
||||
$argument->setDefault(array(1, 2));
|
||||
$this->assertEquals(array(1, 2), $argument->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
try {
|
||||
$argument = new InputArgument('foo', InputArgument::REQUIRED);
|
||||
$argument->setDefault('default');
|
||||
$this->fail('->setDefault() throws an Exception if you give a default value for a required argument');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->parse() throws an \InvalidArgumentException exception if an invalid option is passed');
|
||||
$this->assertEquals('Cannot set a default value except for Parameter::OPTIONAL mode.', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$argument = new InputArgument('foo', InputArgument::IS_ARRAY);
|
||||
$argument->setDefault('default');
|
||||
$this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a IS_ARRAY option');
|
||||
$this->assertEquals('A default value for an array argument must be an array.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
363
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php
vendored
Normal file
363
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php
vendored
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected static $fixtures;
|
||||
|
||||
protected $foo, $bar, $foo1, $foo2;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$fixtures = __DIR__.'/../Fixtures/';
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$this->assertEquals(array(), $definition->getArguments(), '__construct() creates a new InputDefinition object');
|
||||
|
||||
$definition = new InputDefinition(array($this->foo, $this->bar));
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '__construct() takes an array of InputArgument objects as its first argument');
|
||||
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$this->assertEquals(array(), $definition->getOptions(), '__construct() creates a new InputDefinition object');
|
||||
|
||||
$definition = new InputDefinition(array($this->foo, $this->bar));
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '__construct() takes an array of InputOption objects as its first argument');
|
||||
}
|
||||
|
||||
public function testSetArguments()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->setArguments(array($this->foo));
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->setArguments() sets the array of InputArgument objects');
|
||||
$definition->setArguments(array($this->bar));
|
||||
|
||||
$this->assertEquals(array('bar' => $this->bar), $definition->getArguments(), '->setArguments() clears all InputArgument objects');
|
||||
}
|
||||
|
||||
public function testAddArguments()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArguments() adds an array of InputArgument objects');
|
||||
$definition->addArguments(array($this->bar));
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArguments() does not clear existing InputArgument objects');
|
||||
}
|
||||
|
||||
public function testAddArgument()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getArguments(), '->addArgument() adds a InputArgument object');
|
||||
$definition->addArgument($this->bar);
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getArguments(), '->addArgument() adds a InputArgument object');
|
||||
|
||||
// arguments must have different names
|
||||
try {
|
||||
$definition->addArgument($this->foo1);
|
||||
$this->fail('->addArgument() throws a Exception if another argument is already registered with the same name');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws a Exception if another argument is already registered with the same name');
|
||||
$this->assertEquals('An argument with name "foo" already exists.', $e->getMessage());
|
||||
}
|
||||
|
||||
// cannot add a parameter after an array parameter
|
||||
$definition->addArgument(new InputArgument('fooarray', InputArgument::IS_ARRAY));
|
||||
try {
|
||||
$definition->addArgument(new InputArgument('anotherbar'));
|
||||
$this->fail('->addArgument() throws a Exception if there is an array parameter already registered');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws a Exception if there is an array parameter already registered');
|
||||
$this->assertEquals('Cannot add an argument after an array argument.', $e->getMessage());
|
||||
}
|
||||
|
||||
// cannot add a required argument after an optional one
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo);
|
||||
try {
|
||||
$definition->addArgument($this->foo2);
|
||||
$this->fail('->addArgument() throws an exception if you try to add a required argument after an optional one');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->addArgument() throws an exception if you try to add a required argument after an optional one');
|
||||
$this->assertEquals('Cannot add a required argument after an optional one.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetArgument()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertEquals($this->foo, $definition->getArgument('foo'), '->getArgument() returns a InputArgument by its name');
|
||||
try {
|
||||
$definition->getArgument('bar');
|
||||
$this->fail('->getArgument() throws an exception if the InputArgument name does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->getArgument() throws an exception if the InputArgument name does not exist');
|
||||
$this->assertEquals('The "bar" argument does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasArgument()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArguments(array($this->foo));
|
||||
$this->assertTrue($definition->hasArgument('foo'), '->hasArgument() returns true if a InputArgument exists for the given name');
|
||||
$this->assertFalse($definition->hasArgument('bar'), '->hasArgument() returns false if a InputArgument exists for the given name');
|
||||
}
|
||||
|
||||
public function testGetArgumentRequiredCount()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo2);
|
||||
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals(1, $definition->getArgumentRequiredCount(), '->getArgumentRequiredCount() returns the number of required arguments');
|
||||
}
|
||||
|
||||
public function testGetArgumentCount()
|
||||
{
|
||||
$this->initializeArguments();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addArgument($this->foo2);
|
||||
$this->assertEquals(1, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
|
||||
$definition->addArgument($this->foo);
|
||||
$this->assertEquals(2, $definition->getArgumentCount(), '->getArgumentCount() returns the number of arguments');
|
||||
}
|
||||
|
||||
public function testGetArgumentDefaults()
|
||||
{
|
||||
$definition = new InputDefinition(array(
|
||||
new InputArgument('foo1', InputArgument::OPTIONAL),
|
||||
new InputArgument('foo2', InputArgument::OPTIONAL, '', 'default'),
|
||||
new InputArgument('foo3', InputArgument::OPTIONAL | InputArgument::IS_ARRAY),
|
||||
// new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
|
||||
));
|
||||
$this->assertEquals(array('foo1' => null, 'foo2' => 'default', 'foo3' => array()), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
|
||||
|
||||
$definition = new InputDefinition(array(
|
||||
new InputArgument('foo4', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, '', array(1, 2)),
|
||||
));
|
||||
$this->assertEquals(array('foo4' => array(1, 2)), $definition->getArgumentDefaults(), '->getArgumentDefaults() return the default values for each argument');
|
||||
}
|
||||
|
||||
public function testSetOptions()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->setOptions() sets the array of InputOption objects');
|
||||
$definition->setOptions(array($this->bar));
|
||||
$this->assertEquals(array('bar' => $this->bar), $definition->getOptions(), '->setOptions() clears all InputOption objects');
|
||||
try {
|
||||
$definition->getOptionForShortcut('f');
|
||||
$this->fail('->setOptions() clears all InputOption objects');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setOptions() clears all InputOption objects');
|
||||
$this->assertEquals('The "-f" option does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testAddOptions()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOptions() adds an array of InputOption objects');
|
||||
$definition->addOptions(array($this->bar));
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOptions() does not clear existing InputOption objects');
|
||||
}
|
||||
|
||||
public function testAddOption()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition();
|
||||
$definition->addOption($this->foo);
|
||||
$this->assertEquals(array('foo' => $this->foo), $definition->getOptions(), '->addOption() adds a InputOption object');
|
||||
$definition->addOption($this->bar);
|
||||
$this->assertEquals(array('foo' => $this->foo, 'bar' => $this->bar), $definition->getOptions(), '->addOption() adds a InputOption object');
|
||||
try {
|
||||
$definition->addOption($this->foo2);
|
||||
$this->fail('->addOption() throws a Exception if the another option is already registered with the same name');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same name');
|
||||
$this->assertEquals('An option named "foo" already exists.', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
$definition->addOption($this->foo1);
|
||||
$this->fail('->addOption() throws a Exception if the another option is already registered with the same shortcut');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->addOption() throws a Exception if the another option is already registered with the same shortcut');
|
||||
$this->assertEquals('An option with shortcut "f" already exists.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetOption()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($this->foo, $definition->getOption('foo'), '->getOption() returns a InputOption by its name');
|
||||
try {
|
||||
$definition->getOption('bar');
|
||||
$this->fail('->getOption() throws an exception if the option name does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->getOption() throws an exception if the option name does not exist');
|
||||
$this->assertEquals('The "--bar" option does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasOption()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertTrue($definition->hasOption('foo'), '->hasOption() returns true if a InputOption exists for the given name');
|
||||
$this->assertFalse($definition->hasOption('bar'), '->hasOption() returns false if a InputOption exists for the given name');
|
||||
}
|
||||
|
||||
public function testHasShortcut()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertTrue($definition->hasShortcut('f'), '->hasShortcut() returns true if a InputOption exists for the given shortcut');
|
||||
$this->assertFalse($definition->hasShortcut('b'), '->hasShortcut() returns false if a InputOption exists for the given shortcut');
|
||||
}
|
||||
|
||||
public function testGetOptionForShortcut()
|
||||
{
|
||||
$this->initializeOptions();
|
||||
|
||||
$definition = new InputDefinition(array($this->foo));
|
||||
$this->assertEquals($this->foo, $definition->getOptionForShortcut('f'), '->getOptionForShortcut() returns a InputOption by its shortcut');
|
||||
try {
|
||||
$definition->getOptionForShortcut('l');
|
||||
$this->fail('->getOption() throws an exception if the shortcut does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->getOption() throws an exception if the shortcut does not exist');
|
||||
$this->assertEquals('The "-l" option does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetOptionDefaults()
|
||||
{
|
||||
$definition = new InputDefinition(array(
|
||||
new InputOption('foo1', null, InputOption::VALUE_NONE),
|
||||
new InputOption('foo2', null, InputOption::VALUE_REQUIRED),
|
||||
new InputOption('foo3', null, InputOption::VALUE_REQUIRED, '', 'default'),
|
||||
new InputOption('foo4', null, InputOption::VALUE_OPTIONAL),
|
||||
new InputOption('foo5', null, InputOption::VALUE_OPTIONAL, '', 'default'),
|
||||
new InputOption('foo6', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY),
|
||||
new InputOption('foo7', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '', array(1, 2)),
|
||||
));
|
||||
$defaults = array(
|
||||
'foo1' => null,
|
||||
'foo2' => null,
|
||||
'foo3' => 'default',
|
||||
'foo4' => null,
|
||||
'foo5' => 'default',
|
||||
'foo6' => array(),
|
||||
'foo7' => array(1, 2),
|
||||
);
|
||||
$this->assertEquals($defaults, $definition->getOptionDefaults(), '->getOptionDefaults() returns the default values for all options');
|
||||
}
|
||||
|
||||
public function testGetSynopsis()
|
||||
{
|
||||
$definition = new InputDefinition(array(new InputOption('foo')));
|
||||
$this->assertEquals('[--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f')));
|
||||
$this->assertEquals('[-f|--foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)));
|
||||
$this->assertEquals('[-f|--foo="..."]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)));
|
||||
$this->assertEquals('[-f|--foo[="..."]]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
|
||||
$definition = new InputDefinition(array(new InputArgument('foo')));
|
||||
$this->assertEquals('[foo]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED)));
|
||||
$this->assertEquals('foo', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY)));
|
||||
$this->assertEquals('[foo1] ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
$definition = new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY)));
|
||||
$this->assertEquals('foo1 ... [fooN]', $definition->getSynopsis(), '->getSynopsis() returns a synopsis of arguments and options');
|
||||
}
|
||||
|
||||
public function testAsText()
|
||||
{
|
||||
$definition = new InputDefinition(array(
|
||||
new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'),
|
||||
new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true),
|
||||
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')),
|
||||
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
|
||||
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
|
||||
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
|
||||
new InputOption('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('foo', 'bar')),
|
||||
new InputOption('qux2', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux2 option', array('foo' => 'bar')),
|
||||
));
|
||||
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');
|
||||
}
|
||||
|
||||
public function testAsXml()
|
||||
{
|
||||
$definition = new InputDefinition(array(
|
||||
new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'),
|
||||
new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true),
|
||||
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')),
|
||||
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
|
||||
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
|
||||
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
|
||||
));
|
||||
$this->assertXmlStringEqualsXmlFile(self::$fixtures.'/definition_asxml.txt', $definition->asXml(), '->asText() returns a textual representation of the InputDefinition');
|
||||
}
|
||||
|
||||
protected function initializeArguments()
|
||||
{
|
||||
$this->foo = new InputArgument('foo');
|
||||
$this->bar = new InputArgument('bar');
|
||||
$this->foo1 = new InputArgument('foo');
|
||||
$this->foo2 = new InputArgument('foo2', InputArgument::REQUIRED);
|
||||
}
|
||||
|
||||
protected function initializeOptions()
|
||||
{
|
||||
$this->foo = new InputOption('foo', 'f');
|
||||
$this->bar = new InputOption('bar', 'b');
|
||||
$this->foo1 = new InputOption('fooBis', 'f');
|
||||
$this->foo2 = new InputOption('foo', 'p');
|
||||
}
|
||||
}
|
||||
192
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputOptionTest.php
vendored
Normal file
192
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputOptionTest.php
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputOptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$option = new InputOption('foo');
|
||||
$this->assertEquals('foo', $option->getName(), '__construct() takes a name as its first argument');
|
||||
$option = new InputOption('--foo');
|
||||
$this->assertEquals('foo', $option->getName(), '__construct() removes the leading -- of the option name');
|
||||
|
||||
try {
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY);
|
||||
$this->fail('->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if VALUE_IS_ARRAY option is used when an option does not accept a value');
|
||||
$this->assertEquals('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.', $e->getMessage());
|
||||
}
|
||||
|
||||
// shortcut argument
|
||||
$option = new InputOption('foo', 'f');
|
||||
$this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument');
|
||||
$option = new InputOption('foo', '-f');
|
||||
$this->assertEquals('f', $option->getShortcut(), '__construct() removes the leading - of the shortcut');
|
||||
$option = new InputOption('foo');
|
||||
$this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default');
|
||||
|
||||
// mode argument
|
||||
$option = new InputOption('foo', 'f');
|
||||
$this->assertFalse($option->acceptValue(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
|
||||
$this->assertFalse($option->isValueRequired(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
|
||||
$this->assertFalse($option->isValueOptional(), '__construct() gives a "InputOption::VALUE_NONE" mode by default');
|
||||
|
||||
$option = new InputOption('foo', 'f', null);
|
||||
$this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
$this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
|
||||
$this->assertFalse($option->acceptValue(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
$this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_NONE" as its mode');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_REQUIRED);
|
||||
$this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
|
||||
$this->assertTrue($option->isValueRequired(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
|
||||
$this->assertFalse($option->isValueOptional(), '__construct() can take "InputOption::VALUE_REQUIRED" as its mode');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL);
|
||||
$this->assertTrue($option->acceptValue(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
|
||||
$this->assertFalse($option->isValueRequired(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
|
||||
$this->assertTrue($option->isValueOptional(), '__construct() can take "InputOption::VALUE_OPTIONAL" as its mode');
|
||||
|
||||
try {
|
||||
$option = new InputOption('foo', 'f', 'ANOTHER_ONE');
|
||||
$this->fail('__construct() throws an Exception if the mode is not valid');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
|
||||
$this->assertEquals('Option mode "ANOTHER_ONE" is not valid.', $e->getMessage());
|
||||
}
|
||||
try {
|
||||
$option = new InputOption('foo', 'f', -1);
|
||||
$this->fail('__construct() throws an Exception if the mode is not valid');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '__construct() throws an Exception if the mode is not valid');
|
||||
$this->assertEquals('Option mode "-1" is not valid.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testEmptyNameIsInvalid()
|
||||
{
|
||||
new InputOption('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testDoubleDashNameIsInvalid()
|
||||
{
|
||||
new InputOption('--');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testSingleDashOptionIsInvalid()
|
||||
{
|
||||
new InputOption('foo', '-');
|
||||
}
|
||||
|
||||
public function testIsArray()
|
||||
{
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
|
||||
$this->assertTrue($option->isArray(), '->isArray() returns true if the option can be an array');
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_NONE);
|
||||
$this->assertFalse($option->isArray(), '->isArray() returns false if the option can not be an array');
|
||||
}
|
||||
|
||||
public function testGetDescription()
|
||||
{
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$this->assertEquals('Some description', $option->getDescription(), '->getDescription() returns the description message');
|
||||
}
|
||||
|
||||
public function testGetDefault()
|
||||
{
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', 'default');
|
||||
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED, '', 'default');
|
||||
$this->assertEquals('default', $option->getDefault(), '->getDefault() returns the default value');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED);
|
||||
$this->assertNull($option->getDefault(), '->getDefault() returns null if no default value is configured');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
|
||||
$this->assertEquals(array(), $option->getDefault(), '->getDefault() returns an empty array if option is an array');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_NONE);
|
||||
$this->assertFalse($option->getDefault(), '->getDefault() returns false if the option does not take a value');
|
||||
}
|
||||
|
||||
public function testSetDefault()
|
||||
{
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED, '', 'default');
|
||||
$option->setDefault(null);
|
||||
$this->assertNull($option->getDefault(), '->setDefault() can reset the default value by passing null');
|
||||
$option->setDefault('another');
|
||||
$this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$option = new InputOption('foo', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY);
|
||||
$option->setDefault(array(1, 2));
|
||||
$this->assertEquals(array(1, 2), $option->getDefault(), '->setDefault() changes the default value');
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
|
||||
try {
|
||||
$option->setDefault('default');
|
||||
$this->fail('->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
|
||||
$this->assertEquals('Cannot set a default value when using Option::VALUE_NONE mode.', $e->getMessage());
|
||||
}
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
|
||||
try {
|
||||
$option->setDefault('default');
|
||||
$this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
|
||||
$this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testEquals()
|
||||
{
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', null, 'Alternative description');
|
||||
$this->assertTrue($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description', true);
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('bar', 'f', null, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', '', null, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
|
||||
$option = new InputOption('foo', 'f', null, 'Some description');
|
||||
$option2 = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, 'Some description');
|
||||
$this->assertFalse($option->equals($option2));
|
||||
}
|
||||
}
|
||||
117
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputTest.php
vendored
Normal file
117
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/InputTest.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals('foo', $input->getArgument('name'), '->__construct() takes a InputDefinition as an argument');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
{
|
||||
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'))));
|
||||
$this->assertEquals('foo', $input->getOption('name'), '->getOption() returns the value for the given option');
|
||||
|
||||
$input->setOption('name', 'bar');
|
||||
$this->assertEquals('bar', $input->getOption('name'), '->setOption() sets the value for a given option');
|
||||
$this->assertEquals(array('name' => 'bar'), $input->getOptions(), '->getOptions() returns all option values');
|
||||
|
||||
$input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals('default', $input->getOption('bar'), '->getOption() returns the default value for optional options');
|
||||
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getOptions(), '->getOptions() returns all option values, even optional ones');
|
||||
|
||||
try {
|
||||
$input->setOption('foo', 'bar');
|
||||
$this->fail('->setOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
$this->assertEquals('The "foo" option does not exist.', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$input->getOption('foo');
|
||||
$this->fail('->getOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
$this->assertEquals('The "foo" option does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testArguments()
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'))));
|
||||
$this->assertEquals('foo', $input->getArgument('name'), '->getArgument() returns the value for the given argument');
|
||||
|
||||
$input->setArgument('name', 'bar');
|
||||
$this->assertEquals('bar', $input->getArgument('name'), '->setArgument() sets the value for a given argument');
|
||||
$this->assertEquals(array('name' => 'bar'), $input->getArguments(), '->getArguments() returns all argument values');
|
||||
|
||||
$input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default'))));
|
||||
$this->assertEquals('default', $input->getArgument('bar'), '->getArgument() returns the default value for optional arguments');
|
||||
$this->assertEquals(array('name' => 'foo', 'bar' => 'default'), $input->getArguments(), '->getArguments() returns all argument values, even optional ones');
|
||||
|
||||
try {
|
||||
$input->setArgument('foo', 'bar');
|
||||
$this->fail('->setArgument() throws a \InvalidArgumentException if the argument does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
$this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$input->getArgument('foo');
|
||||
$this->fail('->getArgument() throws a \InvalidArgumentException if the argument does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws a \InvalidArgumentException if the option does not exist');
|
||||
$this->assertEquals('The "foo" argument does not exist.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testValidate()
|
||||
{
|
||||
$input = new ArrayInput(array());
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
|
||||
|
||||
try {
|
||||
$input->validate();
|
||||
$this->fail('->validate() throws a \RuntimeException if not enough arguments are given');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\RuntimeException', $e, '->validate() throws a \RuntimeException if not enough arguments are given');
|
||||
$this->assertEquals('Not enough arguments.', $e->getMessage());
|
||||
}
|
||||
|
||||
$input = new ArrayInput(array('name' => 'foo'));
|
||||
$input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED))));
|
||||
|
||||
try {
|
||||
$input->validate();
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->fail('->validate() does not throw a \RuntimeException if enough arguments are given');
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetFetInteractive()
|
||||
{
|
||||
$input = new ArrayInput(array());
|
||||
$this->assertTrue($input->isInteractive(), '->isInteractive() returns whether the input should be interactive or not');
|
||||
$input->setInteractive(false);
|
||||
$this->assertFalse($input->isInteractive(), '->setInteractive() changes the interactive flag');
|
||||
}
|
||||
}
|
||||
58
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/StringInputTest.php
vendored
Normal file
58
core/vendor/symfony/console/Symfony/Component/Console/Tests/Input/StringInputTest.php
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
|
||||
class StringInputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getTokenizeData
|
||||
*/
|
||||
public function testTokenize($input, $tokens, $message)
|
||||
{
|
||||
$input = new StringInput($input);
|
||||
$r = new \ReflectionClass('Symfony\Component\Console\Input\ArgvInput');
|
||||
$p = $r->getProperty('tokens');
|
||||
$p->setAccessible(true);
|
||||
$this->assertEquals($tokens, $p->getValue($input), $message);
|
||||
}
|
||||
|
||||
public function getTokenizeData()
|
||||
{
|
||||
return array(
|
||||
array('', array(), '->tokenize() parses an empty string'),
|
||||
array('foo', array('foo'), '->tokenize() parses arguments'),
|
||||
array(' foo bar ', array('foo', 'bar'), '->tokenize() ignores whitespaces between arguments'),
|
||||
array('"quoted"', array('quoted'), '->tokenize() parses quoted arguments'),
|
||||
array("'quoted'", array('quoted'), '->tokenize() parses quoted arguments'),
|
||||
array('\"quoted\"', array('"quoted"'), '->tokenize() parses escaped-quoted arguments'),
|
||||
array("\'quoted\'", array('\'quoted\''), '->tokenize() parses escaped-quoted arguments'),
|
||||
array('-a', array('-a'), '->tokenize() parses short options'),
|
||||
array('-azc', array('-azc'), '->tokenize() parses aggregated short options'),
|
||||
array('-awithavalue', array('-awithavalue'), '->tokenize() parses short options with a value'),
|
||||
array('-a"foo bar"', array('-afoo bar'), '->tokenize() parses short options with a value'),
|
||||
array('-a"foo bar""foo bar"', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
|
||||
array('-a\'foo bar\'', array('-afoo bar'), '->tokenize() parses short options with a value'),
|
||||
array('-a\'foo bar\'\'foo bar\'', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
|
||||
array('-a\'foo bar\'"foo bar"', array('-afoo barfoo bar'), '->tokenize() parses short options with a value'),
|
||||
array('--long-option', array('--long-option'), '->tokenize() parses long options'),
|
||||
array('--long-option=foo', array('--long-option=foo'), '->tokenize() parses long options with a value'),
|
||||
array('--long-option="foo bar"', array('--long-option=foo bar'), '->tokenize() parses long options with a value'),
|
||||
array('--long-option="foo bar""another"', array('--long-option=foo baranother'), '->tokenize() parses long options with a value'),
|
||||
array('--long-option=\'foo bar\'', array('--long-option=foo bar'), '->tokenize() parses long options with a value'),
|
||||
array("--long-option='foo bar''another'", array("--long-option=foo baranother"), '->tokenize() parses long options with a value'),
|
||||
array("--long-option='foo bar'\"another\"", array("--long-option=foo baranother"), '->tokenize() parses long options with a value'),
|
||||
array('foo -a -ffoo --long bar', array('foo', '-a', '-ffoo', '--long', 'bar'), '->tokenize() parses when several arguments and options'),
|
||||
);
|
||||
}
|
||||
}
|
||||
24
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php
vendored
Normal file
24
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
|
||||
class ConsoleOutputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$output = new ConsoleOutput(Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
|
||||
}
|
||||
}
|
||||
24
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/NullOutputTest.php
vendored
Normal file
24
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/NullOutputTest.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
||||
class NullOutputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$output = new NullOutput();
|
||||
$output->write('foo');
|
||||
$this->assertTrue(true, '->write() does nothing'); // FIXME
|
||||
}
|
||||
}
|
||||
101
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/OutputTest.php
vendored
Normal file
101
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/OutputTest.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
|
||||
class OutputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$output = new TestOutput(Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
|
||||
$this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
|
||||
}
|
||||
|
||||
public function testSetIsDecorated()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->setDecorated(true);
|
||||
$this->assertTrue($output->isDecorated(), 'setDecorated() sets the decorated flag');
|
||||
}
|
||||
|
||||
public function testSetGetVerbosity()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->setVerbosity(Output::VERBOSITY_QUIET);
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '->setVerbosity() sets the verbosity');
|
||||
}
|
||||
|
||||
public function testWrite()
|
||||
{
|
||||
$fooStyle = new OutputFormatterStyle('yellow', 'red', array('blink'));
|
||||
$output = new TestOutput(Output::VERBOSITY_QUIET);
|
||||
$output->writeln('foo');
|
||||
$this->assertEquals('', $output->output, '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln(array('foo', 'bar'));
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln('<info>foo</info>', Output::OUTPUT_RAW);
|
||||
$this->assertEquals("<info>foo</info>\n", $output->output, '->writeln() outputs the raw message if OUTPUT_RAW is specified');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->writeln('<info>foo</info>', Output::OUTPUT_PLAIN);
|
||||
$this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if OUTPUT_PLAIN is specified');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->setDecorated(false);
|
||||
$output->writeln('<info>foo</info>');
|
||||
$this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if decoration is set to false');
|
||||
|
||||
$output = new TestOutput();
|
||||
$output->getFormatter()->setStyle('FOO', $fooStyle);
|
||||
$output->setDecorated(true);
|
||||
$output->writeln('<foo>foo</foo>');
|
||||
$this->assertEquals("\033[33;41;5mfoo\033[0m\n", $output->output, '->writeln() decorates the output');
|
||||
|
||||
try {
|
||||
$output->writeln('<foo>foo</foo>', 24);
|
||||
$this->fail('->writeln() throws an \InvalidArgumentException when the type does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->writeln() throws an \InvalidArgumentException when the type does not exist');
|
||||
$this->assertEquals('Unknown output type given (24)', $e->getMessage());
|
||||
}
|
||||
|
||||
$output->clear();
|
||||
$output->write('<bar>foo</bar>');
|
||||
$this->assertEquals('<bar>foo</bar>', $output->output, '->write() do nothing when a style does not exist');
|
||||
|
||||
$output->clear();
|
||||
$output->writeln('<bar>foo</bar>');
|
||||
$this->assertEquals("<bar>foo</bar>\n", $output->output, '->writeln() do nothing when a style does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
class TestOutput extends Output
|
||||
{
|
||||
public $output = '';
|
||||
|
||||
public function clear()
|
||||
{
|
||||
$this->output = '';
|
||||
}
|
||||
|
||||
protected function doWrite($message, $newline)
|
||||
{
|
||||
$this->output .= $message.($newline ? "\n" : '');
|
||||
}
|
||||
}
|
||||
59
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/StreamOutputTest.php
vendored
Normal file
59
core/vendor/symfony/console/Symfony/Component/Console/Tests/Output/StreamOutputTest.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class StreamOutputTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $stream;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->stream = fopen('php://memory', 'a', false);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->stream = null;
|
||||
}
|
||||
|
||||
public function testConstructor()
|
||||
{
|
||||
try {
|
||||
$output = new StreamOutput('foo');
|
||||
$this->fail('__construct() throws an \InvalidArgumentException if the first argument is not a stream');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '__construct() throws an \InvalidArgumentException if the first argument is not a stream');
|
||||
$this->assertEquals('The StreamOutput class needs a stream as its first argument.', $e->getMessage());
|
||||
}
|
||||
|
||||
$output = new StreamOutput($this->stream, Output::VERBOSITY_QUIET, true);
|
||||
$this->assertEquals(Output::VERBOSITY_QUIET, $output->getVerbosity(), '__construct() takes the verbosity as its first argument');
|
||||
$this->assertTrue($output->isDecorated(), '__construct() takes the decorated flag as its second argument');
|
||||
}
|
||||
|
||||
public function testGetStream()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$this->assertEquals($this->stream, $output->getStream(), '->getStream() returns the current stream');
|
||||
}
|
||||
|
||||
public function testDoWrite()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$output->writeln('foo');
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream');
|
||||
}
|
||||
}
|
||||
64
core/vendor/symfony/console/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php
vendored
Normal file
64
core/vendor/symfony/console/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Tester;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
class ApplicationTesterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $application;
|
||||
protected $tester;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->application = new Application();
|
||||
$this->application->setAutoExit(false);
|
||||
$this->application->register('foo')
|
||||
->addArgument('foo')
|
||||
->setCode(function ($input, $output) { $output->writeln('foo'); })
|
||||
;
|
||||
|
||||
$this->tester = new ApplicationTester($this->application);
|
||||
$this->tester->run(array('command' => 'foo', 'foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->application = null;
|
||||
$this->tester = null;
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
$this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
|
||||
$this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
|
||||
$this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
|
||||
}
|
||||
|
||||
public function testGetInput()
|
||||
{
|
||||
$this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
|
||||
}
|
||||
|
||||
public function testGetOutput()
|
||||
{
|
||||
rewind($this->tester->getOutput()->getStream());
|
||||
$this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
|
||||
}
|
||||
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
|
||||
}
|
||||
}
|
||||
62
core/vendor/symfony/console/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php
vendored
Normal file
62
core/vendor/symfony/console/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Tester;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class CommandTesterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $application;
|
||||
protected $tester;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->command = new Command('foo');
|
||||
$this->command->addArgument('command');
|
||||
$this->command->addArgument('foo');
|
||||
$this->command->setCode(function ($input, $output) { $output->writeln('foo'); });
|
||||
|
||||
$this->tester = new CommandTester($this->command);
|
||||
$this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->command = null;
|
||||
$this->tester = null;
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$this->assertFalse($this->tester->getInput()->isInteractive(), '->execute() takes an interactive option');
|
||||
$this->assertFalse($this->tester->getOutput()->isDecorated(), '->execute() takes a decorated option');
|
||||
$this->assertEquals(Output::VERBOSITY_VERBOSE, $this->tester->getOutput()->getVerbosity(), '->execute() takes a verbosity option');
|
||||
}
|
||||
|
||||
public function testGetInput()
|
||||
{
|
||||
$this->assertEquals('bar', $this->tester->getInput()->getArgument('foo'), '->getInput() returns the current input instance');
|
||||
}
|
||||
|
||||
public function testGetOutput()
|
||||
{
|
||||
rewind($this->tester->getOutput()->getStream());
|
||||
$this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance');
|
||||
}
|
||||
|
||||
public function testGetDisplay()
|
||||
{
|
||||
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
|
||||
}
|
||||
}
|
||||
18
core/vendor/symfony/console/Symfony/Component/Console/Tests/bootstrap.php
vendored
Normal file
18
core/vendor/symfony/console/Symfony/Component/Console/Tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
spl_autoload_register(function ($class) {
|
||||
if (0 === strpos(ltrim($class, '/'), 'Symfony\Component\Console')) {
|
||||
if (file_exists($file = __DIR__.'/../'.substr(str_replace('\\', '/', $class), strlen('Symfony\Component\Console')).'.php')) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
});
|
||||
31
core/vendor/symfony/console/Symfony/Component/Console/composer.json
vendored
Normal file
31
core/vendor/symfony/console/Symfony/Component/Console/composer.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"type": "library",
|
||||
"description": "Symfony Console Component",
|
||||
"keywords": [],
|
||||
"homepage": "http://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Symfony\\Component\\Console": "" }
|
||||
},
|
||||
"target-dir": "Symfony/Component/Console",
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
30
core/vendor/symfony/console/Symfony/Component/Console/phpunit.xml.dist
vendored
Normal file
30
core/vendor/symfony/console/Symfony/Component/Console/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="Tests/bootstrap.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Symfony Console Component Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user