./0000755001161000116100000000000012165326424006776 5ustar arar./Console-2.3.1/0000755001161000116100000000000012165326424011037 5ustar arar./Console-2.3.1/Symfony/0000755001161000116100000000000012165326424012503 5ustar arar./Console-2.3.1/Symfony/Component/0000755001161000116100000000000012165326424014445 5ustar arar./Console-2.3.1/Symfony/Component/Console/0000755001161000116100000000000012165326443016050 5ustar arar./Console-2.3.1/Symfony/Component/Console/ConsoleEvents.php0000644001161000116100000000277012155624475021363 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console; /** * Contains all events dispatched by an Application. * * @author Francesco Levorato */ final class ConsoleEvents { /** * The COMMAND event allows you to attach listeners before any command is * executed by the console. It also allows you to modify the command, input and output * before they are handled to the command. * * The event listener method receives a Symfony\Component\Console\Event\ConsoleCommandEvent * instance. * * @var string */ const COMMAND = 'console.command'; /** * The TERMINATE event allows you to attach listeners after a command is * executed by the console. * * The event listener method receives a Symfony\Component\Console\Event\ConsoleTerminateEvent * instance. * * @var string */ const TERMINATE = 'console.terminate'; /** * The EXCEPTION event occurs when an uncaught exception appears. * * This event allows you to deal with the exception or * to modify the thrown exception. The event listener method receives * a Symfony\Component\Console\Event\ConsoleExceptionEvent * instance. * * @var string */ const EXCEPTION = 'console.exception'; } ./Console-2.3.1/Symfony/Component/Console/phpunit.xml.dist0000644001161000116100000000155112155624475021232 0ustar arar ./Tests/ ./ ./Resources ./Tests ./vendor ./Console-2.3.1/Symfony/Component/Console/Tester/0000755001161000116100000000000012165326424017315 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tester/CommandTester.php0000644001161000116100000000543412155624475022607 0ustar arar * * 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 */ 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. * * @param Boolean $normalize Whether to normalize end of lines to \n or not * * @return string The display */ public function getDisplay($normalize = false) { rewind($this->output->getStream()); $display = stream_get_contents($this->output->getStream()); if ($normalize) { $display = str_replace(PHP_EOL, "\n", $display); } return $display; } /** * 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; } } ./Console-2.3.1/Symfony/Component/Console/Tester/ApplicationTester.php0000644001161000116100000000613112155624475023467 0ustar arar * * 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. * * When testing an application, don't forget to disable the auto exit flag: * * $application = new Application(); * $application->setAutoExit(false); * * @author Fabien Potencier */ 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. * * @param Boolean $normalize Whether to normalize end of lines to \n or not * * @return string The display */ public function getDisplay($normalize = false) { rewind($this->output->getStream()); $display = stream_get_contents($this->output->getStream()); if ($normalize) { $display = str_replace(PHP_EOL, "\n", $display); } return $display; } /** * 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; } } ./Console-2.3.1/Symfony/Component/Console/Command/0000755001161000116100000000000012165326424017425 5ustar arar./Console-2.3.1/Symfony/Component/Console/Command/Command.php0000644001161000116100000003703712155624475021534 0ustar arar * * 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\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; 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 * * @api */ class Command { private $application; private $name; private $aliases; private $definition; private $help; private $description; private $ignoreValidationErrors; private $applicationDefinitionMerged; private $applicationDefinitionMergedWithArgs; 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->applicationDefinitionMergedWithArgs = 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 null|integer null or 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 * * @throws \Exception * * @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) { $statusCode = call_user_func($this->code, $input, $output); } else { $statusCode = $this->execute($input, $output); } return is_numeric($statusCode) ? (int) $statusCode : 0; } /** * Sets the code to execute when running this command. * * If this method is used, it overrides the code defined * in the execute() method. * * @param callable $code A callable(InputInterface $input, OutputInterface $output) * * @return Command The current instance * * @throws \InvalidArgumentException * * @see execute() * * @api */ public function setCode($code) { if (!is_callable($code)) { throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.'); } $this->code = $code; return $this; } /** * Merges the application definition with the command definition. * * This method is not part of public API and should not be used directly. * * @param Boolean $mergeArgs Whether to merge or not the Application definition arguments to Command definition arguments */ public function mergeApplicationDefinition($mergeArgs = true) { if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) { return; } if ($mergeArgs) { $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; if ($mergeArgs) { $this->applicationDefinitionMergedWithArgs = 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. * * This method is not part of public API and should not be used directly. * * @return InputDefinition An InputDefinition instance */ public 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 * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asText() { $descriptor = new TextDescriptor(); return $descriptor->describe($this); } /** * 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 * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asXml($asDom = false) { $descriptor = new XmlDescriptor(); return $descriptor->describe($this, array('as_dom' => $asDom)); } private function validateName($name) { if (!preg_match('/^[^\:]+(\:[^\:]+)*$/', $name)) { throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); } } } ./Console-2.3.1/Symfony/Component/Console/Command/HelpCommand.php0000644001161000116100000000502512155624475022335 0ustar arar * * 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\Helper\DescriptorHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * HelpCommand displays the help for a given command. * * @author Fabien Potencier */ 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'), new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'), )) ->setDescription('Displays help for a command') ->setHelp(<<%command.name% command displays help for a given command: php %command.full_name% list You can also output the help in other formats by using the --format option: php %command.full_name% --format=xml list To display the list of available commands, please use the list command. 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()->find($input->getArgument('command_name')); } if ($input->getOption('xml')) { $input->setOption('format', 'xml'); } $helper = new DescriptorHelper(); $helper->describe($output, $this->command, $input->getOption('format'), $input->getOption('raw')); $this->command = null; } } ./Console-2.3.1/Symfony/Component/Console/Command/ListCommand.php0000644001161000116100000000512612155624475022362 0ustar arar * * 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\Helper\DescriptorHelper; 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\Input\InputDefinition; /** * ListCommand displays the list of all available commands for the application. * * @author Fabien Potencier */ class ListCommand extends Command { /** * {@inheritdoc} */ protected function configure() { $this ->setName('list') ->setDefinition($this->createDefinition()) ->setDescription('Lists commands') ->setHelp(<<%command.name% command lists all commands: php %command.full_name% You can also display the commands for a specific namespace: php %command.full_name% test You can also output the information in other formats by using the --format option: php %command.full_name% --format=xml It's also possible to get raw list of commands (useful for embedding command runner): php %command.full_name% --raw EOF ) ; } /** * {@inheritdoc} */ public function getNativeDefinition() { return $this->createDefinition(); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('xml')) { $input->setOption('format', 'xml'); } $helper = new DescriptorHelper(); $helper->describe($output, $this->getApplication(), $input->getOption('format'), $input->getOption('raw'), $input->getArgument('namespace')); } /** * {@inheritdoc} */ private function createDefinition() { return new InputDefinition(array( new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'), new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'), new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats'), )); } } ./Console-2.3.1/Symfony/Component/Console/autoloader.php0000644001161000116100000000052112155624475020723 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; /** * Descriptor interface. * * @author Jean-François Simon */ interface DescriptorInterface { /** * Describes an InputArgument instance. * * @param object $object * @param array $options * * @return string|mixed */ public function describe($object, array $options = array()); } ./Console-2.3.1/Symfony/Component/Console/Descriptor/XmlDescriptor.php0000644001161000116100000002061612155624475023510 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; /** * XML descriptor. * * @author Jean-François Simon */ class XmlDescriptor extends Descriptor { /** * {@inheritdoc} */ protected function describeInputArgument(InputArgument $argument, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($objectXML = $dom->createElement('argument')); $objectXML->setAttribute('name', $argument->getName()); $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0); $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0); $objectXML->appendChild($descriptionXML = $dom->createElement('description')); $descriptionXML->appendChild($dom->createTextNode($argument->getDescription())); $objectXML->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)); } return $this->output($dom, $options); } /** * {@inheritdoc} */ protected function describeInputOption(InputOption $option, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($objectXML = $dom->createElement('option')); $objectXML->setAttribute('name', '--'.$option->getName()); $pos = strpos($option->getShortcut(), '|'); if (false !== $pos) { $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos)); $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut()))); } else { $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : ''); } $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0); $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0); $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0); $objectXML->appendChild($descriptionXML = $dom->createElement('description')); $descriptionXML->appendChild($dom->createTextNode($option->getDescription())); if ($option->acceptValue()) { $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array())); $objectXML->appendChild($defaultsXML = $dom->createElement('defaults')); if (!empty($defaults)) { foreach ($defaults as $default) { $defaultsXML->appendChild($defaultXML = $dom->createElement('default')); $defaultXML->appendChild($dom->createTextNode($default)); } } } return $this->output($dom, $options); } /** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($definitionXML = $dom->createElement('definition')); $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments')); foreach ($definition->getArguments() as $argument) { $this->appendDocument($argumentsXML, $this->describeInputArgument($argument, array('as_dom' => true))); } $definitionXML->appendChild($optionsXML = $dom->createElement('options')); foreach ($definition->getOptions() as $option) { $this->appendDocument($optionsXML, $this->describeInputOption($option, array('as_dom' => true))); } return $this->output($dom, $options); } /** * {@inheritdoc} */ protected function describeCommand(Command $command, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($commandXML = $dom->createElement('command')); $command->getSynopsis(); $command->mergeApplicationDefinition(false); $commandXML->setAttribute('id', $command->getName()); $commandXML->setAttribute('name', $command->getName()); $commandXML->appendChild($usageXML = $dom->createElement('usage')); $usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), ''))); $commandXML->appendChild($descriptionXML = $dom->createElement('description')); $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription()))); $commandXML->appendChild($helpXML = $dom->createElement('help')); $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp()))); $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); foreach ($command->getAliases() as $alias) { $aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); $aliasXML->appendChild($dom->createTextNode($alias)); } $definitionXML = $this->describeInputDefinition($command->getNativeDefinition(), array('as_dom' => true)); $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0)); return $this->output($dom, $options); } /** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->appendChild($rootXml = $dom->createElement('symfony')); $rootXml->appendChild($commandsXML = $dom->createElement('commands')); $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); if ($describedNamespace) { $commandsXML->setAttribute('namespace', $describedNamespace); } foreach ($description->getCommands() as $command) { $this->appendDocument($commandsXML, $this->describeCommand($command, array('as_dom' => true))); } if (!$describedNamespace) { $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces')); foreach ($description->getNamespaces() as $namespace) { $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace')); $namespaceArrayXML->setAttribute('id', $namespace['id']); foreach ($namespace['commands'] as $name) { $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command')); $commandXML->appendChild($dom->createTextNode($name)); } } } return $this->output($dom, $options); } /** * Appends document children to parent node. * * @param \DOMNode $parentNode * @param \DOMNode $importedParent */ private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent) { foreach ($importedParent->childNodes as $childNode) { $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true)); } } /** * Outputs document as DOMDocument or string according to options. * * @param \DOMDocument $dom * @param array $options * * @return \DOMDocument|string */ private function output(\DOMDocument $dom, array $options) { if (isset($options['as_dom']) && $options['as_dom']) { return $dom; } $dom->formatOutput = true; return $dom->saveXML(); } } ./Console-2.3.1/Symfony/Component/Console/Descriptor/TextDescriptor.php0000644001161000116100000001667012155624475023701 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; /** * Text descriptor. * * @author Jean-François Simon */ class TextDescriptor extends Descriptor { /** * {@inheritdoc} */ protected function describeInputArgument(InputArgument $argument, array $options = array()) { if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) { $default = sprintf(' (default: %s)', $this->formatDefaultValue($argument->getDefault())); } else { $default = ''; } $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName()); $output = str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()); $output = sprintf(" %-${nameWidth}s %s%s", $argument->getName(), $output, $default); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; } /** * {@inheritdoc} */ protected function describeInputOption(InputOption $option, array $options = array()) { if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) { $default = sprintf(' (default: %s)', $this->formatDefaultValue($option->getDefault())); } else { $default = ''; } $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName()); $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2; $output = sprintf(" %s %-${nameWithShortcutWidth}s%s%s%s", '--'.$option->getName(), $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()), $default, $option->isArray() ? ' (multiple values allowed)' : '' ); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; } /** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $nameWidth = 0; foreach ($definition->getOptions() as $option) { $nameLength = strlen($option->getName()) + 2; if ($option->getShortcut()) { $nameLength += strlen($option->getShortcut()) + 3; } $nameWidth = max($nameWidth, $nameLength); } foreach ($definition->getArguments() as $argument) { $nameWidth = max($nameWidth, strlen($argument->getName())); } ++$nameWidth; $messages = array(); if ($definition->getArguments()) { $messages[] = 'Arguments:'; foreach ($definition->getArguments() as $argument) { $messages[] = $this->describeInputArgument($argument, array('name_width' => $nameWidth)); } $messages[] = ''; } if ($definition->getOptions()) { $messages[] = 'Options:'; foreach ($definition->getOptions() as $option) { $messages[] = $this->describeInputOption($option, array('name_width' => $nameWidth)); } $messages[] = ''; } $output = implode("\n", $messages); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; } /** * {@inheritdoc} */ protected function describeCommand(Command $command, array $options = array()) { $command->getSynopsis(); $command->mergeApplicationDefinition(false); $messages = array('Usage:', ' '.$command->getSynopsis(), ''); if ($command->getAliases()) { $messages[] = 'Aliases: '.implode(', ', $command->getAliases()).''; } $messages[] = $this->describeInputDefinition($command->getNativeDefinition()); if ($help = $command->getProcessedHelp()) { $messages[] = 'Help:'; $messages[] = ' '.str_replace("\n", "\n ", $help)."\n"; } $output = implode("\n", $messages); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; } /** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); $messages = array(); if (isset($options['raw_text']) && $options['raw_text']) { $width = $this->getColumnWidth($description->getCommands()); foreach ($description->getCommands() as $command) { $messages[] = sprintf("%-${width}s %s", $command->getName(), $command->getDescription()); } } else { $width = $this->getColumnWidth($description->getCommands()); $messages[] = $application->getHelp(); $messages[] = ''; if ($describedNamespace) { $messages[] = sprintf("Available commands for the \"%s\" namespace:", $describedNamespace); } else { $messages[] = 'Available commands:'; } // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $messages[] = ''.$namespace['id'].''; } foreach ($namespace['commands'] as $name) { $messages[] = sprintf(" %-${width}s %s", $name, $description->getCommand($name)->getDescription()); } } } $output = implode("\n", $messages); return isset($options['raw_text']) && $options['raw_text'] ? strip_tags($output) : $output; } /** * Formats input option/argument default value. * * @param mixed $default * * @return string */ private function formatDefaultValue($default) { if (version_compare(PHP_VERSION, '5.4', '<')) { return str_replace('\/', '/', json_encode($default)); } return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } /** * @param Command[] $commands * * @return int */ private function getColumnWidth(array $commands) { $width = 0; foreach ($commands as $command) { $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width; } return $width + 2; } } ./Console-2.3.1/Symfony/Component/Console/Descriptor/JsonDescriptor.php0000644001161000116100000001045712155624475023663 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; /** * JSON descriptor. * * @author Jean-François Simon */ class JsonDescriptor extends Descriptor { /** * {@inheritdoc} */ protected function describeInputArgument(InputArgument $argument, array $options = array()) { return $this->output(array( 'name' => $argument->getName(), 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), 'description' => $argument->getDescription(), 'default' => $argument->getDefault(), ), $options); } /** * {@inheritdoc} */ protected function describeInputOption(InputOption $option, array $options = array()) { return $this->output(array( 'name' => '--'.$option->getName(), 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '', 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), 'description' => $option->getDescription(), 'default' => $option->getDefault(), ), $options); } /** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $inputArguments = array(); foreach ($definition->getArguments() as $name => $argument) { $inputArguments[$name] = $this->describeInputArgument($argument, array('as_array' => true)); } $inputOptions = array(); foreach ($definition->getOptions() as $name => $option) { $inputOptions[$name] = $this->describeInputOption($option, array('as_array' => true)); } return $this->output(array('arguments' => $inputArguments, 'options' => $inputOptions), $options); } /** * {@inheritdoc} */ protected function describeCommand(Command $command, array $options = array()) { $command->getSynopsis(); $command->mergeApplicationDefinition(false); return $this->output(array( 'name' => $command->getName(), 'usage' => $command->getSynopsis(), 'description' => $command->getDescription(), 'help' => $command->getProcessedHelp(), 'aliases' => $command->getAliases(), 'definition' => $this->describeInputDefinition($command->getNativeDefinition(), array('as_array' => true)), ), $options); } /** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); $commands = array(); foreach ($description->getCommands() as $command) { $commands[] = $this->describeCommand($command, array('as_array' => true)); } $data = $describedNamespace ? array('commands' => $commands, 'namespace' => $describedNamespace) : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces())); return $this->output($data, $options); } /** * Outputs data as array or string according to options. * * @param array $data * @param array $options * * @return array|string */ private function output(array $data, array $options) { if (isset($options['as_array']) && $options['as_array']) { return $data; } return json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0); } } ./Console-2.3.1/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php0000644001161000116100000001101712155624475024525 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; /** * Markdown descriptor. * * @author Jean-François Simon */ class MarkdownDescriptor extends Descriptor { /** * {@inheritdoc} */ protected function describeInputArgument(InputArgument $argument, array $options = array()) { return '**'.$argument->getName().':**'."\n\n" .'* Name: '.($argument->getName() ?: '')."\n" .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n" .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n" .'* Description: '.($argument->getDescription() ?: '')."\n" .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'; } /** * {@inheritdoc} */ protected function describeInputOption(InputOption $option, array $options = array()) { return '**'.$option->getName().':**'."\n\n" .'* Name: `--'.$option->getName().'`'."\n" .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '')."\n" .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n" .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n" .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n" .'* Description: '.($option->getDescription() ?: '')."\n" .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'; } /** * {@inheritdoc} */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { $blocks = array(); if (count($definition->getArguments()) > 0) { $blocks[] = '### Arguments:'; foreach ($definition->getArguments() as $argument) { $blocks[] = $this->describeInputArgument($argument); } } if (count($definition->getOptions()) > 0) { $blocks[] = '### Options:'; foreach ($definition->getOptions() as $option) { $blocks[] = $this->describeInputOption($option); } } return implode("\n\n", $blocks); } /** * {@inheritdoc} */ protected function describeCommand(Command $command, array $options = array()) { $command->getSynopsis(); $command->mergeApplicationDefinition(false); $markdown = $command->getName()."\n" .str_repeat('-', strlen($command->getName()))."\n\n" .'* Description: '.($command->getDescription() ?: '')."\n" .'* Usage: `'.$command->getSynopsis().'`'."\n" .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : ''); if ($help = $command->getProcessedHelp()) { $markdown .= "\n\n".$help; } if ($definitionMarkdown = $this->describeInputDefinition($command->getNativeDefinition())) { $markdown .= "\n\n".$definitionMarkdown; } return $markdown; } /** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); $blocks = array($application->getName()."\n".str_repeat('=', strlen($application->getName()))); foreach ($description->getNamespaces() as $namespace) { if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $blocks[] = '**'.$namespace['id'].':**'; } $blocks[] = implode("\n", array_map(function ($commandName) { return '* '.$commandName; } , $namespace['commands'])); } foreach ($description->getCommands() as $command) { $blocks[] = $this->describeCommand($command); } return implode("\n\n", $blocks); } } ./Console-2.3.1/Symfony/Component/Console/Descriptor/Descriptor.php0000644001161000116100000000547612155624475023036 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; /** * @author Jean-François Simon */ abstract class Descriptor implements DescriptorInterface { public function describe($object, array $options = array()) { switch (true) { case $object instanceof InputArgument: return $this->describeInputArgument($object, $options); case $object instanceof InputOption: return $this->describeInputOption($object, $options); case $object instanceof InputDefinition: return $this->describeInputDefinition($object, $options); case $object instanceof Command: return $this->describeCommand($object, $options); case $object instanceof Application: return $this->describeApplication($object, $options); } throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object))); } /** * Describes an InputArgument instance. * * @param InputArgument $argument * @param array $options * * @return string|mixed */ abstract protected function describeInputArgument(InputArgument $argument, array $options = array()); /** * Describes an InputOption instance. * * @param InputOption $option * @param array $options * * @return string|mixed */ abstract protected function describeInputOption(InputOption $option, array $options = array()); /** * Describes an InputDefinition instance. * * @param InputDefinition $definition * @param array $options * * @return string|mixed */ abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array()); /** * Describes a Command instance. * * @param Command $command * @param array $options * * @return string|mixed */ abstract protected function describeCommand(Command $command, array $options = array()); /** * Describes an Application instance. * * @param Application $application * @param array $options * * @return string|mixed */ abstract protected function describeApplication(Application $application, array $options = array()); } ./Console-2.3.1/Symfony/Component/Console/Descriptor/ApplicationDescription.php0000644001161000116100000000667112155624475025365 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; /** * @author Jean-François Simon */ class ApplicationDescription { const GLOBAL_NAMESPACE = '_global'; /** * @var Application */ private $application; /** * @var null|string */ private $namespace; /** * @var array */ private $namespaces; /** * @var Command[] */ private $commands; /** * @var Command[] */ private $aliases; /** * Constructor. * * @param Application $application * @param string|null $namespace */ public function __construct(Application $application, $namespace = null) { $this->application = $application; $this->namespace = $namespace; } /** * @return array */ public function getNamespaces() { if (null === $this->namespaces) { $this->inspectApplication(); } return $this->namespaces; } /** * @return Command[] */ public function getCommands() { if (null === $this->commands) { $this->inspectApplication(); } return $this->commands; } /** * @param string $name * * @return Command * * @throws \InvalidArgumentException */ public function getCommand($name) { if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name)); } return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; } private function inspectApplication() { $this->commands = array(); $this->namespaces = array(); $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); foreach ($this->sortCommands($all) as $namespace => $commands) { $names = array(); /** @var Command $command */ foreach ($commands as $name => $command) { if (!$command->getName()) { continue; } if ($command->getName() === $name) { $this->commands[$name] = $command; } else { $this->aliases[$name] = $command; } $names[] = $name; } $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names); } } /** * @param array $commands * * @return array */ private function sortCommands(array $commands) { $namespacedCommands = array(); foreach ($commands as $name => $command) { $key = $this->application->extractNamespace($name, 1); if (!$key) { $key = '_global'; } $namespacedCommands[$key][$name] = $command; } ksort($namespacedCommands); foreach ($namespacedCommands as &$commands) { ksort($commands); } return $namespacedCommands; } } ./Console-2.3.1/Symfony/Component/Console/Application.php0000644001161000116100000010555512155624475021044 0ustar arar * * 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\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\HelpCommand; use Symfony\Component\Console\Command\ListCommand; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\DialogHelper; use Symfony\Component\Console\Helper\ProgressHelper; use Symfony\Component\Console\Helper\TableHelper; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Event\ConsoleExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * An Application is the container for a collection of commands. * * It is the main entry point of a Console application. * * This class is optimized for a standard CLI environment. * * Usage: * * $app = new Application('myapp', '1.0 (stable)'); * $app->add(new SimpleCommand()); * $app->run(); * * @author Fabien Potencier * * @api */ class Application { private $commands; private $wantHelps = false; private $runningCommand; private $name; private $version; private $catchExceptions; private $autoExit; private $definition; private $helperSet; private $dispatcher; /** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->name = $name; $this->version = $version; $this->catchExceptions = true; $this->autoExit = true; $this->commands = array(); $this->helperSet = $this->getDefaultHelperSet(); $this->definition = $this->getDefaultInputDefinition(); foreach ($this->getDefaultCommands() as $command) { $this->add($command); } } public function setDispatcher(EventDispatcherInterface $dispatcher) { $this->dispatcher = $dispatcher; } /** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code * * @throws \Exception When doRun returns Exception * * @api */ public function run(InputInterface $input = null, OutputInterface $output = null) { if (null === $input) { $input = new ArgvInput(); } if (null === $output) { $output = new ConsoleOutput(); } $this->configureIO($input, $output); try { $exitCode = $this->doRun($input, $output); } catch (\Exception $e) { if (!$this->catchExceptions) { throw $e; } if ($output instanceof ConsoleOutputInterface) { $this->renderException($e, $output->getErrorOutput()); } else { $this->renderException($e, $output); } $exitCode = $e->getCode(); if (is_numeric($exitCode)) { $exitCode = (int) $exitCode; if (0 === $exitCode) { $exitCode = 1; } } else { $exitCode = 1; } } if ($this->autoExit) { if ($exitCode > 255) { $exitCode = 255; } // @codeCoverageIgnoreStart exit($exitCode); // @codeCoverageIgnoreEnd } return $exitCode; } /** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ public function doRun(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--version', '-V'))) { $output->writeln($this->getLongVersion()); return 0; } $name = $this->getCommandName($input); if (true === $input->hasParameterOption(array('--help', '-h'))) { if (!$name) { $name = 'help'; $input = new ArrayInput(array('command' => 'help')); } else { $this->wantHelps = true; } } if (!$name) { $name = 'list'; $input = new ArrayInput(array('command' => 'list')); } // the command name MUST be the first element of the input $command = $this->find($name); $this->runningCommand = $command; $exitCode = $this->doRunCommand($command, $input, $output); $this->runningCommand = null; return $exitCode; } /** * Set a helper set to be used with the command. * * @param HelperSet $helperSet The helper set * * @api */ public function setHelperSet(HelperSet $helperSet) { $this->helperSet = $helperSet; } /** * Get the helper set associated with the command. * * @return HelperSet The HelperSet instance associated with this command * * @api */ public function getHelperSet() { return $this->helperSet; } /** * Set an input definition set to be used with this application * * @param InputDefinition $definition The input definition * * @api */ public function setDefinition(InputDefinition $definition) { $this->definition = $definition; } /** * Gets the InputDefinition related to this Application. * * @return InputDefinition The InputDefinition instance */ public function getDefinition() { return $this->definition; } /** * Gets the help message. * * @return string A help message. */ public function getHelp() { $messages = array( $this->getLongVersion(), '', 'Usage:', ' [options] command [arguments]', '', 'Options:', ); foreach ($this->getDefinition()->getOptions() as $option) { $messages[] = sprintf(' %-29s %s %s', '--'.$option->getName().'', $option->getShortcut() ? '-'.$option->getShortcut().'' : ' ', $option->getDescription() ); } return implode(PHP_EOL, $messages); } /** * Sets whether to catch exceptions or not during commands execution. * * @param Boolean $boolean Whether to catch exceptions or not during commands execution * * @api */ public function setCatchExceptions($boolean) { $this->catchExceptions = (Boolean) $boolean; } /** * Sets whether to automatically exit after a command execution or not. * * @param Boolean $boolean Whether to automatically exit after a command execution or not * * @api */ public function setAutoExit($boolean) { $this->autoExit = (Boolean) $boolean; } /** * Gets the name of the application. * * @return string The application name * * @api */ public function getName() { return $this->name; } /** * Sets the application name. * * @param string $name The application name * * @api */ public function setName($name) { $this->name = $name; } /** * Gets the application version. * * @return string The application version * * @api */ public function getVersion() { return $this->version; } /** * Sets the application version. * * @param string $version The application version * * @api */ public function setVersion($version) { $this->version = $version; } /** * Returns the long version of the application. * * @return string The long application version * * @api */ public function getLongVersion() { if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) { return sprintf('%s version %s', $this->getName(), $this->getVersion()); } return 'Console Tool'; } /** * Registers a new command. * * @param string $name The command name * * @return Command The newly created command * * @api */ public function register($name) { return $this->add(new Command($name)); } /** * Adds an array of command objects. * * @param Command[] $commands An array of commands * * @api */ public function addCommands(array $commands) { foreach ($commands as $command) { $this->add($command); } } /** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command $command A Command object * * @return Command The registered command * * @api */ public function add(Command $command) { $command->setApplication($this); if (!$command->isEnabled()) { $command->setApplication(null); return; } $this->commands[$command->getName()] = $command; foreach ($command->getAliases() as $alias) { $this->commands[$alias] = $command; } return $command; } /** * Returns a registered command by name or alias. * * @param string $name The command name or alias * * @return Command A Command object * * @throws \InvalidArgumentException When command name given does not exist * * @api */ public function get($name) { if (!isset($this->commands[$name])) { throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name)); } $command = $this->commands[$name]; if ($this->wantHelps) { $this->wantHelps = false; $helpCommand = $this->get('help'); $helpCommand->setCommand($command); return $helpCommand; } return $command; } /** * Returns true if the command exists, false otherwise. * * @param string $name The command name or alias * * @return Boolean true if the command exists, false otherwise * * @api */ public function has($name) { return isset($this->commands[$name]); } /** * Returns an array of all unique namespaces used by currently registered commands. * * It does not returns the global namespace which always exists. * * @return array An array of namespaces */ public function getNamespaces() { $namespaces = array(); foreach ($this->commands as $command) { $namespaces[] = $this->extractNamespace($command->getName()); foreach ($command->getAliases() as $alias) { $namespaces[] = $this->extractNamespace($alias); } } return array_values(array_unique(array_filter($namespaces))); } /** * Finds a registered namespace by a name or an abbreviation. * * @param string $namespace A namespace or abbreviation to search for * * @return string A registered namespace * * @throws \InvalidArgumentException When namespace is incorrect or ambiguous */ public function findNamespace($namespace) { $allNamespaces = $this->getNamespaces(); $found = ''; foreach (explode(':', $namespace) as $i => $part) { // select sub-namespaces matching the current namespace we found $namespaces = array(); foreach ($allNamespaces as $n) { if ('' === $found || 0 === strpos($n, $found)) { $namespaces[$n] = explode(':', $n); } } $abbrevs = static::getAbbreviations(array_unique(array_values(array_filter(array_map(function ($p) use ($i) { return isset($p[$i]) ? $p[$i] : ''; }, $namespaces))))); if (!isset($abbrevs[$part])) { $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace); if (1 <= $i) { $part = $found.':'.$part; } if ($alternatives = $this->findAlternativeNamespace($part, $abbrevs)) { if (1 == count($alternatives)) { $message .= "\n\nDid you mean this?\n "; } else { $message .= "\n\nDid you mean one of these?\n "; } $message .= implode("\n ", $alternatives); } throw new \InvalidArgumentException($message); } // there are multiple matches, but $part is an exact match of one of them so we select it if (in_array($part, $abbrevs[$part])) { $abbrevs[$part] = array($part); } if (count($abbrevs[$part]) > 1) { throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($abbrevs[$part]))); } $found .= $found ? ':' . $abbrevs[$part][0] : $abbrevs[$part][0]; } return $found; } /** * Finds a command by name or alias. * * Contrary to get, this command tries to find the best * match if you give it an abbreviation of a name or alias. * * @param string $name A command name or a command alias * * @return Command A Command instance * * @throws \InvalidArgumentException When command name is incorrect or ambiguous * * @api */ public function find($name) { // namespace $namespace = ''; $searchName = $name; if (false !== $pos = strrpos($name, ':')) { $namespace = $this->findNamespace(substr($name, 0, $pos)); $searchName = $namespace.substr($name, $pos); } // name $commands = array(); foreach ($this->commands as $command) { $extractedNamespace = $this->extractNamespace($command->getName()); if ($extractedNamespace === $namespace || !empty($namespace) && 0 === strpos($extractedNamespace, $namespace) ) { $commands[] = $command->getName(); } } $abbrevs = static::getAbbreviations(array_unique($commands)); if (isset($abbrevs[$searchName]) && 1 == count($abbrevs[$searchName])) { return $this->get($abbrevs[$searchName][0]); } if (isset($abbrevs[$searchName]) && in_array($searchName, $abbrevs[$searchName])) { return $this->get($searchName); } if (isset($abbrevs[$searchName]) && count($abbrevs[$searchName]) > 1) { $suggestions = $this->getAbbreviationSuggestions($abbrevs[$searchName]); throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions)); } // aliases $aliases = array(); foreach ($this->commands as $command) { foreach ($command->getAliases() as $alias) { $extractedNamespace = $this->extractNamespace($alias); if ($extractedNamespace === $namespace || !empty($namespace) && 0 === strpos($extractedNamespace, $namespace) ) { $aliases[] = $alias; } } } $aliases = static::getAbbreviations(array_unique($aliases)); if (!isset($aliases[$searchName])) { $message = sprintf('Command "%s" is not defined.', $name); if ($alternatives = $this->findAlternativeCommands($searchName, $abbrevs)) { if (1 == count($alternatives)) { $message .= "\n\nDid you mean this?\n "; } else { $message .= "\n\nDid you mean one of these?\n "; } $message .= implode("\n ", $alternatives); } throw new \InvalidArgumentException($message); } if (count($aliases[$searchName]) > 1) { throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $this->getAbbreviationSuggestions($aliases[$searchName]))); } return $this->get($aliases[$searchName][0]); } /** * Gets the commands (registered in the given namespace if provided). * * The array keys are the full names and the values the command instances. * * @param string $namespace A namespace name * * @return Command[] An array of Command instances * * @api */ public function all($namespace = null) { if (null === $namespace) { return $this->commands; } $commands = array(); foreach ($this->commands as $name => $command) { if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) { $commands[$name] = $command; } } return $commands; } /** * Returns an array of possible abbreviations given a set of names. * * @param array $names An array of names * * @return array An array of abbreviations */ public static function getAbbreviations($names) { $abbrevs = array(); foreach ($names as $name) { for ($len = strlen($name); $len > 0; --$len) { $abbrev = substr($name, 0, $len); $abbrevs[$abbrev][] = $name; } } return $abbrevs; } /** * Returns a text representation of the Application. * * @param string $namespace An optional namespace name * @param boolean $raw Whether to return raw command list * * @return string A string representing the Application * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asText($namespace = null, $raw = false) { $descriptor = new TextDescriptor(); return $descriptor->describe($this, array('namespace' => $namespace, 'raw_text' => $raw)); } /** * Returns an XML representation of the Application. * * @param string $namespace An optional namespace name * @param Boolean $asDom Whether to return a DOM or an XML string * * @return string|\DOMDocument An XML string representing the Application * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asXml($namespace = null, $asDom = false) { $descriptor = new XmlDescriptor(); return $descriptor->describe($this, array('namespace' => $namespace, 'as_dom' => $asDom)); } /** * Renders a caught exception. * * @param Exception $e An exception instance * @param OutputInterface $output An OutputInterface instance */ public function renderException($e, $output) { $strlen = function ($string) { if (!function_exists('mb_strlen')) { return strlen($string); } if (false === $encoding = mb_detect_encoding($string)) { return strlen($string); } return mb_strlen($string, $encoding); }; do { $title = sprintf(' [%s] ', get_class($e)); $len = $strlen($title); $width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX; $lines = array(); foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) { foreach (str_split($line, $width - 4) as $line) { $lines[] = sprintf(' %s ', $line); $len = max($strlen($line) + 4, $len); } } $messages = array(str_repeat(' ', $len), $title.str_repeat(' ', max(0, $len - $strlen($title)))); foreach ($lines as $line) { $messages[] = $line.str_repeat(' ', $len - $strlen($line)); } $messages[] = str_repeat(' ', $len); $output->writeln(""); $output->writeln(""); foreach ($messages as $message) { $output->writeln(''.$message.''); } $output->writeln(""); $output->writeln(""); if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln('Exception trace:'); // exception related properties $trace = $e->getTrace(); array_unshift($trace, array( 'function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array(), )); for ($i = 0, $count = count($trace); $i < $count; $i++) { $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; $function = $trace[$i]['function']; $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a'; $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a'; $output->writeln(sprintf(' %s%s%s() at %s:%s', $class, $type, $function, $file, $line)); } $output->writeln(""); $output->writeln(""); } } while ($e = $e->getPrevious()); if (null !== $this->runningCommand) { $output->writeln(sprintf('%s', sprintf($this->runningCommand->getSynopsis(), $this->getName()))); $output->writeln(""); $output->writeln(""); } } /** * Tries to figure out the terminal width in which this application runs * * @return int|null */ protected function getTerminalWidth() { $dimensions = $this->getTerminalDimensions(); return $dimensions[0]; } /** * Tries to figure out the terminal height in which this application runs * * @return int|null */ protected function getTerminalHeight() { $dimensions = $this->getTerminalDimensions(); return $dimensions[1]; } /** * Tries to figure out the terminal dimensions based on the current environment * * @return array Array containing width and height */ public function getTerminalDimensions() { if (defined('PHP_WINDOWS_VERSION_BUILD')) { // extract [w, H] from "wxh (WxH)" if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) { return array((int) $matches[1], (int) $matches[2]); } // extract [w, h] from "wxh" if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) { return array((int) $matches[1], (int) $matches[2]); } } if ($sttyString = $this->getSttyColumns()) { // extract [w, h] from "rows h; columns w;" if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { return array((int) $matches[2], (int) $matches[1]); } // extract [w, h] from "; h rows; w columns" if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { return array((int) $matches[2], (int) $matches[1]); } } return array(null, null); } /** * Configures the input and output instances based on the user arguments and options. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function configureIO(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--ansi'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'))) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } if (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); if (!posix_isatty($inputStream)) { $input->setInteractive(false); } } if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } else { if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) { $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } } } /** * Runs the current command. * * If an event dispatcher has been attached to the application, * events are also dispatched during the life-cycle of the command. * * @param Command $command A Command instance * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) { if (null === $this->dispatcher) { return $command->run($input, $output); } $event = new ConsoleCommandEvent($command, $input, $output); $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event); try { $exitCode = $command->run($input, $output); } catch (\Exception $e) { $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode()); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode()); $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event); throw $event->getException(); } $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); return $event->getExitCode(); } /** * Gets the name of the command based on input. * * @param InputInterface $input The input interface * * @return string The command name */ protected function getCommandName(InputInterface $input) { return $input->getFirstArgument(); } /** * Gets the default input definition. * * @return InputDefinition An InputDefinition instance */ protected function getDefaultInputDefinition() { return new InputDefinition(array( new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'), new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'), new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'), new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version.'), new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'), new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'), new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'), )); } /** * Gets the default commands that should always be available. * * @return Command[] An array of default Command instances */ protected function getDefaultCommands() { return array(new HelpCommand(), new ListCommand()); } /** * Gets the default helper set with the helpers that should always be available. * * @return HelperSet A HelperSet instance */ protected function getDefaultHelperSet() { return new HelperSet(array( new FormatterHelper(), new DialogHelper(), new ProgressHelper(), new TableHelper(), )); } /** * Runs and parses stty -a if it's available, suppressing any error output * * @return string */ private function getSttyColumns() { if (!function_exists('proc_open')) { return; } $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true)); if (is_resource($process)) { $info = stream_get_contents($pipes[1]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); return $info; } } /** * Runs and parses mode CON if it's available, suppressing any error output * * @return string x or null if it could not be parsed */ private function getConsoleMode() { if (!function_exists('proc_open')) { return; } $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true)); if (is_resource($process)) { $info = stream_get_contents($pipes[1]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { return $matches[2].'x'.$matches[1]; } } } /** * Returns abbreviated suggestions in string format. * * @param array $abbrevs Abbreviated suggestions to convert * * @return string A formatted string of abbreviated suggestions */ private function getAbbreviationSuggestions($abbrevs) { return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : ''); } /** * Returns the namespace part of the command name. * * This method is not part of public API and should not be used directly. * * @param string $name The full name of the command * @param string $limit The maximum number of parts of the namespace * * @return string The namespace of the command */ public function extractNamespace($name, $limit = null) { $parts = explode(':', $name); array_pop($parts); return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit)); } /** * Finds alternative commands of $name * * @param string $name The full name of the command * @param array $abbrevs The abbreviations * * @return array A sorted array of similar commands */ private function findAlternativeCommands($name, $abbrevs) { $callback = function($item) { return $item->getName(); }; return $this->findAlternatives($name, $this->commands, $abbrevs, $callback); } /** * Finds alternative namespace of $name * * @param string $name The full name of the namespace * @param array $abbrevs The abbreviations * * @return array A sorted array of similar namespace */ private function findAlternativeNamespace($name, $abbrevs) { return $this->findAlternatives($name, $this->getNamespaces(), $abbrevs); } /** * Finds alternative of $name among $collection, * if nothing is found in $collection, try in $abbrevs * * @param string $name The string * @param array|Traversable $collection The collection * @param array $abbrevs The abbreviations * @param Closure|string|array $callback The callable to transform collection item before comparison * * @return array A sorted array of similar string */ private function findAlternatives($name, $collection, $abbrevs, $callback = null) { $alternatives = array(); foreach ($collection as $item) { if (null !== $callback) { $item = call_user_func($callback, $item); } $lev = levenshtein($name, $item); if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) { $alternatives[$item] = $lev; } } if (!$alternatives) { foreach ($abbrevs as $key => $values) { $lev = levenshtein($name, $key); if ($lev <= strlen($name) / 3 || false !== strpos($key, $name)) { foreach ($values as $value) { $alternatives[$value] = $lev; } } } } asort($alternatives); return array_keys($alternatives); } } ./Console-2.3.1/Symfony/Component/Console/Output/0000755001161000116100000000000012165326424017347 5ustar arar./Console-2.3.1/Symfony/Component/Console/Output/ConsoleOutputInterface.php0000644001161000116100000000160212155624475024531 0ustar arar * * 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 */ interface ConsoleOutputInterface extends OutputInterface { /** * Gets the OutputInterface for errors. * * @return OutputInterface */ public function getErrorOutput(); /** * Sets the OutputInterface used for errors. * * @param OutputInterface $error */ public function setErrorOutput(OutputInterface $error); } ./Console-2.3.1/Symfony/Component/Console/Output/NullOutput.php0000644001161000116100000000332412155624475022223 0ustar arar * * 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; /** * NullOutput suppresses all output. * * $output = new NullOutput(); * * @author Fabien Potencier * @author Tobias Schultze * * @api */ class NullOutput implements OutputInterface { /** * {@inheritdoc} */ public function setFormatter(OutputFormatterInterface $formatter) { // do nothing } /** * {@inheritdoc} */ public function getFormatter() { // to comply with the interface we must return a OutputFormatterInterface return new OutputFormatter(); } /** * {@inheritdoc} */ public function setDecorated($decorated) { // do nothing } /** * {@inheritdoc} */ public function isDecorated() { return false; } /** * {@inheritdoc} */ public function setVerbosity($level) { // do nothing } /** * {@inheritdoc} */ public function getVerbosity() { return self::VERBOSITY_QUIET; } /** * {@inheritdoc} */ public function writeln($messages, $type = self::OUTPUT_NORMAL) { // do nothing } /** * {@inheritdoc} */ public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL) { // do nothing } } ./Console-2.3.1/Symfony/Component/Console/Output/Output.php0000644001161000116100000000725212155624475021374 0ustar arar * * 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 five levels of verbosity: * * * normal: no option passed (normal output) * * verbose: -v (more output) * * very verbose: -vv (highly extended output) * * debug: -vvv (all debug output) * * quiet: -q (no output) * * @author Fabien Potencier * * @api */ abstract class Output implements OutputInterface { private $verbosity; private $formatter; /** * Constructor. * * @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) * @param Boolean $decorated Whether to decorate messages * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) * * @api */ public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null) { $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity; $this->formatter = null === $formatter ? new OutputFormatter() : $formatter; $this->formatter->setDecorated($decorated); } /** * {@inheritdoc} */ public function setFormatter(OutputFormatterInterface $formatter) { $this->formatter = $formatter; } /** * {@inheritdoc} */ public function getFormatter() { return $this->formatter; } /** * {@inheritdoc} */ public function setDecorated($decorated) { $this->formatter->setDecorated($decorated); } /** * {@inheritdoc} */ public function isDecorated() { return $this->formatter->isDecorated(); } /** * {@inheritdoc} */ public function setVerbosity($level) { $this->verbosity = (int) $level; } /** * {@inheritdoc} */ public function getVerbosity() { return $this->verbosity; } /** * {@inheritdoc} */ public function writeln($messages, $type = self::OUTPUT_NORMAL) { $this->write($messages, true, $type); } /** * {@inheritdoc} */ public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL) { 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); } ./Console-2.3.1/Symfony/Component/Console/Output/ConsoleOutput.php0000644001161000116100000000567212155624475022723 0ustar arar * * 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\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 * * @api */ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { private $stderr; /** * Constructor. * * @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) * @param Boolean|null $decorated Whether to decorate messages (null for auto-guessing) * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) * * @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); } /** * {@inheritdoc} */ public function setDecorated($decorated) { parent::setDecorated($decorated); $this->stderr->setDecorated($decorated); } /** * {@inheritdoc} */ public function setFormatter(OutputFormatterInterface $formatter) { parent::setFormatter($formatter); $this->stderr->setFormatter($formatter); } /** * {@inheritdoc} */ public function setVerbosity($level) { parent::setVerbosity($level); $this->stderr->setVerbosity($level); } /** * {@inheritdoc} */ public function getErrorOutput() { return $this->stderr; } /** * {@inheritdoc} */ 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')); } } ./Console-2.3.1/Symfony/Component/Console/Output/OutputInterface.php0000644001161000116100000000551512155624475023215 0ustar arar * * 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 * * @api */ interface OutputInterface { const VERBOSITY_QUIET = 0; const VERBOSITY_NORMAL = 1; const VERBOSITY_VERBOSE = 2; const VERBOSITY_VERY_VERBOSE = 3; const VERBOSITY_DEBUG = 4; 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 or a single string * @param Boolean $newline Whether to add a newline * @param integer $type The type of output (one of the OUTPUT constants) * * @throws \InvalidArgumentException When unknown output type is given * * @api */ public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL); /** * 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 (one of the OUTPUT constants) * * @throws \InvalidArgumentException When unknown output type is given * * @api */ public function writeln($messages, $type = self::OUTPUT_NORMAL); /** * Sets the verbosity of the output. * * @param integer $level The level of verbosity (one of the VERBOSITY constants) * * @api */ public function setVerbosity($level); /** * Gets the current verbosity of the output. * * @return integer The current level of verbosity (one of the VERBOSITY constants) * * @api */ public function getVerbosity(); /** * Sets the decorated flag. * * @param Boolean $decorated Whether to decorate the messages * * @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(); } ./Console-2.3.1/Symfony/Component/Console/Output/StreamOutput.php0000644001161000116100000000611512155624475022545 0ustar arar * * 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 * * @api */ class StreamOutput extends Output { private $stream; /** * Constructor. * * @param mixed $stream A stream resource * @param integer $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) * @param Boolean|null $decorated Whether to decorate messages (null for auto-guessing) * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) * * @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(); } parent::__construct($verbosity, $decorated, $formatter); } /** * Gets the stream attached to this StreamOutput instance. * * @return resource A stream resource */ public function getStream() { return $this->stream; } /** * {@inheritdoc} */ 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 and ConEmu * - non tty consoles * * @return Boolean true if the stream supports colorization, false otherwise */ protected function hasColorSupport() { // @codeCoverageIgnoreStart if (DIRECTORY_SEPARATOR == '\\') { return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); } return function_exists('posix_isatty') && @posix_isatty($this->stream); // @codeCoverageIgnoreEnd } } ./Console-2.3.1/Symfony/Component/Console/composer.json0000644001161000116100000000154512155624475020604 0ustar arar{ "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" }, "require-dev": { "symfony/event-dispatcher": "~2.1" }, "suggest": { "symfony/event-dispatcher": "" }, "autoload": { "psr-0": { "Symfony\\Component\\Console\\": "" } }, "target-dir": "Symfony/Component/Console", "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "2.3-dev" } } } ./Console-2.3.1/Symfony/Component/Console/Shell.php0000644001161000116100000001450612155624475017643 0ustar arar * * 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 * @author Martin Hasoň */ class Shell { private $application; private $history; private $output; private $hasReadline; 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->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(<<Running with process isolation, you should consider this: * 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('The command terminated with an error status (%s)', $ret)); } } } /** * Returns the shell header. * * @return string The header string */ protected function getHeader() { return <<{$this->application->getName()} shell ({$this->application->getVersion()}). At the prompt, type help for some help, or list to get a list of available commands. To exit the shell, type ^D. EOF; } /** * Renders a prompt. * * @return string The prompt */ protected function getPrompt() { // using the formatter here is required when using readline return $this->output->getFormatter()->format($this->application->getName().' > '); } protected function getOutput() { return $this->output; } protected function getApplication() { return $this->application; } /** * 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->getPrompt()); } else { $this->output->write($this->getPrompt()); $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; if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) { throw new \RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.'); } } } ./Console-2.3.1/Symfony/Component/Console/Tests/0000755001161000116100000000000012165326424017151 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Tester/0000755001161000116100000000000012165326424020417 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Tester/CommandTesterTest.php0000644001161000116100000000420112155624475024540 0ustar arar * * 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 $command; 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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Tester/ApplicationTesterTest.php0000644001161000116100000000430412155624475025431 0ustar arar * * 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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Command/0000755001161000116100000000000012165326424020527 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Command/HelpCommandTest.php0000644001161000116100000000546212155624475024304 0ustar arar * * 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 testExecuteForCommandAlias() { $command = new HelpCommand(); $command->setApplication(new Application()); $commandTester = new CommandTester($command); $commandTester->execute(array('command_name' => 'li')); $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); } public function testExecuteForCommand() { $command = new HelpCommand(); $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); $commandTester->execute(array()); $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForCommandWithXmlOption() { $command = new HelpCommand(); $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); $commandTester->execute(array('--format' => 'xml')); $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --xml is passed'); } public function testExecuteForApplicationCommand() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list')); $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForApplicationCommandWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Command/CommandTest.php0000644001161000116100000003453212155624475023473 0ustar arar * * 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() { $command = new Command('foo:bar'); $this->assertEquals('foo:bar', $command->getName(), '__construct() takes the command name as its first argument'); } /** * @expectedException \LogicException * @expectedExceptionMessage The command name cannot be empty. */ public function testCommandNameCannotBeEmpty() { new Command(); } 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'); } /** * @dataProvider provideInvalidCommandNames */ public function testInvalidCommandNames($name) { $this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name)); $command = new \TestCommand(); $command->setName($name); } public function provideInvalidCommandNames() { return array( array(''), array('foo:') ); } 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 testMergeApplicationDefinitionWithoutArgsThenWithArgsAddsArgs() { $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())); $r = new \ReflectionObject($command); $m = $r->getMethod('mergeApplicationDefinition'); $m->setAccessible(true); $m->invoke($command, false); $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition(false) merges the application and the commmand options'); $this->assertFalse($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(false) does not merge the application arguments'); $m->invoke($command, true); $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(true) merges the application arguments and the command arguments'); $m->invoke($command); $this->assertEquals(2, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments'); } public function testRunInteractive() { $tester = new CommandTester(new \TestCommand()); $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'); } public function testRunNonInteractive() { $tester = new CommandTester(new \TestCommand()); $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'); } /** * @expectedException \LogicException * @expectedExceptionMessage You must override the execute() method in the concrete command class. */ public function testExecuteMethodNeedsToBeOverriden() { $command = new Command('foo'); $command->run(new StringInput(''), new NullOutput()); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "--bar" option does not exist. */ public function testRunWithInvalidOption() { $command = new \TestCommand(); $tester = new CommandTester($command); $tester->execute(array('--bar' => true)); } public function testRunReturnsIntegerExitCode() { $command = new \TestCommand(); $exitCode = $command->run(new StringInput(''), new NullOutput()); $this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)'); $command = $this->getMock('TestCommand', array('execute')); $command->expects($this->once()) ->method('execute') ->will($this->returnValue('2.3')); $exitCode = $command->run(new StringInput(''), new NullOutput()); $this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)'); } public function testRunReturnsAlwaysInteger() { $command = new \TestCommand(); $this->assertSame(0, $command->run(new StringInput(''), new NullOutput())); } 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 testSetCodeWithNonClosureCallable() { $command = new \TestCommand(); $ret = $command->setCode(array($this, 'callableMethodCommand')); $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()); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Invalid callable provided to Command::setCode. */ public function testSetCodeWithNonCallable() { $command = new \TestCommand(); $command->setCode(array($this, 'nonExistentMethod')); } public function callableMethodCommand(InputInterface $input, OutputInterface $output) { $output->writeln('from the code...'); } 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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Command/ListCommandTest.php0000644001161000116100000000450312155624475024322 0ustar arar * * 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 testExecuteListsCommands() { $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'); } public function testExecuteListsCommandsWithXmlOption() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml')); $this->assertRegExp('//', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); } public function testExecuteListsCommandsWithRawOption() { $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), '--raw' => true)); $output = <<assertEquals($output, $commandTester->getDisplay(true)); } public function testExecuteListsCommandsWithNamespaceArgument() { require_once(realpath(__DIR__.'/../Fixtures/FooCommand.php')); $application = new Application(); $application->add(new \FooCommand()); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), 'namespace' => 'foo', '--raw' => true)); $output = <<assertEquals($output, $commandTester->getDisplay(true)); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/0000755001161000116100000000000012165326424021267 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php0000644001161000116100000000110412155624475026463 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\MarkdownDescriptor; class MarkdownDescriptorTest extends AbstractDescriptorTest { protected function getDescriptor() { return new MarkdownDescriptor(); } protected function getFormat() { return 'md'; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/XmlDescriptorTest.php0000644001161000116100000000106612155624475025450 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; class XmlDescriptorTest extends AbstractDescriptorTest { protected function getDescriptor() { return new XmlDescriptor(); } protected function getFormat() { return 'xml'; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php0000644001161000116100000000707212155624475026456 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Descriptor\DescriptorInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase { /** @dataProvider getDescribeInputArgumentTestData */ public function testDescribeInputArgument(InputArgument $argument, $expectedDescription) { $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($argument))); } /** @dataProvider getDescribeInputOptionTestData */ public function testDescribeInputOption(InputOption $option, $expectedDescription) { $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($option))); } /** @dataProvider getDescribeInputDefinitionTestData */ public function testDescribeInputDefinition(InputDefinition $definition, $expectedDescription) { $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($definition))); } /** @dataProvider getDescribeCommandTestData */ public function testDescribeCommand(Command $command, $expectedDescription) { $this->assertEquals(trim($expectedDescription), trim($this->getDescriptor()->describe($command))); } /** @dataProvider getDescribeApplicationTestData */ public function testDescribeApplication(Application $application, $expectedDescription) { // 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. foreach ($application->all() as $command) { $command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp())); } $this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $this->getDescriptor()->describe($application)))); } public function getDescribeInputArgumentTestData() { return $this->getDescriptionTestData(ObjectsProvider::getInputArguments()); } public function getDescribeInputOptionTestData() { return $this->getDescriptionTestData(ObjectsProvider::getInputOptions()); } public function getDescribeInputDefinitionTestData() { return $this->getDescriptionTestData(ObjectsProvider::getInputDefinitions()); } public function getDescribeCommandTestData() { return $this->getDescriptionTestData(ObjectsProvider::getCommands()); } public function getDescribeApplicationTestData() { return $this->getDescriptionTestData(ObjectsProvider::getApplications()); } abstract protected function getDescriptor(); abstract protected function getFormat(); private function getDescriptionTestData(array $objects) { $data = array(); foreach ($objects as $name => $object) { $description = file_get_contents(sprintf('%s/../Fixtures/%s.%s', __DIR__, $name, $this->getFormat())); $data[] = array($object, $description); } return $data; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php0000644001161000116100000000556612155624475025126 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication1; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication2; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand1; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand2; use Symfony\Component\Finder\Shell\Command; /** * @author Jean-François Simon */ class ObjectsProvider { public static function getInputArguments() { return array( 'input_argument_1' => new InputArgument('argument_name', InputArgument::REQUIRED), 'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'), 'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'), ); } public static function getInputOptions() { return array( 'input_option_1' => new InputOption('option_name', 'o', InputOption::VALUE_NONE), 'input_option_2' => new InputOption('option_name', 'o', InputOption::VALUE_OPTIONAL, 'option description', 'default_value'), 'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'), 'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()), ); } public static function getInputDefinitions() { return array( 'input_definition_1' => new InputDefinition(), 'input_definition_2' => new InputDefinition(array(new InputArgument('argument_name', InputArgument::REQUIRED))), 'input_definition_3' => new InputDefinition(array(new InputOption('option_name', 'o', InputOption::VALUE_NONE))), 'input_definition_4' => new InputDefinition(array( new InputArgument('argument_name', InputArgument::REQUIRED), new InputOption('option_name', 'o', InputOption::VALUE_NONE), )), ); } public static function getCommands() { return array( 'command_1' => new DescriptorCommand1(), 'command_2' => new DescriptorCommand2(), ); } public static function getApplications() { return array( 'application_1' => new DescriptorApplication1(), 'application_2' => new DescriptorApplication2(), ); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/JsonDescriptorTest.php0000644001161000116100000000107212155624475025616 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\JsonDescriptor; class JsonDescriptorTest extends AbstractDescriptorTest { protected function getDescriptor() { return new JsonDescriptor(); } protected function getFormat() { return 'json'; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php0000644001161000116100000000107112155624475025630 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\TextDescriptor; class TextDescriptorTest extends AbstractDescriptorTest { protected function getDescriptor() { return new TextDescriptor(); } protected function getFormat() { return 'txt'; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Output/0000755001161000116100000000000012165326424020451 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Output/StreamOutputTest.php0000644001161000116100000000340712155624475024510 0ustar arar * * 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() { $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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The StreamOutput class needs a stream as its first argument. */ public function testStreamIsRequired() { new StreamOutput('foo'); } 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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Output/ConsoleOutputTest.php0000644001161000116100000000130312155624475024650 0ustar arar * * 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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Output/OutputTest.php0000644001161000116100000001003712155624475023331 0ustar arar * * 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 testWriteWithVerbosityQuiet() { $output = new TestOutput(Output::VERBOSITY_QUIET); $output->writeln('foo'); $this->assertEquals('', $output->output, '->writeln() outputs nothing if verbosity is set to VERBOSITY_QUIET'); } public function testWriteAnArrayOfMessages() { $output = new TestOutput(); $output->writeln(array('foo', 'bar')); $this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output'); } /** * @dataProvider provideWriteArguments */ public function testWriteRawMessage($message, $type, $expectedOutput) { $output = new TestOutput(); $output->writeln($message, $type); $this->assertEquals($expectedOutput, $output->output); } public function provideWriteArguments() { return array( array('foo', Output::OUTPUT_RAW, "foo\n"), array('foo', Output::OUTPUT_PLAIN, "foo\n"), ); } public function testWriteWithDecorationTurnedOff() { $output = new TestOutput(); $output->setDecorated(false); $output->writeln('foo'); $this->assertEquals("foo\n", $output->output, '->writeln() strips decoration tags if decoration is set to false'); } public function testWriteDecoratedMessage() { $fooStyle = new OutputFormatterStyle('yellow', 'red', array('blink')); $output = new TestOutput(); $output->getFormatter()->setStyle('FOO', $fooStyle); $output->setDecorated(true); $output->writeln('foo'); $this->assertEquals("\033[33;41;5mfoo\033[0m\n", $output->output, '->writeln() decorates the output'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Unknown output type given (24) */ public function testWriteWithInvalidOutputType() { $output = new TestOutput(); $output->writeln('foo', 24); } public function testWriteWithInvalidStyle() { $output = new TestOutput(); $output->clear(); $output->write('foo'); $this->assertEquals('foo', $output->output, '->write() do nothing when a style does not exist'); $output->clear(); $output->writeln('foo'); $this->assertEquals("foo\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" : ''); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Output/NullOutputTest.php0000644001161000116100000000236512155624475024171 0ustar arar * * 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; use Symfony\Component\Console\Output\OutputInterface; class NullOutputTest extends \PHPUnit_Framework_TestCase { public function testConstructor() { $output = new NullOutput(); ob_start(); $output->write('foo'); $buffer = ob_get_clean(); $this->assertSame('', $buffer, '->write() does nothing (at least nothing is printed)'); $this->assertFalse($output->isDecorated(), '->isDecorated() returns false'); } public function testVerbosity() { $output = new NullOutput(); $this->assertSame(OutputInterface::VERBOSITY_QUIET, $output->getVerbosity(), '->getVerbosity() returns VERBOSITY_QUIET for NullOutput by default'); $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); $this->assertSame(OutputInterface::VERBOSITY_QUIET, $output->getVerbosity(), '->getVerbosity() always returns VERBOSITY_QUIET for NullOutput'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/ApplicationTest.php0000644001161000116100000011472012155624475023000 0ustar arar * * 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\Helper\HelperSet; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\ApplicationTester; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\Console\Event\ConsoleExceptionEvent; use Symfony\Component\Console\Event\ConsoleTerminateEvent; use Symfony\Component\EventDispatcher\EventDispatcher; 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'; require_once self::$fixturesPath.'/Foo4Command.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('foo version bar', $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'); $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->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $command, '->get() returns the help command if --help is provided as the input'); } public function testSilentHelp() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $tester = new ApplicationTester($application); $tester->run(array('-h' => true, '-q' => true), array('decorated' => false)); $this->assertEmpty($tester->getDisplay(true)); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The command "foofoo" does not exist. */ public function testGetInvalidCommand() { $application = new Application(); $application->get('foofoo'); } 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1). */ public function testFindAmbiguousNamespace() { $application = new Application(); $application->add(new \FooCommand()); $application->add(new \Foo2Command()); $application->findNamespace('f'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage There are no commands defined in the "bar" namespace. */ public function testFindInvalidNamespace() { $application = new Application(); $application->findNamespace('bar'); } public function testFind() { $application = new Application(); $application->add(new \FooCommand()); $this->assertInstanceOf('FooCommand', $application->find('foo:bar'), '->find() returns a command if its name exists'); $this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $application->find('h'), '->find() returns a command if its name exists'); $this->assertInstanceOf('FooCommand', $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); $this->assertInstanceOf('FooCommand', $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); $this->assertInstanceOf('FooCommand', $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); } /** * @dataProvider provideAmbiguousAbbreviations */ public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage) { $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); $application = new Application(); $application->add(new \FooCommand()); $application->add(new \Foo1Command()); $application->add(new \Foo2Command()); $application->find($abbreviation); } public function provideAmbiguousAbbreviations() { return array( array('f', 'Command "f" is not defined.'), array('a', 'Command "a" is ambiguous (afoobar, afoobar1 and 1 more).'), array('foo:b', 'Command "foo:b" is ambiguous (foo:bar, foo:bar1).') ); } public function testFindCommandEqualNamespace() { $application = new Application(); $application->add(new \Foo3Command()); $application->add(new \Foo4Command()); $this->assertInstanceOf('Foo3Command', $application->find('foo3:bar'), '->find() returns the good command even if a namespace has same name'); $this->assertInstanceOf('Foo4Command', $application->find('foo3:bar:toh'), '->find() returns a command even if its namespace equals another command name'); } /** * @dataProvider provideInvalidCommandNamesSingle * @expectedException \InvalidArgumentException * @expectedExceptionMessage Did you mean this */ public function testFindAlternativeExceptionMessageSingle($name) { $application = new Application(); $application->add(new \FooCommand()); $application->find($name); } public function provideInvalidCommandNamesSingle() { return array( array('foo:baR'), array('foO:bar') ); } public function testFindAlternativeExceptionMessageMultiple() { $application = new Application(); $application->add(new \FooCommand()); $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'); } $application->add(new \Foo3Command()); $application->add(new \Foo4Command()); // Subnamespace + plural try { $a = $application->find('foo3:'); $this->fail('->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives'); } catch (\Exception $e) { $this->assertInstanceOf('\InvalidArgumentException', $e); $this->assertRegExp('/foo3:bar/', $e->getMessage()); $this->assertRegExp('/foo3:bar:toh/', $e->getMessage()); } } 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 testFindNamespaceDoesNotFailOnDeepSimilarNamespaces() { $application = $this->getMock('Symfony\Component\Console\Application', array('getNamespaces')); $application->expects($this->once()) ->method('getNamespaces') ->will($this->returnValue(array('foo:sublong', 'bar:sub'))); $this->assertEquals('foo:sublong', $application->findNamespace('f:sub')); } 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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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); $tester->run(array('command' => 'foo'), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->run() runs the help command if --help is passed'); $tester->run(array('-h' => true), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_run2.txt', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->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', $tester->getDisplay(true), '->run() displays the program version if --version is passed'); $tester->run(array('-V' => true), array('decorated' => false)); $this->assertStringEqualsFile(self::$fixturesPath.'/application_run4.txt', $tester->getDisplay(true), '->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', '--verbose' => 1)); $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if --verbose=1 is passed'); $tester->run(array('command' => 'list', '--verbose' => 2)); $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to very verbose if --verbose=2 is passed'); $tester->run(array('command' => 'list', '--verbose' => 3)); $this->assertSame(Output::VERBOSITY_DEBUG, $tester->getOutput()->getVerbosity(), '->run() sets the output to debug if --verbose=3 is passed'); $tester->run(array('command' => 'list', '--verbose' => 4)); $this->assertSame(Output::VERBOSITY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if unknown --verbose level 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'); $tester->run(array('command' => 'list', '-vv' => true)); $this->assertSame(Output::VERBOSITY_VERY_VERBOSE, $tester->getOutput()->getVerbosity(), '->run() sets the output to verbose if -v is passed'); $tester->run(array('command' => 'list', '-vvv' => true)); $this->assertSame(Output::VERBOSITY_DEBUG, $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'); } public function testRunReturnsIntegerExitCode() { $exception = new \Exception('', 4); $application = $this->getMock('Symfony\Component\Console\Application', array('doRun')); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') ->will($this->throwException($exception)); $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); $this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception'); } public function testRunReturnsExitCodeOneForExceptionCodeZero() { $exception = new \Exception('', 0); $application = $this->getMock('Symfony\Component\Console\Application', array('doRun')); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') ->will($this->throwException($exception)); $exitCode = $application->run(new ArrayInput(array()), new NullOutput()); $this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0'); } /** * @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)), ); } public function testGetDefaultHelperSetReturnsDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $helperSet = $application->getHelperSet(); $this->assertTrue($helperSet->has('formatter')); $this->assertTrue($helperSet->has('dialog')); $this->assertTrue($helperSet->has('progress')); } public function testAddingSingleHelperSetOverwritesDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->setHelperSet(new HelperSet(array(new FormatterHelper()))); $helperSet = $application->getHelperSet(); $this->assertTrue($helperSet->has('formatter')); // no other default helper set should be returned $this->assertFalse($helperSet->has('dialog')); $this->assertFalse($helperSet->has('progress')); } public function testOverwritingDefaultHelperSetOverwritesDefaultValues() { $application = new CustomApplication(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->setHelperSet(new HelperSet(array(new FormatterHelper()))); $helperSet = $application->getHelperSet(); $this->assertTrue($helperSet->has('formatter')); // no other default helper set should be returned $this->assertFalse($helperSet->has('dialog')); $this->assertFalse($helperSet->has('progress')); } public function testGetDefaultInputDefinitionReturnsDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $inputDefinition = $application->getDefinition(); $this->assertTrue($inputDefinition->hasArgument('command')); $this->assertTrue($inputDefinition->hasOption('help')); $this->assertTrue($inputDefinition->hasOption('quiet')); $this->assertTrue($inputDefinition->hasOption('verbose')); $this->assertTrue($inputDefinition->hasOption('version')); $this->assertTrue($inputDefinition->hasOption('ansi')); $this->assertTrue($inputDefinition->hasOption('no-ansi')); $this->assertTrue($inputDefinition->hasOption('no-interaction')); } public function testOverwritingDefaultInputDefinitionOverwritesDefaultValues() { $application = new CustomApplication(); $application->setAutoExit(false); $application->setCatchExceptions(false); $inputDefinition = $application->getDefinition(); // check whether the default arguments and options are not returned any more $this->assertFalse($inputDefinition->hasArgument('command')); $this->assertFalse($inputDefinition->hasOption('help')); $this->assertFalse($inputDefinition->hasOption('quiet')); $this->assertFalse($inputDefinition->hasOption('verbose')); $this->assertFalse($inputDefinition->hasOption('version')); $this->assertFalse($inputDefinition->hasOption('ansi')); $this->assertFalse($inputDefinition->hasOption('no-ansi')); $this->assertFalse($inputDefinition->hasOption('no-interaction')); $this->assertTrue($inputDefinition->hasOption('custom')); } public function testSettingCustomInputDefinitionOverwritesDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->setDefinition(new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')))); $inputDefinition = $application->getDefinition(); // check whether the default arguments and options are not returned any more $this->assertFalse($inputDefinition->hasArgument('command')); $this->assertFalse($inputDefinition->hasOption('help')); $this->assertFalse($inputDefinition->hasOption('quiet')); $this->assertFalse($inputDefinition->hasOption('verbose')); $this->assertFalse($inputDefinition->hasOption('version')); $this->assertFalse($inputDefinition->hasOption('ansi')); $this->assertFalse($inputDefinition->hasOption('no-ansi')); $this->assertFalse($inputDefinition->hasOption('no-interaction')); $this->assertTrue($inputDefinition->hasOption('custom')); } public function testRunWithDispatcher() { if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $application = new Application(); $application->setAutoExit(false); $application->setDispatcher($this->getDispatcher()); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertEquals('before.foo.after.', $tester->getDisplay()); } /** * @expectedException \LogicException * @expectedExceptionMessage caught */ public function testRunWithExceptionAndDispatcher() { if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); } public function testRunDispatchesAllEventsWithException() { if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $application = new Application(); $application->setDispatcher($this->getDispatcher()); $application->setAutoExit(false); $application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) { $output->write('foo.'); throw new \RuntimeException('foo'); }); $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); } protected function getDispatcher() { $dispatcher = new EventDispatcher; $dispatcher->addListener('console.command', function (ConsoleCommandEvent $event) { $event->getOutput()->write('before.'); }); $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) { $event->getOutput()->write('after.'); $event->setExitCode(128); }); $dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) { $event->getOutput()->writeln('caught.'); $event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException())); }); return $dispatcher; } } class CustomApplication extends Application { /** * Overwrites the default input definition. * * @return InputDefinition An InputDefinition instance */ protected function getDefaultInputDefinition() { return new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.'))); } /** * Gets the default helper set with the helpers that should always be available. * * @return HelperSet A HelperSet instance */ protected function getDefaultHelperSet() { return new HelperSet(array(new FormatterHelper())); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Helper/0000755001161000116100000000000012165326424020370 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Helper/TableHelperTest.php0000644001161000116100000001517312155624475024145 0ustar arar * * 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\TableHelper; use Symfony\Component\Console\Output\StreamOutput; class TableHelperTest extends \PHPUnit_Framework_TestCase { protected $stream; protected function setUp() { $this->stream = fopen('php://memory', 'r+'); } protected function tearDown() { fclose($this->stream); $this->stream = null; } /** * @dataProvider testRenderProvider */ public function testRender($headers, $rows, $layout, $expected) { $table = new TableHelper(); $table ->setHeaders($headers) ->setRows($rows) ->setLayout($layout) ; $table->render($output = $this->getOutputStream()); $this->assertEquals($expected, $this->getOutputContent($output)); } /** * @dataProvider testRenderProvider */ public function testRenderAddRows($headers, $rows, $layout, $expected) { $table = new TableHelper(); $table ->setHeaders($headers) ->addRows($rows) ->setLayout($layout) ; $table->render($output = $this->getOutputStream()); $this->assertEquals($expected, $this->getOutputContent($output)); } /** * @dataProvider testRenderProvider */ public function testRenderAddRowsOneByOne($headers, $rows, $layout, $expected) { $table = new TableHelper(); $table ->setHeaders($headers) ->setLayout($layout) ; foreach ($rows as $row) { $table->addRow($row); } $table->render($output = $this->getOutputStream()); $this->assertEquals($expected, $this->getOutputContent($output)); } public function testRenderProvider() { return array( array( array('ISBN', 'Title', 'Author'), array( array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'), array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'), array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'), array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'), ), TableHelper::LAYOUT_DEFAULT, <<stream, StreamOutput::VERBOSITY_NORMAL, false); } protected function getOutputContent(StreamOutput $output) { rewind($output->getStream()); return str_replace(PHP_EOL, "\n", stream_get_contents($output->getStream())); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php0000644001161000116100000002052412155624475024311 0ustar arar * * 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 testSelect() { $dialog = new DialogHelper(); $helperSet = new HelperSet(array(new FormatterHelper())); $dialog->setHelperSet($helperSet); $heroes = array('Superman', 'Batman', 'Spiderman'); $dialog->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n")); $this->assertEquals('2', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, '2')); $this->assertEquals('1', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes)); $this->assertEquals('1', $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes)); $this->assertEquals('1', $dialog->select($output = $this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', false)); rewind($output->getStream()); $this->assertContains('Input "Fabien" is not a superhero!', stream_get_contents($output->getStream())); try { $this->assertEquals('1', $dialog->select($output = $this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, 1)); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertEquals('Value "Fabien" is invalid', $e->getMessage()); } $this->assertEquals(array('1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true)); $this->assertEquals(array('0', '2'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true)); $this->assertEquals(array('0', '2'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, null, false, 'Input "%s" is not a superhero!', true)); $this->assertEquals(array('0', '1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, '0,1', false, 'Input "%s" is not a superhero!', true)); $this->assertEquals(array('0', '1'), $dialog->select($this->getOutputStream(), 'What is your favorite superhero?', $heroes, ' 0 , 1 ', false, 'Input "%s" is not a superhero!', true)); } 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 testAskWithAutocomplete() { if (!$this->hasSttyAvailable()) { $this->markTestSkipped('`stty` is required to test autocomplete functionality'); } // Acm // AcsTest // // // Test // // S // F00oo $inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n"); $dialog = new DialogHelper(); $dialog->setInputStream($inputStream); $bundles = array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'); $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('AsseticBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('FrameworkBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('SecurityBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('FooBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('AsseticBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('FooBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); } public function testAskHiddenResponse() { if (defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('This test is not supported on Windows'); } $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("8AM\n")); $this->assertEquals('8AM', $dialog->askHiddenResponse($this->getOutputStream(), 'What time is it?')); } 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)); } private function hasSttyAvailable() { exec('stty 2>&1', $output, $exitcode); return $exitcode === 0; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php0000644001161000116100000001373612155624475024725 0ustar arar * * 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\ProgressHelper; use Symfony\Component\Console\Output\StreamOutput; class ProgressHelperTest extends \PHPUnit_Framework_TestCase { public function testAdvance() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream()); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 1 [->--------------------------]'), stream_get_contents($output->getStream())); } public function testAdvanceWithStep() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream()); $progress->advance(5); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream())); } public function testAdvanceMultipleTimes() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream()); $progress->advance(3); $progress->advance(2); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 3 [--->------------------------]').$this->generateOutput(' 5 [----->----------------------]'), stream_get_contents($output->getStream())); } public function testCustomizations() { $progress = new ProgressHelper(); $progress->setBarWidth(10); $progress->setBarCharacter('_'); $progress->setEmptyBarCharacter(' '); $progress->setProgressCharacter('/'); $progress->setFormat(' %current%/%max% [%bar%] %percent%%'); $progress->start($output = $this->getOutputStream(), 10); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 1/10 [_/ ] 10%'), stream_get_contents($output->getStream())); } public function testPercent() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(), 50); $progress->display(); $progress->advance(); $progress->advance(); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 0/50 [>---------------------------] 0%').$this->generateOutput(' 1/50 [>---------------------------] 2%').$this->generateOutput(' 2/50 [=>--------------------------] 4%'), stream_get_contents($output->getStream())); } public function testOverwriteWithShorterLine() { $progress = new ProgressHelper(); $progress->setFormat(' %current%/%max% [%bar%] %percent%%'); $progress->start($output = $this->getOutputStream(), 50); $progress->display(); $progress->advance(); // set shorter format $progress->setFormat(' %current%/%max% [%bar%]'); $progress->advance(); rewind($output->getStream()); $this->assertEquals( $this->generateOutput(' 0/50 [>---------------------------] 0%') . $this->generateOutput(' 1/50 [>---------------------------] 2%') . $this->generateOutput(' 2/50 [=>--------------------------] '), stream_get_contents($output->getStream()) ); } public function testSetCurrentProgress() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(), 50); $progress->display(); $progress->advance(); $progress->setCurrent(15); $progress->setCurrent(25); rewind($output->getStream()); $this->assertEquals( $this->generateOutput(' 0/50 [>---------------------------] 0%') . $this->generateOutput(' 1/50 [>---------------------------] 2%') . $this->generateOutput(' 15/50 [========>-------------------] 30%') . $this->generateOutput(' 25/50 [==============>-------------] 50%'), stream_get_contents($output->getStream()) ); } /** * @expectedException \LogicException * @expectedExceptionMessage You must start the progress bar */ public function testSetCurrentBeforeStarting() { $progress = new ProgressHelper(); $progress->setCurrent(15); } /** * @expectedException \LogicException * @expectedExceptionMessage You can't regress the progress bar */ public function testRegressProgress() { $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream(), 50); $progress->setCurrent(15); $progress->setCurrent(10); } public function testMultiByteSupport() { if (!function_exists('mb_strlen') || (false === $encoding = mb_detect_encoding('■'))) { $this->markTestSkipped('The mbstring extension is needed for multi-byte support'); } $progress = new ProgressHelper(); $progress->start($output = $this->getOutputStream()); $progress->setBarCharacter('■'); $progress->advance(3); rewind($output->getStream()); $this->assertEquals($this->generateOutput(' 3 [■■■>------------------------]'), stream_get_contents($output->getStream())); } protected function getOutputStream() { return new StreamOutput(fopen('php://memory', 'r+', false)); } protected $lastMessagesLength; protected function generateOutput($expected) { $expectedout = $expected; if ($this->lastMessagesLength !== null) { $expectedout = str_pad($expected, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT); } $this->lastMessagesLength = strlen($expectedout); return "\x0D".$expectedout; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Helper/HelperSetTest.php0000644001161000116100000001312612155624475023645 0ustar arar * * 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\HelperSet; use Symfony\Component\Console\Command\Command; class HelperSetTest extends \PHPUnit_Framework_TestCase { /** * @covers \Symfony\Component\Console\Helper\HelperSet::__construct */ public function testConstructor() { $mock_helper = $this->getGenericMockHelper('fake_helper'); $helperset = new HelperSet(array('fake_helper_alias' => $mock_helper)); $this->assertEquals($mock_helper, $helperset->get('fake_helper_alias'), '__construct sets given helper to helpers'); $this->assertTrue($helperset->has('fake_helper_alias'), '__construct sets helper alias for given helper'); } /** * @covers \Symfony\Component\Console\Helper\HelperSet::set */ public function testSet() { $helperset = new HelperSet(); $helperset->set($this->getGenericMockHelper('fake_helper', $helperset)); $this->assertTrue($helperset->has('fake_helper'), '->set() adds helper to helpers'); $helperset = new HelperSet(); $helperset->set($this->getGenericMockHelper('fake_helper_01', $helperset)); $helperset->set($this->getGenericMockHelper('fake_helper_02', $helperset)); $this->assertTrue($helperset->has('fake_helper_01'), '->set() will set multiple helpers on consecutive calls'); $this->assertTrue($helperset->has('fake_helper_02'), '->set() will set multiple helpers on consecutive calls'); $helperset = new HelperSet(); $helperset->set($this->getGenericMockHelper('fake_helper', $helperset), 'fake_helper_alias'); $this->assertTrue($helperset->has('fake_helper'), '->set() adds helper alias when set'); $this->assertTrue($helperset->has('fake_helper_alias'), '->set() adds helper alias when set'); } /** * @covers \Symfony\Component\Console\Helper\HelperSet::has */ public function testHas() { $helperset = new HelperSet(array('fake_helper_alias' => $this->getGenericMockHelper('fake_helper'))); $this->assertTrue($helperset->has('fake_helper'), '->has() finds set helper'); $this->assertTrue($helperset->has('fake_helper_alias'), '->has() finds set helper by alias'); } /** * @covers \Symfony\Component\Console\Helper\HelperSet::get */ public function testGet() { $helper_01 = $this->getGenericMockHelper('fake_helper_01'); $helper_02 = $this->getGenericMockHelper('fake_helper_02'); $helperset = new HelperSet(array('fake_helper_01_alias' => $helper_01, 'fake_helper_02_alias' => $helper_02)); $this->assertEquals($helper_01, $helperset->get('fake_helper_01'), '->get() returns correct helper by name'); $this->assertEquals($helper_01, $helperset->get('fake_helper_01_alias'), '->get() returns correct helper by alias'); $this->assertEquals($helper_02, $helperset->get('fake_helper_02'), '->get() returns correct helper by name'); $this->assertEquals($helper_02, $helperset->get('fake_helper_02_alias'), '->get() returns correct helper by alias'); $helperset = new HelperSet(); try { $helperset->get('foo'); $this->fail('->get() throws \InvalidArgumentException when helper not found'); } catch (\Exception $e) { $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws \InvalidArgumentException when helper not found'); $this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \InvalidArgumentException when helper not found'); } } /** * @covers \Symfony\Component\Console\Helper\HelperSet::setCommand */ public function testSetCommand() { $cmd_01 = new Command('foo'); $cmd_02 = new Command('bar'); $helperset = new HelperSet(); $helperset->setCommand($cmd_01); $this->assertEquals($cmd_01, $helperset->getCommand(), '->setCommand() stores given command'); $helperset = new HelperSet(); $helperset->setCommand($cmd_01); $helperset->setCommand($cmd_02); $this->assertEquals($cmd_02, $helperset->getCommand(), '->setCommand() overwrites stored command with consecutive calls'); } /** * @covers \Symfony\Component\Console\Helper\HelperSet::getCommand */ public function testGetCommand() { $cmd = new Command('foo'); $helperset = new HelperSet(); $helperset->setCommand($cmd); $this->assertEquals($cmd, $helperset->getCommand(), '->getCommand() retrieves stored command'); } /** * Create a generic mock for the helper interface. Optionally check for a call to setHelperSet with a specific * helperset instance. * * @param string $name * @param HelperSet $helperset allows a mock to verify a particular helperset set is being added to the Helper */ private function getGenericMockHelper($name, HelperSet $helperset = null) { $mock_helper = $this->getMock('\Symfony\Component\Console\Helper\HelperInterface'); $mock_helper->expects($this->any()) ->method('getName') ->will($this->returnValue($name)); if ($helperset) { $mock_helper->expects($this->any()) ->method('setHelperSet') ->with($this->equalTo($helperset)); } return $mock_helper; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php0000644001161000116100000000531712155624475025060 0ustar arar * * 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( '[cli] 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( ' Some text to display ', $formatter->formatBlock('Some text to display', 'error'), '::formatBlock() formats a message in a block' ); $this->assertEquals( ' Some text to display '."\n" . ' foo bar ', $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'), '::formatBlock() formats a message in a block' ); $this->assertEquals( ' '."\n" . ' Some text to display '."\n" . ' ', $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( ' '."\n" . ' Du texte à afficher '."\n" . ' ', $formatter->formatBlock('Du texte à afficher', 'error', true), '::formatBlock() formats a message in a block' ); } public function testFormatBlockLGEscaping() { $formatter = new FormatterHelper(); $this->assertEquals( ' '."\n" . ' \some info\ '."\n" . ' ', $formatter->formatBlock('some info', 'error', true), '::formatBlock() escapes \'<\' chars' ); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/0000755001161000116100000000000012165326424020250 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Input/InputOptionTest.php0000644001161000116100000002176712155624475024134 0ustar arar * * 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value. */ public function testArrayModeWithoutValue() { new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY); } public function testShortcut() { $option = new InputOption('foo', 'f'); $this->assertEquals('f', $option->getShortcut(), '__construct() can take a shortcut as its second argument'); $option = new InputOption('foo', '-f|-ff|fff'); $this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts'); $option = new InputOption('foo', array('f', 'ff', '-fff')); $this->assertEquals('f|ff|fff', $option->getShortcut(), '__construct() removes the leading - of the shortcuts'); $option = new InputOption('foo'); $this->assertNull($option->getShortcut(), '__construct() makes the shortcut null by default'); } public function testModes() { $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'); } /** * @dataProvider provideInvalidModes */ public function testInvalidModes($mode) { $this->setExpectedException('InvalidArgumentException', sprintf('Option mode "%s" is not valid.', $mode)); new InputOption('foo', 'f', $mode); } public function provideInvalidModes() { return array( array('ANOTHER_ONE'), array(-1) ); } /** * @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'); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot set a default value when using InputOption::VALUE_NONE mode. */ public function testDefaultValueWithValueNoneMode() { $option = new InputOption('foo', 'f', InputOption::VALUE_NONE); $option->setDefault('default'); } /** * @expectedException \LogicException * @expectedExceptionMessage A default value for an array option must be an array. */ public function testDefaultValueWithIsArrayMode() { $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY); $option->setDefault('default'); } 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)); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/StringInputTest.php0000644001161000116100000001123112155624475024113 0ustar arar * * 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\InputOption; 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 testInputOptionWithGivenString() { $definition = new InputDefinition( array(new InputOption('foo', null, InputOption::VALUE_REQUIRED)) ); // call to bind $input = new StringInput('--foo=bar'); $input->bind($definition); $this->assertEquals('bar', $input->getOption('foo')); // definition in constructor $input = new StringInput('--foo=bar', $definition); $this->assertEquals('bar', $input->getOption('foo')); } 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("'a\rb\nc\td'", array("a\rb\nc\td"), '->tokenize() parses whitespace chars in strings'), array("'a'\r'b'\n'c'\t'd'", array('a','b','c','d'), '->tokenize() parses whitespace chars between args as spaces'), 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'), ); } public function testToString() { $input = new StringInput('-f foo'); $this->assertEquals('-f foo', (string) $input); $input = new StringInput('-f --bar=foo "a b c d"'); $this->assertEquals('-f --bar=foo '.escapeshellarg('a b c d'), (string) $input); $input = new StringInput('-f --bar=foo \'a b c d\' '."'A\nB\\'C'"); $this->assertEquals('-f --bar=foo '.escapeshellarg('a b c d').' '.escapeshellarg("A\nB'C"), (string) $input); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/InputTest.php0000644001161000116100000001271012155624475022727 0ustar arar * * 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "foo" option does not exist. */ public function testSetInvalidOption() { $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')))); $input->setOption('foo', 'bar'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "foo" option does not exist. */ public function testGetInvalidOption() { $input = new ArrayInput(array('--name' => 'foo'), new InputDefinition(array(new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')))); $input->getOption('foo'); } 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "foo" argument does not exist. */ public function testSetInvalidArgument() { $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')))); $input->setArgument('foo', 'bar'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "foo" argument does not exist. */ public function testGetInvalidArgument() { $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')))); $input->getArgument('foo'); } /** * @expectedException \RuntimeException * @expectedExceptionMessage Not enough arguments. */ public function testValidateWithMissingArguments() { $input = new ArrayInput(array()); $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED)))); $input->validate(); } public function testValidate() { $input = new ArrayInput(array('name' => 'foo')); $input->bind(new InputDefinition(array(new InputArgument('name', InputArgument::REQUIRED)))); $this->assertNull($input->validate()); } public function testSetGetInteractive() { $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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/ArgvInputTest.php0000644001161000116100000003361612155624475023557 0ustar arar * * 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 testParseArguments() { $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'); } /** * @dataProvider provideOptions */ public function testParseOptions($input, $options, $expectedOptions, $message) { $input = new ArgvInput($input); $input->bind(new InputDefinition($options)); $this->assertEquals($expectedOptions, $input->getOptions(), $message); } public function provideOptions() { return array( array( array('cli.php', '--foo'), array(new InputOption('foo')), array('foo' => true), '->parse() parses long options without a value' ), array( array('cli.php', '--foo=bar'), array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)), array('foo' => 'bar'), '->parse() parses long options with a required value (with a = separator)' ), array( array('cli.php', '--foo', 'bar'), array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)), array('foo' => 'bar'), '->parse() parses long options with a required value (with a space separator)' ), array( array('cli.php', '-f'), array(new InputOption('foo', 'f')), array('foo' => true), '->parse() parses short options without a value' ), array( array('cli.php', '-fbar'), array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)), array('foo' => 'bar'), '->parse() parses short options with a required value (with no separator)' ), array( array('cli.php', '-f', 'bar'), array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED)), array('foo' => 'bar'), '->parse() parses short options with a required value (with a space separator)' ), array( array('cli.php', '-f', ''), array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)), array('foo' => ''), '->parse() parses short options with an optional empty value' ), array( array('cli.php', '-f', '', 'foo'), array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)), array('foo' => ''), '->parse() parses short options with an optional empty value followed by an argument' ), array( array('cli.php', '-f', '', '-b'), array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b')), array('foo' => '', 'bar' => true), '->parse() parses short options with an optional empty value followed by an option' ), array( array('cli.php', '-f', '-b', 'foo'), array(new InputArgument('name'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b')), array('foo' => null, 'bar' => true), '->parse() parses short options with an optional value which is not present' ), array( array('cli.php', '-fb'), array(new InputOption('foo', 'f'), new InputOption('bar', 'b')), array('foo' => true, 'bar' => true), '->parse() parses short options when they are aggregated as a single one' ), array( array('cli.php', '-fb', 'bar'), array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_REQUIRED)), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has a required value' ), array( array('cli.php', '-fb', 'bar'), array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value' ), array( array('cli.php', '-fbbar'), array(new InputOption('foo', 'f'), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)), array('foo' => true, 'bar' => 'bar'), '->parse() parses short options when they are aggregated as a single one and the last one has an optional value with no separator' ), array( array('cli.php', '-fbbar'), array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL)), array('foo' => 'bbar', 'bar' => null), '->parse() parses short options when they are aggregated as a single one and one of them takes a value' ) ); } /** * @dataProvider provideInvalidInput */ public function testInvalidInput($argv, $definition, $expectedExceptionMessage) { $this->setExpectedException('RuntimeException', $expectedExceptionMessage); $input = new ArgvInput($argv); $input->bind($definition); } public function provideInvalidInput() { return array( array( array('cli.php', '--foo'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))), 'The "--foo" option requires a value.' ), array( array('cli.php', '-f'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))), 'The "--foo" option requires a value.' ), array( array('cli.php', '-ffoo'), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))), 'The "-o" option does not exist.' ), array( array('cli.php', 'foo', 'bar'), new InputDefinition(), 'Too many arguments.' ), array( array('cli.php', '--foo'), new InputDefinition(), 'The "--foo" option does not exist.' ), array( array('cli.php', '-f'), new InputDefinition(), 'The "-f" option does not exist.' ), array( array('cli.php', '-1'), new InputDefinition(array(new InputArgument('number'))), 'The "-1" option does not exist.' ) ); } public function testParseArrayArgument() { $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'); } public function testParseArrayOption() { $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(), '->parse() parses array options ("--option=value" syntax)'); $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(), '->parse() parses array options ("--option value" syntax)'); $input = new ArgvInput(array('cli.php', '--name=foo', '--name=bar', '--name=')); $input->bind(new InputDefinition(array(new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)))); $this->assertSame(array('name' => array('foo', 'bar', null)), $input->getOptions(), '->parse() parses empty array options as null ("--option=value" syntax)'); $input = new ArgvInput(array('cli.php', '--name', 'foo', '--name', 'bar', '--name', '--anotherOption')); $input->bind(new InputDefinition(array( new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY), new InputOption('anotherOption', null, InputOption::VALUE_NONE), ))); $this->assertSame(array('name' => array('foo', 'bar', null), 'anotherOption' => true), $input->getOptions(), '->parse() parses empty array options as null ("--option value" syntax)'); } public function testParseNegativeNumberAfterDoubleDash() { $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'); } public function testParseEmptyStringArgument() { $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'); } public function testToString() { $input = new ArgvInput(array('cli.php', '-f', 'foo')); $this->assertEquals('-f foo', (string) $input); $input = new ArgvInput(array('cli.php', '-f', '--bar=foo', 'a b c d', "A\nB'C")); $this->assertEquals('-f --bar=foo '.escapeshellarg('a b c d').' '.escapeshellarg("A\nB'C"), (string) $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'), ); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/ArrayInputTest.php0000644001161000116100000001147412155624475023734 0ustar arar * * 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 testParseArguments() { $input = new ArrayInput(array('name' => 'foo'), new InputDefinition(array(new InputArgument('name')))); $this->assertEquals(array('name' => 'foo'), $input->getArguments(), '->parse() parses required arguments'); } /** * @dataProvider provideOptions */ public function testParseOptions($input, $options, $expectedOptions, $message) { $input = new ArrayInput($input, new InputDefinition($options)); $this->assertEquals($expectedOptions, $input->getOptions(), $message); } public function provideOptions() { return array( array( array('--foo' => 'bar'), array(new InputOption('foo')), array('foo' => 'bar'), '->parse() parses long options' ), array( array('--foo' => 'bar'), array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default')), array('foo' => 'bar'), '->parse() parses long options with a default value' ), array( array('--foo' => null), array(new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL, '', 'default')), array('foo' => 'default'), '->parse() parses long options with a default value' ), array( array('-f' => 'bar'), array(new InputOption('foo', 'f')), array('foo' => 'bar'), '->parse() parses short options' ) ); } /** * @dataProvider provideInvalidInput */ public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage) { $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); new ArrayInput($parameters, $definition); } public function provideInvalidInput() { return array( array( array('foo' => 'foo'), new InputDefinition(array(new InputArgument('name'))), 'The "foo" argument does not exist.' ), array( array('--foo' => null), new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_REQUIRED))), 'The "--foo" option requires a value.' ), array( array('--foo' => 'foo'), new InputDefinition(), 'The "--foo" option does not exist.' ), array( array('-o' => 'foo'), new InputDefinition(), 'The "-o" option does not exist.' ) ); } public function testToString() { $input = new ArrayInput(array('-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C")); $this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php0000644001161000116100000004424012155624475024743 0ustar arar * * 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 testConstructorArguments() { $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'); } public function testConstructorOptions() { $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'); } /** * @expectedException \LogicException * @expectedExceptionMessage An argument with name "foo" already exists. */ public function testArgumentsMustHaveDifferentNames() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArgument($this->foo); $definition->addArgument($this->foo1); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot add an argument after an array argument. */ public function testArrayArgumentHasToBeLast() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArgument(new InputArgument('fooarray', InputArgument::IS_ARRAY)); $definition->addArgument(new InputArgument('anotherbar')); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot add a required argument after an optional one. */ public function testRequiredArgumentCannotFollowAnOptionalOne() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArgument($this->foo); $definition->addArgument($this->foo2); } 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "bar" argument does not exist. */ public function testGetInvalidArgument() { $this->initializeArguments(); $definition = new InputDefinition(); $definition->addArguments(array($this->foo)); $definition->getArgument('bar'); } 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "-f" option does not exist. */ public function testSetOptionsClearsOptions() { $this->initializeOptions(); $definition = new InputDefinition(array($this->foo)); $definition->setOptions(array($this->bar)); $definition->getOptionForShortcut('f'); } 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'); } /** * @expectedException \LogicException * @expectedExceptionMessage An option named "foo" already exists. */ public function testAddDuplicateOption() { $this->initializeOptions(); $definition = new InputDefinition(); $definition->addOption($this->foo); $definition->addOption($this->foo2); } /** * @expectedException \LogicException * @expectedExceptionMessage An option with shortcut "f" already exists. */ public function testAddDuplicateShortcutOption() { $this->initializeOptions(); $definition = new InputDefinition(); $definition->addOption($this->foo); $definition->addOption($this->foo1); } 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'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "--bar" option does not exist. */ public function testGetInvalidOption() { $this->initializeOptions(); $definition = new InputDefinition(array($this->foo)); $definition->getOption('bar'); } 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'); } public function testGetOptionForMultiShortcut() { $this->initializeOptions(); $definition = new InputDefinition(array($this->multi)); $this->assertEquals($this->multi, $definition->getOptionForShortcut('m'), '->getOptionForShortcut() returns a InputOption by its shortcut'); $this->assertEquals($this->multi, $definition->getOptionForShortcut('mmm'), '->getOptionForShortcut() returns a InputOption by its shortcut'); } /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The "-l" option does not exist. */ public function testGetOptionForInvalidShortcut() { $this->initializeOptions(); $definition = new InputDefinition(array($this->foo)); $definition->getOptionForShortcut('l'); } 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('http://foo.com/')), 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('http://foo.com/', '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'); $this->multi = new InputOption('multi', 'm|mm|mmm'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Input/InputArgumentTest.php0000644001161000116100000001026712155624475024437 0ustar arar * * 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'); } public function testModes() { $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'); } /** * @dataProvider provideInvalidModes */ public function testInvalidModes($mode) { $this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode)); new InputArgument('foo', $mode); } public function provideInvalidModes() { return array( array('ANOTHER_ONE'), array(-1) ); } 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'); } /** * @expectedException \LogicException * @expectedExceptionMessage Cannot set a default value except for InputArgument::OPTIONAL mode. */ public function testSetDefaultWithRequiredArgument() { $argument = new InputArgument('foo', InputArgument::REQUIRED); $argument->setDefault('default'); } /** * @expectedException \LogicException * @expectedExceptionMessage A default value for an array argument must be an array. */ public function testSetDefaultWithArrayArgument() { $argument = new InputArgument('foo', InputArgument::IS_ARRAY); $argument->setDefault('default'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/0000755001161000116100000000000012165326424020762 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_4.json0000644001161000116100000000023212155624475024632 0ustar arar{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":true,"description":"option description","default":[]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_renderexception2.txt0000644001161000116100000000032412155624475027373 0ustar arar [InvalidArgumentException] The "--foo" option does not exist. list [--xml] [--raw] [--format="..."] [namespace] ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_3.xml0000644001161000116100000000040112155624475025276 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php0000644001161000116100000000111512155624475026063 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Fixtures; use Symfony\Component\Console\Application; class DescriptorApplication2 extends Application { public function __construct() { parent::__construct('My Symfony application', 'v1.0'); $this->add(new DescriptorCommand1()); $this->add(new DescriptorCommand2()); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt0000644001161000116100000000165412155624475025513 0ustar ararConsole Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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: afoobar The foo:bar command help Displays help for a command list Lists commands foo foo:bar The foo:bar command./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_2.xml0000644001161000116100000000026012155624475024772 0ustar arar argument description ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication1.php0000644001161000116100000000060412155624475026064 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Fixtures; use Symfony\Component\Console\Application; class DescriptorApplication1 extends Application { } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_2.xml0000644001161000116100000000036112155624475025302 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_2.md0000644001161000116100000000074512155624475023157 0ustar arardescriptor:command2 ------------------- * Description: command 2 description * Usage: `descriptor:command2 [-o|--option_name] argument_name` * Aliases: command 2 help ### Arguments: **argument_name:** * Name: argument_name * Is required: yes * Is array: no * Description: * Default: `NULL` ### Options: **option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: no * Is value required: no * Is multiple: no * Description: * Default: `false` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt0000644001161000116100000001367112155624475025331 0ustar arar help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: <info>php app/console help list</info> You can also output the help in other formats by using the <comment>--format</comment> option: <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. The command name help list [--xml] [--raw] [--format="..."] [namespace] Lists commands 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 in other formats by using the <comment>--format</comment> option: <info>php app/console list --format=xml</info> It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> The namespace name foo:bar The foo:bar command afoobar afoobar help list foo:bar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_3.md0000644001161000116100000000021412155624475024572 0ustar arar**argument_name:** * Name: argument_name * Is required: no * Is array: no * Description: argument description * Default: `'default_value'` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_3.md0000644001161000116100000000025612155624475024266 0ustar arar**option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: yes * Is value required: yes * Is multiple: no * Description: option description * Default: `NULL` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_4.json0000644001161000116100000000044412155624475025457 0ustar arar{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_run2.txt0000644001161000116100000000203412155624475025001 0ustar ararUsage: help [--xml] [--format="..."] [--raw] [command_name] Arguments: command The command to execute command_name The command name (default: "help") Options: --xml To output help as XML --format To output help in other formats --raw To output raw command help --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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 in other formats by using the --format option: php app/console help --format=xml list To display the list of available commands, please use the list command. ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php0000644001161000116100000000147712155624475025211 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Fixtures; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; class DescriptorCommand2 extends Command { protected function configure() { $this ->setName('descriptor:command2') ->setDescription('command 2 description') ->setHelp('command 2 help') ->addArgument('argument_name', InputArgument::REQUIRED) ->addOption('option_name', 'o', InputOption::VALUE_NONE) ; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_gethelp.txt0000644001161000116100000000126612155624475025551 0ustar ararConsole Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question../Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_4.xml0000644001161000116100000000032212155624475024461 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_run4.txt0000644001161000116100000000001512155624475025000 0ustar ararConsole Tool ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt0000644001161000116100000000144312155624475025510 0ustar ararConsole Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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 for the "foo" namespace: foo:bar The foo:bar command./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_1.xml0000644001161000116100000000026212155624475024461 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_2.txt0000644001161000116100000000014212155624475024476 0ustar arar --option_name (-o) option description (default: "default_value") ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_2.txt0000644001161000116100000000221012155624475024250 0ustar ararMy Symfony application version v1.0 Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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: alias1 command 1 description alias2 command 1 description help Displays help for a command list Lists commands descriptor descriptor:command1 command 1 description descriptor:command2 command 2 description ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_2.json0000644001161000116100000000025012155624475024630 0ustar arar{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":false,"is_multiple":false,"description":"option description","default":"default_value"} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_3.txt0000644001161000116100000000013712155624475025015 0ustar arar argument_name argument description (default: "default_value") ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_3.txt0000644001161000116100000000007512155624475025324 0ustar ararOptions: --option_name (-o) ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_2.json0000644001161000116100000000015712155624475025150 0ustar arar{"name":"argument_name","is_required":false,"is_array":true,"description":"argument description","default":[]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_renderexception3.txt0000644001161000116100000000026712155624475027402 0ustar arar [Exception] Second exception [Exception] First exception foo3:bar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_2.json0000644001161000116100000001575712155624475024426 0ustar arar{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":null}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_2.json0000644001161000116100000000021212155624475025446 0ustar arar{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":[]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_2.md0000644001161000116100000000027012155624475024261 0ustar arar**option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: yes * Is value required: no * Is multiple: no * Description: option description * Default: `'default_value'` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_3.md0000644001161000116100000000025712155624475025107 0ustar arar### Options: **option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: no * Is value required: no * Is multiple: no * Description: * Default: `false` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_2.md0000644001161000116100000000020612155624475024572 0ustar arar**argument_name:** * Name: argument_name * Is required: no * Is array: yes * Description: argument description * Default: `array ()` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_run3.txt0000644001161000116100000000120012155624475024774 0ustar ararUsage: list [--xml] [--raw] [--format="..."] [namespace] Arguments: namespace The namespace name Options: --xml To output list as XML --raw To output raw command list --format To output list in other formats 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 in other formats by using the --format option: php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): php app/console list --raw ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_asxml.txt0000644001161000116100000000333012155624475024352 0ustar arar namespace:name description help name The command to execute ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_1.txt0000644001161000116100000000003412155624475025007 0ustar arar argument_name ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_astext.txt0000644001161000116100000000136312155624475024542 0ustar ararUsage: namespace:name Aliases: name Arguments: command The command to execute Options: --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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: help ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_1.json0000644001161000116100000000021512155624475024630 0ustar arar{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php0000644001161000116100000000075512155624475023614 0ustar ararsetName('foo1:bar') ->setDescription('The foo1:bar command') ->setAliases(array('afoobar2')) ; } protected function execute(InputInterface $input, OutputInterface $output) { } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_2.xml0000644001161000116100000000040412155624475024460 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_1.txt0000644001161000116100000000004112155624475024473 0ustar arar --option_name (-o) ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php0000644001161000116100000000112512155624475023603 0ustar ararsetName('foo:bar1') ->setDescription('The foo:bar1 command') ->setAliases(array('afoobar1')) ; } protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_1.xml0000644001161000116100000000013612155624475025301 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_2.txt0000644001161000116100000000007312155624475025321 0ustar ararArguments: argument_name ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_1.txt0000644001161000116100000000000012155624475025306 0ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_4.txt0000644001161000116100000000017612155624475025327 0ustar ararArguments: argument_name Options: --option_name (-o) ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_1.json0000644001161000116100000000013512155624475025143 0ustar arar{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_1.xml0000644001161000116100000000023412155624475024772 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_1.json0000644001161000116100000000003612155624475025451 0ustar arar{"arguments":[],"options":[]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_1.md0000644001161000116100000000024112155624475024256 0ustar arar**option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: no * Is value required: no * Is multiple: no * Description: * Default: `false` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_3.xml0000644001161000116100000000032212155624475024460 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/TestCommand.php0000644001161000116100000000127212155624475023721 0ustar ararsetName('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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_1.md0000644001161000116100000000723412155624475024043 0ustar ararUNKNOWN ======= * help * list help ---- * Description: Displays help for a command * Usage: `help [--xml] [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: php app/console help list You can also output the help in other formats by using the --format option: php app/console help --format=xml list To display the list of available commands, please use the list command. ### Arguments: **command_name:** * Name: command_name * Is required: no * Is array: no * Description: The command name * Default: `'help'` ### Options: **xml:** * Name: `--xml` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output help as XML * Default: `false` **format:** * Name: `--format` * Shortcut: * Accept value: yes * Is value required: yes * Is multiple: no * Description: To output help in other formats * Default: `NULL` **raw:** * Name: `--raw` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output raw command help * Default: `false` **help:** * Name: `--help` * Shortcut: `-h` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this help message. * Default: `false` **quiet:** * Name: `--quiet` * Shortcut: `-q` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not output any message. * Default: `false` **verbose:** * Name: `--verbose` * Shortcut: `-v|-vv|-vvv` * Accept value: no * Is value required: no * Is multiple: no * Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug * Default: `false` **version:** * Name: `--version` * Shortcut: `-V` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this application version. * Default: `false` **ansi:** * Name: `--ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Force ANSI output. * Default: `false` **no-ansi:** * Name: `--no-ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Disable ANSI output. * Default: `false` **no-interaction:** * Name: `--no-interaction` * Shortcut: `-n` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not ask any interactive question. * Default: `false` list ---- * Description: Lists commands * Usage: `list [--xml] [--raw] [--format="..."] [namespace]` * Aliases: 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 in other formats by using the --format option: php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): php app/console list --raw ### Arguments: **namespace:** * Name: namespace * Is required: no * Is array: no * Description: The namespace name * Default: `NULL` ### Options: **xml:** * Name: `--xml` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output list as XML * Default: `false` **raw:** * Name: `--raw` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output raw command list * Default: `false` **format:** * Name: `--format` * Shortcut: * Accept value: yes * Is value required: yes * Is multiple: no * Description: To output list in other formats * Default: `NULL` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_1.md0000644001161000116100000000016412155624475024574 0ustar arar**argument_name:** * Name: argument_name * Is required: yes * Is array: no * Description: * Default: `NULL` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_3.json0000644001161000116100000000017512155624475025151 0ustar arar{"name":"argument_name","is_required":false,"is_array":false,"description":"argument description","default":"default_value"} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_1.xml0000644001161000116100000001106412155624475024237 0ustar arar help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: <info>php app/console help list</info> You can also output the help in other formats by using the <comment>--format</comment> option: <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. The command name help list [--xml] [--raw] [--format="..."] [namespace] Lists commands 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 in other formats by using the <comment>--format</comment> option: <info>php app/console list --format=xml</info> It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> The namespace name help list ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_2.md0000644001161000116100000000020412155624475025076 0ustar arar### Arguments: **argument_name:** * Name: argument_name * Is required: yes * Is array: no * Description: * Default: `NULL` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_2.xml0000644001161000116100000000114612155624475023353 0ustar arar descriptor:command2 [-o|--option_name] argument_name command 2 description command 2 help ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php0000644001161000116100000000115512155624475023610 0ustar ararsetName('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); } } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_1.json0000644001161000116100000000030412155624475023516 0ustar arar{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":[]}} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_3.xml0000644001161000116100000000034212155624475024774 0ustar arar argument description default_value ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand1.php0000644001161000116100000000120612155624475025176 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Tests\Fixtures; use Symfony\Component\Console\Command\Command; class DescriptorCommand1 extends Command { protected function configure() { $this ->setName('descriptor:command1') ->setAliases(array('alias1', 'alias2')) ->setDescription('command 1 description') ->setHelp('command 1 help') ; } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_4.md0000644001161000116100000000026212155624475024264 0ustar arar**option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: yes * Is value required: no * Is multiple: yes * Description: option description * Default: `array ()` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_4.txt0000644001161000116100000000014112155624475024477 0ustar arar --option_name (-o) option description (multiple values allowed) ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/definition_asxml.txt0000644001161000116100000000234712155624475025073 0ustar arar The foo argument The baz argument true The bar argument bar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_4.md0000644001161000116100000000046412155624475025110 0ustar arar### Arguments: **argument_name:** * Name: argument_name * Is required: yes * Is array: no * Description: * Default: `NULL` ### Options: **option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: no * Is value required: no * Is multiple: no * Description: * Default: `false` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_2.json0000644001161000116100000000073212155624475023524 0ustar arar{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}}} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_4.xml0000644001161000116100000000062412155624475025306 0ustar arar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_argument_2.txt0000644001161000116100000000006112155624475025010 0ustar arar argument_name argument description ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_3.json0000644001161000116100000000023412155624475024633 0ustar arar{"name":"--option_name","shortcut":"-o","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"option description","default":null} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/FooCommand.php0000644001161000116100000000140012155624475023516 0ustar ararsetName('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'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/definition_astext.txt0000644001161000116100000000133512155624475025253 0ustar ararArguments: foo The foo argument baz The baz argument (default: true) bar The bar argument (default: ["http://foo.com/"]) Options: --foo (-f) The foo option --baz The baz option (default: false) --bar (-b) The bar option (default: "bar") --qux The qux option (default: ["http://foo.com/","bar"]) (multiple values allowed) --qux2 The qux2 option (default: {"foo":"bar"}) (multiple values allowed) ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_run1.txt0000644001161000116100000000107212155624475025001 0ustar ararConsole Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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 ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_option_3.txt0000644001161000116100000000006412155624475024502 0ustar arar --option_name (-o) option description ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_1.md0000644001161000116100000000023312155624475023146 0ustar arardescriptor:command1 ------------------- * Description: command 1 description * Usage: `descriptor:command1` * Aliases: `alias1`, `alias2` command 1 help ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_1.txt0000644001161000116100000000146612155624475024263 0ustar ararConsole Tool Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --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 ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_renderexception1.txt0000644001161000116100000000021412155624475027370 0ustar arar [InvalidArgumentException] Command "foo" is not defined. ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_1.md0000644001161000116100000000000012155624475025067 0ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_2.xml0000644001161000116100000002070012155624475024235 0ustar arar help [--xml] [--format="..."] [--raw] [command_name] Displays help for a command The <info>help</info> command displays help for a given command: <info>php app/console help list</info> You can also output the help in other formats by using the <comment>--format</comment> option: <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. The command name help list [--xml] [--raw] [--format="..."] [namespace] Lists commands 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 in other formats by using the <comment>--format</comment> option: <info>php app/console list --format=xml</info> It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> The namespace name descriptor:command1 command 1 description command 1 help alias1 alias2 descriptor:command2 [-o|--option_name] argument_name command 2 description command 2 help alias1 alias2 help list descriptor:command1 descriptor:command2 ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_1.xml0000644001161000116100000000051712155624475023353 0ustar arar descriptor:command1 command 1 description command 1 help alias1 alias2 ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_1.json0000644001161000116100000000734112155624475024413 0ustar arar{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":null},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message.","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message.","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version.","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output.","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output.","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question.","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":null}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_1.txt0000644001161000116100000000022212155624475023363 0ustar ararUsage: descriptor:command1 Aliases: alias1, alias2 Help: command 1 help ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_renderexception4.txt0000644001161000116100000000024412155624475027376 0ustar arar [InvalidArgumentException] Command "foo" is not define d. ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_2.md0000644001161000116100000001571212155624475024044 0ustar ararMy Symfony application ====================== * alias1 * alias2 * help * list **descriptor:** * descriptor:command1 * descriptor:command2 help ---- * Description: Displays help for a command * Usage: `help [--xml] [--format="..."] [--raw] [command_name]` * Aliases: The help command displays help for a given command: php app/console help list You can also output the help in other formats by using the --format option: php app/console help --format=xml list To display the list of available commands, please use the list command. ### Arguments: **command_name:** * Name: command_name * Is required: no * Is array: no * Description: The command name * Default: `'help'` ### Options: **xml:** * Name: `--xml` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output help as XML * Default: `false` **format:** * Name: `--format` * Shortcut: * Accept value: yes * Is value required: yes * Is multiple: no * Description: To output help in other formats * Default: `NULL` **raw:** * Name: `--raw` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output raw command help * Default: `false` **help:** * Name: `--help` * Shortcut: `-h` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this help message. * Default: `false` **quiet:** * Name: `--quiet` * Shortcut: `-q` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not output any message. * Default: `false` **verbose:** * Name: `--verbose` * Shortcut: `-v|-vv|-vvv` * Accept value: no * Is value required: no * Is multiple: no * Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug * Default: `false` **version:** * Name: `--version` * Shortcut: `-V` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this application version. * Default: `false` **ansi:** * Name: `--ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Force ANSI output. * Default: `false` **no-ansi:** * Name: `--no-ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Disable ANSI output. * Default: `false` **no-interaction:** * Name: `--no-interaction` * Shortcut: `-n` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not ask any interactive question. * Default: `false` list ---- * Description: Lists commands * Usage: `list [--xml] [--raw] [--format="..."] [namespace]` * Aliases: 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 in other formats by using the --format option: php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): php app/console list --raw ### Arguments: **namespace:** * Name: namespace * Is required: no * Is array: no * Description: The namespace name * Default: `NULL` ### Options: **xml:** * Name: `--xml` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output list as XML * Default: `false` **raw:** * Name: `--raw` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: To output raw command list * Default: `false` **format:** * Name: `--format` * Shortcut: * Accept value: yes * Is value required: yes * Is multiple: no * Description: To output list in other formats * Default: `NULL` descriptor:command1 ------------------- * Description: command 1 description * Usage: `descriptor:command1` * Aliases: `alias1`, `alias2` command 1 help ### Options: **help:** * Name: `--help` * Shortcut: `-h` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this help message. * Default: `false` **quiet:** * Name: `--quiet` * Shortcut: `-q` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not output any message. * Default: `false` **verbose:** * Name: `--verbose` * Shortcut: `-v|-vv|-vvv` * Accept value: no * Is value required: no * Is multiple: no * Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug * Default: `false` **version:** * Name: `--version` * Shortcut: `-V` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this application version. * Default: `false` **ansi:** * Name: `--ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Force ANSI output. * Default: `false` **no-ansi:** * Name: `--no-ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Disable ANSI output. * Default: `false` **no-interaction:** * Name: `--no-interaction` * Shortcut: `-n` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not ask any interactive question. * Default: `false` descriptor:command2 ------------------- * Description: command 2 description * Usage: `descriptor:command2 [-o|--option_name] argument_name` * Aliases: command 2 help ### Arguments: **argument_name:** * Name: argument_name * Is required: yes * Is array: no * Description: * Default: `NULL` ### Options: **option_name:** * Name: `--option_name` * Shortcut: `-o` * Accept value: no * Is value required: no * Is multiple: no * Description: * Default: `false` **help:** * Name: `--help` * Shortcut: `-h` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this help message. * Default: `false` **quiet:** * Name: `--quiet` * Shortcut: `-q` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not output any message. * Default: `false` **verbose:** * Name: `--verbose` * Shortcut: `-v|-vv|-vvv` * Accept value: no * Is value required: no * Is multiple: no * Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug * Default: `false` **version:** * Name: `--version` * Shortcut: `-V` * Accept value: no * Is value required: no * Is multiple: no * Description: Display this application version. * Default: `false` **ansi:** * Name: `--ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Force ANSI output. * Default: `false` **no-ansi:** * Name: `--no-ansi` * Shortcut: * Accept value: no * Is value required: no * Is multiple: no * Description: Disable ANSI output. * Default: `false` **no-interaction:** * Name: `--no-interaction` * Shortcut: `-n` * Accept value: no * Is value required: no * Is multiple: no * Description: Do not ask any interactive question. * Default: `false` ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/input_definition_3.json0000644001161000116100000000027012155624475025453 0ustar arar{"arguments":[],"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false}}} ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/Foo4Command.php0000644001161000116100000000026412155624475023611 0ustar ararsetName('foo3:bar:toh'); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/application_asxml2.txt0000644001161000116100000000322312155624475025322 0ustar arar foo:bar The foo:bar command afoobar ./Console-2.3.1/Symfony/Component/Console/Tests/Fixtures/command_2.txt0000644001161000116100000000037212155624475023372 0ustar ararUsage: descriptor:command2 [-o|--option_name] argument_name Arguments: argument_name Options: --option_name (-o) Help: command 2 help ./Console-2.3.1/Symfony/Component/Console/Tests/Formatter/0000755001161000116100000000000012165326424021114 5ustar arar./Console-2.3.1/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php0000644001161000116100000001526512155624475025670 0ustar arar * * 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("fooformat('foo\\assertEquals("some info", $formatter->format('\\some info\\')); $this->assertEquals("\\some info\\", OutputFormatter::escape('some info')); $this->assertEquals( "\033[33mSymfony\\Component\\Console does work very well!\033[0m", $formatter->format('Symfony\Component\Console does work very well!') ); } 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('some error') ); $this->assertEquals( "\033[32msome info\033[0m", $formatter->format('some info') ); $this->assertEquals( "\033[33msome comment\033[0m", $formatter->format('some comment') ); $this->assertEquals( "\033[30;46msome question\033[0m", $formatter->format('some 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('some some info error') ); } public function testStyleMatchingNotGreedy() { $formatter = new OutputFormatter(true); $this->assertEquals( "(\033[32m>=2.0,<2.3\033[0m)", $formatter->format('(>=2.0,<2.3)') ); } public function testStyleEscaping() { $formatter = new OutputFormatter(true); $this->assertEquals( "(\033[32mz>=2.0,format('('.$formatter->escape('z>=2.0,)') ); } 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('errorinfocommenterror') ); } 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('some custom msg')); } 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('some custom msg')); } public function testInlineStyle() { $formatter = new OutputFormatter(true); $this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('some text')); $this->assertEquals("\033[34;41msome text\033[0m", $formatter->format('some text')); } public function testNonStyleTag() { $formatter = new OutputFormatter(true); $this->assertEquals("\033[32msome \033[0m\033[32m styled\033[0m", $formatter->format('some styled')); } 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('some error') ); $this->assertEquals( "some info", $formatter->format('some info') ); $this->assertEquals( "some comment", $formatter->format('some comment') ); $this->assertEquals( "some question", $formatter->format('some question') ); $formatter->setDecorated(true); $this->assertEquals( "\033[37;41msome error\033[0m", $formatter->format('some error') ); $this->assertEquals( "\033[32msome info\033[0m", $formatter->format('some info') ); $this->assertEquals( "\033[33msome comment\033[0m", $formatter->format('some comment') ); $this->assertEquals( "\033[30;46msome question\033[0m", $formatter->format('some question') ); } public function testContentWithLineBreaks() { $formatter = new OutputFormatter(true); $this->assertEquals(<<format(<< some text EOF )); $this->assertEquals(<<format(<<some text EOF )); $this->assertEquals(<<format(<< some text EOF )); $this->assertEquals(<<format(<< some text more text EOF )); } } ./Console-2.3.1/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleTest.php0000644001161000116100000000716712155624475026713 0ustar arar * * 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')); try { $style->setOption('foo'); $this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } try { $style->unsetOption('foo'); $this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { $this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } } } ./Console-2.3.1/Symfony/Component/Console/Tests/Formatter/OutputFormatterStyleStackTest.php0000644001161000116100000000416612155624475027675 0ustar arar * * 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')); } } ./Console-2.3.1/Symfony/Component/Console/Helper/0000755001161000116100000000000012165326424017266 5ustar arar./Console-2.3.1/Symfony/Component/Console/Helper/HelperSet.php0000644001161000116100000000456612155624475021713 0ustar arar * * 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 */ 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; } } ./Console-2.3.1/Symfony/Component/Console/Helper/HelperInterface.php0000644001161000116100000000176312155624475023054 0ustar arar * * 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 * * @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(); } ./Console-2.3.1/Symfony/Component/Console/Helper/Helper.php0000644001161000116100000000265312155624475021232 0ustar arar * * 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 */ 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; } /** * 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 */ protected 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); } } ./Console-2.3.1/Symfony/Component/Console/Helper/ProgressHelper.php0000644001161000116100000002664412155624475022765 0ustar arar * * 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 Progress class provides helpers to display progress output. * * @author Chris Jones * @author Fabien Potencier */ class ProgressHelper extends Helper { const FORMAT_QUIET = ' %percent%%'; const FORMAT_NORMAL = ' %current%/%max% [%bar%] %percent%%'; const FORMAT_VERBOSE = ' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed%'; const FORMAT_QUIET_NOMAX = ' %current%'; const FORMAT_NORMAL_NOMAX = ' %current% [%bar%]'; const FORMAT_VERBOSE_NOMAX = ' %current% [%bar%] Elapsed: %elapsed%'; // options private $barWidth = 28; private $barChar = '='; private $emptyBarChar = '-'; private $progressChar = '>'; private $format = null; private $redrawFreq = 1; private $lastMessagesLength; private $barCharOriginal; /** * @var OutputInterface */ private $output; /** * Current step * * @var integer */ private $current; /** * Maximum number of steps * * @var integer */ private $max; /** * Start time of the progress bar * * @var integer */ private $startTime; /** * List of formatting variables * * @var array */ private $defaultFormatVars = array( 'current', 'max', 'bar', 'percent', 'elapsed', ); /** * Available formatting variables * * @var array */ private $formatVars; /** * Stored format part widths (used for padding) * * @var array */ private $widths = array( 'current' => 4, 'max' => 4, 'percent' => 3, 'elapsed' => 6, ); /** * Various time formats * * @var array */ private $timeFormats = array( array(0, '???'), array(2, '1 sec'), array(59, 'secs', 1), array(60, '1 min'), array(3600, 'mins', 60), array(5400, '1 hr'), array(86400, 'hrs', 3600), array(129600, '1 day'), array(604800, 'days', 86400), ); /** * Sets the progress bar width. * * @param int $size The progress bar size */ public function setBarWidth($size) { $this->barWidth = (int) $size; } /** * Sets the bar character. * * @param string $char A character */ public function setBarCharacter($char) { $this->barChar = $char; } /** * Sets the empty bar character. * * @param string $char A character */ public function setEmptyBarCharacter($char) { $this->emptyBarChar = $char; } /** * Sets the progress bar character. * * @param string $char A character */ public function setProgressCharacter($char) { $this->progressChar = $char; } /** * Sets the progress bar format. * * @param string $format The format */ public function setFormat($format) { $this->format = $format; } /** * Sets the redraw frequency. * * @param int $freq The frequency in seconds */ public function setRedrawFrequency($freq) { $this->redrawFreq = (int) $freq; } /** * Starts the progress output. * * @param OutputInterface $output An Output instance * @param integer $max Maximum steps */ public function start(OutputInterface $output, $max = null) { $this->startTime = time(); $this->current = 0; $this->max = (int) $max; $this->output = $output; if (null === $this->format) { switch ($output->getVerbosity()) { case OutputInterface::VERBOSITY_QUIET: $this->format = self::FORMAT_QUIET_NOMAX; if ($this->max > 0) { $this->format = self::FORMAT_QUIET; } break; case OutputInterface::VERBOSITY_VERBOSE: case OutputInterface::VERBOSITY_VERY_VERBOSE: case OutputInterface::VERBOSITY_DEBUG: $this->format = self::FORMAT_VERBOSE_NOMAX; if ($this->max > 0) { $this->format = self::FORMAT_VERBOSE; } break; default: $this->format = self::FORMAT_NORMAL_NOMAX; if ($this->max > 0) { $this->format = self::FORMAT_NORMAL; } break; } } $this->initialize(); } /** * Advances the progress output X steps. * * @param integer $step Number of steps to advance * @param Boolean $redraw Whether to redraw or not * * @throws \LogicException */ public function advance($step = 1, $redraw = false) { if (null === $this->startTime) { throw new \LogicException('You must start the progress bar before calling advance().'); } if (0 === $this->current) { $redraw = true; } $this->current += $step; if ($redraw || 0 === $this->current % $this->redrawFreq) { $this->display(); } } /** * Sets the current progress. * * @param integer $current The current progress * @param Boolean $redraw Whether to redraw or not * * @throws \LogicException */ public function setCurrent($current, $redraw = false) { if (null === $this->startTime) { throw new \LogicException('You must start the progress bar before calling setCurrent().'); } $current = (int) $current; if ($current < $this->current) { throw new \LogicException('You can\'t regress the progress bar'); } if (0 === $this->current) { $redraw = true; } $this->current = $current; if ($redraw || 0 === $this->current % $this->redrawFreq) { $this->display(); } } /** * Outputs the current progress string. * * @param Boolean $finish Forces the end result * * @throws \LogicException */ public function display($finish = false) { if (null === $this->startTime) { throw new \LogicException('You must start the progress bar before calling display().'); } $message = $this->format; foreach ($this->generate($finish) as $name => $value) { $message = str_replace("%{$name}%", $value, $message); } $this->overwrite($this->output, $message); } /** * Finishes the progress output. */ public function finish() { if (null === $this->startTime) { throw new \LogicException('You must start the progress bar before calling finish().'); } if (null !== $this->startTime) { if (!$this->max) { $this->barChar = $this->barCharOriginal; $this->display(true); } $this->startTime = null; $this->output->writeln(''); $this->output = null; } } /** * Initializes the progress helper. */ private function initialize() { $this->formatVars = array(); foreach ($this->defaultFormatVars as $var) { if (false !== strpos($this->format, "%{$var}%")) { $this->formatVars[$var] = true; } } if ($this->max > 0) { $this->widths['max'] = $this->strlen($this->max); $this->widths['current'] = $this->widths['max']; } else { $this->barCharOriginal = $this->barChar; $this->barChar = $this->emptyBarChar; } } /** * Generates the array map of format variables to values. * * @param Boolean $finish Forces the end result * * @return array Array of format vars and values */ private function generate($finish = false) { $vars = array(); $percent = 0; if ($this->max > 0) { $percent = (double) round($this->current / $this->max, 2); } if (isset($this->formatVars['bar'])) { $completeBars = 0; $emptyBars = 0; if ($this->max > 0) { $completeBars = floor($percent * $this->barWidth); } else { if (!$finish) { $completeBars = floor($this->current % $this->barWidth); } else { $completeBars = $this->barWidth; } } $emptyBars = $this->barWidth - $completeBars - $this->strlen($this->progressChar); $bar = str_repeat($this->barChar, $completeBars); if ($completeBars < $this->barWidth) { $bar .= $this->progressChar; $bar .= str_repeat($this->emptyBarChar, $emptyBars); } $vars['bar'] = $bar; } if (isset($this->formatVars['elapsed'])) { $elapsed = time() - $this->startTime; $vars['elapsed'] = str_pad($this->humaneTime($elapsed), $this->widths['elapsed'], ' ', STR_PAD_LEFT); } if (isset($this->formatVars['current'])) { $vars['current'] = str_pad($this->current, $this->widths['current'], ' ', STR_PAD_LEFT); } if (isset($this->formatVars['max'])) { $vars['max'] = $this->max; } if (isset($this->formatVars['percent'])) { $vars['percent'] = str_pad($percent * 100, $this->widths['percent'], ' ', STR_PAD_LEFT); } return $vars; } /** * Converts seconds into human-readable format. * * @param integer $secs Number of seconds * * @return string Time in readable format */ private function humaneTime($secs) { $text = ''; foreach ($this->timeFormats as $format) { if ($secs < $format[0]) { if (count($format) == 2) { $text = $format[1]; break; } else { $text = ceil($secs / $format[2]).' '.$format[1]; break; } } } return $text; } /** * Overwrites a previous message to the output. * * @param OutputInterface $output An Output instance * @param string $message The message */ private function overwrite(OutputInterface $output, $message) { $length = $this->strlen($message); // append whitespace to match the last line's length if (null !== $this->lastMessagesLength && $this->lastMessagesLength > $length) { $message = str_pad($message, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT); } // carriage return $output->write("\x0D"); $output->write($message); $this->lastMessagesLength = $this->strlen($message); } /** * {@inheritDoc} */ public function getName() { return 'progress'; } } ./Console-2.3.1/Symfony/Component/Console/Helper/DescriptorHelper.php0000644001161000116100000000534212155624475023267 0ustar arar * * 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\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Descriptor\DescriptorInterface; use Symfony\Component\Console\Descriptor\JsonDescriptor; use Symfony\Component\Console\Descriptor\MarkdownDescriptor; use Symfony\Component\Console\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** * This class adds helper method to describe objects in various formats. * * @author Jean-François Simon */ class DescriptorHelper extends Helper { /** * @var DescriptorInterface[] */ private $descriptors = array(); /** * Constructor. */ public function __construct() { $this ->register('txt', new TextDescriptor()) ->register('xml', new XmlDescriptor()) ->register('json', new JsonDescriptor()) ->register('md', new MarkdownDescriptor()) ; } /** * Describes an object if supported. * * @param OutputInterface $output * @param object $object * @param string $format * @param boolean $raw */ public function describe(OutputInterface $output, $object, $format = null, $raw = false, $namespace = null) { $options = array('raw_text' => $raw, 'format' => $format ?: 'txt', 'namespace' => $namespace); $type = !$raw && 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; if (!isset($this->descriptors[$options['format']])) { throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format'])); } $descriptor = $this->descriptors[$options['format']]; $output->writeln($descriptor->describe($object, $options), $type); } /** * Registers a descriptor. * * @param string $format * @param DescriptorInterface $descriptor * * @return DescriptorHelper */ public function register($format, DescriptorInterface $descriptor) { $this->descriptors[$format] = $descriptor; return $this; } /** * {@inheritdoc} */ public function getName() { return 'descriptor'; } } ./Console-2.3.1/Symfony/Component/Console/Helper/FormatterHelper.php0000644001161000116100000000427412155624475023117 0ustar arar * * 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 */ 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', $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', $style, $message, $style); } return implode("\n", $messages); } /** * {@inheritDoc} */ public function getName() { return 'formatter'; } } ./Console-2.3.1/Symfony/Component/Console/Helper/DialogHelper.php0000644001161000116100000003772712155624475022364 0ustar arar * * 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; use Symfony\Component\Console\Formatter\OutputFormatterStyle; /** * The Dialog class provides helpers to interact with the user. * * @author Fabien Potencier */ class DialogHelper extends Helper { private $inputStream; private static $shell; private static $stty; /** * Asks the user to select a value. * * @param OutputInterface $output An Output instance * @param string|array $question The question to ask * @param array $choices List of choices to pick from * @param Boolean $default The default answer if the user enters nothing * @param Boolean|integer $attempts Max number of times to ask before giving up (false by default, which means infinite) * @param string $errorMessage Message which will be shown if invalid value from choice list would be picked * @param Boolean $multiselect Select more than one value separated by comma * * @return integer|string|array The selected value or values (the key of the choices array) * * @throws \InvalidArgumentException */ public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) { $width = max(array_map('strlen', array_keys($choices))); $messages = (array) $question; foreach ($choices as $key => $value) { $messages[] = sprintf(" [%-${width}s] %s", $key, $value); } $output->writeln($messages); $result = $this->askAndValidate($output, '> ', function ($picked) use ($choices, $errorMessage, $multiselect) { // Collapse all spaces. $selectedChoices = str_replace(" ", "", $picked); if ($multiselect) { // Check for a separated comma values if(!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) { throw new \InvalidArgumentException(sprintf($errorMessage, $picked)); } $selectedChoices = explode(",", $selectedChoices); } else { $selectedChoices = array($picked); } $multiselectChoices = array(); foreach ($selectedChoices as $value) { if (empty($choices[$value])) { throw new \InvalidArgumentException(sprintf($errorMessage, $value)); } array_push($multiselectChoices, $value); } if ($multiselect){ return $multiselectChoices; } return $picked; }, $attempts, $default); return $result; } /** * 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 * @param array $autocomplete List of values to autocomplete * * @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, array $autocomplete = null) { $output->write($question); $inputStream = $this->inputStream ?: STDIN; if (null === $autocomplete || !$this->hasSttyAvailable()) { $ret = fgets($inputStream, 4096); if (false === $ret) { throw new \RuntimeException('Aborted'); } $ret = trim($ret); } else { $ret = ''; $i = 0; $ofs = -1; $matches = $autocomplete; $numMatches = count($matches); $sttyMode = shell_exec('stty -g'); // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); // Add highlighted text style $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white')); // Read a keypress while (!feof($inputStream)) { $c = fread($inputStream, 1); // Backspace Character if ("\177" === $c) { if (0 === $numMatches && 0 !== $i) { $i--; // Move cursor backwards $output->write("\033[1D"); } if ($i === 0) { $ofs = -1; $matches = $autocomplete; $numMatches = count($matches); } else { $numMatches = 0; } // Pop the last character off the end of our string $ret = substr($ret, 0, $i); } elseif ("\033" === $c) { // Did we read an escape sequence? $c .= fread($inputStream, 2); // A = Up Arrow. B = Down Arrow if ('A' === $c[2] || 'B' === $c[2]) { if ('A' === $c[2] && -1 === $ofs) { $ofs = 0; } if (0 === $numMatches) { continue; } $ofs += ('A' === $c[2]) ? -1 : 1; $ofs = ($numMatches + $ofs) % $numMatches; } } elseif (ord($c) < 32) { if ("\t" === $c || "\n" === $c) { if ($numMatches > 0 && -1 !== $ofs) { $ret = $matches[$ofs]; // Echo out remaining chars for current match $output->write(substr($ret, $i)); $i = strlen($ret); } if ("\n" === $c) { $output->write($c); break; } $numMatches = 0; } continue; } else { $output->write($c); $ret .= $c; $i++; $numMatches = 0; $ofs = 0; foreach ($autocomplete as $value) { // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle) if (0 === strpos($value, $ret) && $i !== strlen($value)) { $matches[$numMatches++] = $value; } } } // Erase characters from cursor to end of line $output->write("\033[K"); if ($numMatches > 0 && -1 !== $ofs) { // Save cursor position $output->write("\0337"); // Write highlighted text $output->write(''.substr($matches[$ofs], $i).''); // Restore cursor position $output->write("\0338"); } } // Reset stty so it behaves normally again shell_exec(sprintf('stty %s', $sttyMode)); } 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 a question to the user, the response is hidden * * @param OutputInterface $output An Output instance * @param string|array $question The question * @param Boolean $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not * * @return string The answer * * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden */ public function askHiddenResponse(OutputInterface $output, $question, $fallback = true) { if (defined('PHP_WINDOWS_VERSION_BUILD')) { $exe = __DIR__.'/../Resources/bin/hiddeninput.exe'; // handle code running from a phar if ('phar:' === substr(__FILE__, 0, 5)) { $tmpExe = sys_get_temp_dir().'/hiddeninput.exe'; copy($exe, $tmpExe); $exe = $tmpExe; } $output->write($question); $value = rtrim(shell_exec($exe)); $output->writeln(''); if (isset($tmpExe)) { unlink($tmpExe); } return $value; } if ($this->hasSttyAvailable()) { $output->write($question); $sttyMode = shell_exec('stty -g'); shell_exec('stty -echo'); $value = fgets($this->inputStream ?: STDIN, 4096); shell_exec(sprintf('stty %s', $sttyMode)); if (false === $value) { throw new \RuntimeException('Aborted'); } $value = trim($value); $output->writeln(''); return $value; } if (false !== $shell = $this->getShell()) { $output->write($question); $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword'; $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); $value = rtrim(shell_exec($command)); $output->writeln(''); return $value; } if ($fallback) { return $this->ask($output, $question); } throw new \RuntimeException('Unable to hide the response'); } /** * 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 callable $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 * @param array $autocomplete List of values to autocomplete * * @return mixed * * @throws \Exception When any of the validators return an error */ public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null) { $that = $this; $interviewer = function() use ($output, $question, $default, $autocomplete, $that) { return $that->ask($output, $question, $default, $autocomplete); }; return $this->validateAttempts($interviewer, $output, $validator, $attempts); } /** * Asks for a value, hide 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 callable $validator A PHP callback * @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite) * @param Boolean $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not * * @return string The response * * @throws \Exception When any of the validators return an error * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden * */ public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true) { $that = $this; $interviewer = function() use ($output, $question, $fallback, $that) { return $that->askHiddenResponse($output, $question, $fallback); }; return $this->validateAttempts($interviewer, $output, $validator, $attempts); } /** * 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; } /** * {@inheritDoc} */ public function getName() { return 'dialog'; } /** * Return a valid unix shell * * @return string|Boolean The valid shell name, false in case no valid shell is found */ private function getShell() { if (null !== self::$shell) { return self::$shell; } self::$shell = false; if (file_exists('/usr/bin/env')) { // handle other OSs with bash/zsh/ksh/csh if available to hide the answer $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { self::$shell = $sh; break; } } } return self::$shell; } private function hasSttyAvailable() { if (null !== self::$stty) { return self::$stty; } exec('stty 2>&1', $output, $exitcode); return self::$stty = $exitcode === 0; } /** * Validate an attempt * * @param callable $interviewer A callable that will ask for a question and return the result * @param OutputInterface $output An Output instance * @param callable $validator A PHP callback * @param integer $attempts Max number of times to ask before giving up ; false will ask infinitely * * @return string The validated response * * @throws \Exception In case the max number of attempts has been reached and no valid response has been given */ private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts) { $error = null; while (false === $attempts || $attempts--) { if (null !== $error) { $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error')); } try { return call_user_func($validator, $interviewer()); } catch (\Exception $error) { } } throw $error; } } ./Console-2.3.1/Symfony/Component/Console/Helper/TableHelper.php0000644001161000116100000002423212155624475022177 0ustar arar * * 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; use InvalidArgumentException; /** * Provides helpers to display table output. * * @author Саша Стаменковић */ class TableHelper extends Helper { const LAYOUT_DEFAULT = 0; const LAYOUT_BORDERLESS = 1; /** * Table headers. * * @var array */ private $headers = array(); /** * Table rows. * * @var array */ private $rows = array(); // Rendering options private $paddingChar; private $horizontalBorderChar; private $verticalBorderChar; private $crossingChar; private $cellHeaderFormat; private $cellRowFormat; private $borderFormat; private $padType; /** * Column widths cache. * * @var array */ private $columnWidths = array(); /** * Number of columns cache. * * @var array */ private $numberOfColumns; /** * @var OutputInterface */ private $output; public function __construct() { $this->setLayout(self::LAYOUT_DEFAULT); } /** * Sets table layout type. * * @param int $layout self::LAYOUT_* * * @return TableHelper */ public function setLayout($layout) { switch ($layout) { case self::LAYOUT_BORDERLESS: $this ->setPaddingChar(' ') ->setHorizontalBorderChar('=') ->setVerticalBorderChar(' ') ->setCrossingChar(' ') ->setCellHeaderFormat('%s') ->setCellRowFormat('%s') ->setBorderFormat('%s') ->setPadType(STR_PAD_RIGHT) ; break; case self::LAYOUT_DEFAULT: $this ->setPaddingChar(' ') ->setHorizontalBorderChar('-') ->setVerticalBorderChar('|') ->setCrossingChar('+') ->setCellHeaderFormat('%s') ->setCellRowFormat('%s') ->setBorderFormat('%s') ->setPadType(STR_PAD_RIGHT) ; break; default: throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout)); break; }; return $this; } public function setHeaders(array $headers) { $this->headers = array_values($headers); return $this; } public function setRows(array $rows) { $this->rows = array(); return $this->addRows($rows); } public function addRows(array $rows) { foreach ($rows as $row) { $this->addRow($row); } return $this; } public function addRow(array $row) { $this->rows[] = array_values($row); return $this; } public function setRow($column, array $row) { $this->rows[$column] = $row; return $this; } /** * Sets padding character, used for cell padding. * * @param string $paddingChar * * @return TableHelper */ public function setPaddingChar($paddingChar) { $this->paddingChar = $paddingChar; return $this; } /** * Sets horizontal border character. * * @param string $horizontalBorderChar * * @return TableHelper */ public function setHorizontalBorderChar($horizontalBorderChar) { $this->horizontalBorderChar = $horizontalBorderChar; return $this; } /** * Sets vertical border character. * * @param string $verticalBorderChar * * @return TableHelper */ public function setVerticalBorderChar($verticalBorderChar) { $this->verticalBorderChar = $verticalBorderChar; return $this; } /** * Sets crossing character. * * @param string $crossingChar * * @return TableHelper */ public function setCrossingChar($crossingChar) { $this->crossingChar = $crossingChar; return $this; } /** * Sets header cell format. * * @param string $cellHeaderFormat * * @return TableHelper */ public function setCellHeaderFormat($cellHeaderFormat) { $this->cellHeaderFormat = $cellHeaderFormat; return $this; } /** * Sets row cell format. * * @param string $cellRowFormat * * @return TableHelper */ public function setCellRowFormat($cellRowFormat) { $this->cellRowFormat = $cellRowFormat; return $this; } /** * Sets table border format. * * @param string $borderFormat * * @return TableHelper */ public function setBorderFormat($borderFormat) { $this->borderFormat = $borderFormat; return $this; } /** * Sets cell padding type. * * @param integer $padType STR_PAD_* * * @return TableHelper */ public function setPadType($padType) { $this->padType = $padType; return $this; } /** * Renders table to output. * * Example: * +---------------+-----------------------+------------------+ * | ISBN | Title | Author | * +---------------+-----------------------+------------------+ * | 99921-58-10-7 | Divine Comedy | Dante Alighieri | * | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien | * +---------------+-----------------------+------------------+ * * @param OutputInterface $output */ public function render(OutputInterface $output) { $this->output = $output; $this->renderRowSeparator(); $this->renderRow($this->headers, $this->cellHeaderFormat); if (!empty($this->headers)) { $this->renderRowSeparator(); } foreach ($this->rows as $row) { $this->renderRow($row, $this->cellRowFormat); } if (!empty($this->rows)) { $this->renderRowSeparator(); } $this->cleanup(); } /** * Renders horizontal header separator. * * Example: +-----+-----------+-------+ */ private function renderRowSeparator() { if (0 === $count = $this->getNumberOfColumns()) { return; } $markup = $this->crossingChar; for ($column = 0; $column < $count; $column++) { $markup .= str_repeat($this->horizontalBorderChar, $this->getColumnWidth($column)) .$this->crossingChar ; } $this->output->writeln(sprintf($this->borderFormat, $markup)); } /** * Renders vertical column separator. */ private function renderColumnSeparator() { $this->output->write(sprintf($this->borderFormat, $this->verticalBorderChar)); } /** * Renders table row. * * Example: | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | * * @param array $row * @param string $cellFormat */ private function renderRow(array $row, $cellFormat) { if (empty($row)) { return; } $this->renderColumnSeparator(); for ($column = 0, $count = $this->getNumberOfColumns(); $column < $count; $column++) { $this->renderCell($row, $column, $cellFormat); $this->renderColumnSeparator(); } $this->output->writeln(''); } /** * Renders table cell with padding. * * @param array $row * @param integer $column * @param string $cellFormat */ private function renderCell(array $row, $column, $cellFormat) { $cell = isset($row[$column]) ? $row[$column] : ''; $this->output->write(sprintf( $cellFormat, str_pad( $this->paddingChar.$cell.$this->paddingChar, $this->getColumnWidth($column), $this->paddingChar, $this->padType ) )); } /** * Gets number of columns for this table. * * @return int */ private function getNumberOfColumns() { if (null !== $this->numberOfColumns) { return $this->numberOfColumns; } $columns = array(0); $columns[] = count($this->headers); foreach ($this->rows as $row) { $columns[] = count($row); } return $this->numberOfColumns = max($columns); } /** * Gets column width. * * @param integer $column * * @return int */ private function getColumnWidth($column) { if (isset($this->columnWidths[$column])) { return $this->columnWidths[$column]; } $lengths = array(0); $lengths[] = $this->getCellWidth($this->headers, $column); foreach ($this->rows as $row) { $lengths[] = $this->getCellWidth($row, $column); } return $this->columnWidths[$column] = max($lengths) + 2; } /** * Gets cell width. * * @param array $row * @param integer $column * * @return int */ private function getCellWidth(array $row, $column) { if ($column < 0) { return 0; } if (isset($row[$column])) { return $this->strlen($row[$column]); } return $this->getCellWidth($row, $column - 1); } /** * Called after rendering to cleanup cache data. */ private function cleanup() { $this->columnWidths = array(); $this->numberOfColumns = null; } /** * {@inheritDoc} */ public function getName() { return 'table'; } } ./Console-2.3.1/Symfony/Component/Console/Event/0000755001161000116100000000000012165326424017130 5ustar arar./Console-2.3.1/Symfony/Component/Console/Event/ConsoleExceptionEvent.php0000644001161000116100000000307312155624475024135 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Event; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * Allows to handle exception thrown in a command. * * @author Fabien Potencier */ class ConsoleExceptionEvent extends ConsoleEvent { private $exception; private $exitCode; public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode) { parent::__construct($command, $input, $output); $this->setException($exception); $this->exitCode = $exitCode; } /** * Returns the thrown exception. * * @return \Exception The thrown exception */ public function getException() { return $this->exception; } /** * Replaces the thrown exception. * * This exception will be thrown if no response is set in the event. * * @param \Exception $exception The thrown exception */ public function setException(\Exception $exception) { $this->exception = $exception; } /** * Gets the exit code. * * @return integer The command exit code */ public function getExitCode() { return $this->exitCode; } } ./Console-2.3.1/Symfony/Component/Console/Event/ConsoleTerminateEvent.php0000644001161000116100000000244012155624475024124 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Event; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * Allows to manipulate the exit code of a command after its execution. * * @author Francesco Levorato */ class ConsoleTerminateEvent extends ConsoleEvent { /** * The exit code of the command. * * @var integer */ private $exitCode; public function __construct(Command $command, InputInterface $input, OutputInterface $output, $exitCode) { parent::__construct($command, $input, $output); $this->setExitCode($exitCode); } /** * Sets the exit code. * * @param integer $exitCode The command exit code */ public function setExitCode($exitCode) { $this->exitCode = $exitCode; } /** * Gets the exit code. * * @return integer The command exit code */ public function getExitCode() { return $this->exitCode; } } ./Console-2.3.1/Symfony/Component/Console/Event/ConsoleCommandEvent.php0000644001161000116100000000113212155624475023547 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Event; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * Allows to do things before the command is executed. * * @author Fabien Potencier */ class ConsoleCommandEvent extends ConsoleEvent { } ./Console-2.3.1/Symfony/Component/Console/Event/ConsoleEvent.php0000644001161000116100000000267012155624475022260 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Event; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\Event; /** * Allows to inspect input and output of a command. * * @author Francesco Levorato */ class ConsoleEvent extends Event { protected $command; private $input; private $output; public function __construct(Command $command, InputInterface $input, OutputInterface $output) { $this->command = $command; $this->input = $input; $this->output = $output; } /** * Gets the command that is executed. * * @return Command A Command instance */ public function getCommand() { return $this->command; } /** * Gets the input instance. * * @return InputInterface An InputInterface instance */ public function getInput() { return $this->input; } /** * Gets the output instance. * * @return OutputInterface An OutputInterface instance */ public function getOutput() { return $this->output; } } ./Console-2.3.1/Symfony/Component/Console/README.md0000644001161000116100000000365512155624475017345 0ustar ararConsole 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 %s', $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: $ cd path/to/Symfony/Component/Console/ $ composer.phar install --dev $ phpunit Third Party ----------- `Resources/bin/hiddeninput.exe` is a third party binary provided within this component. Find sources and license at https://github.com/Seldaek/hidden-input. 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) ./Console-2.3.1/Symfony/Component/Console/Input/0000755001161000116100000000000012165326424017146 5ustar arar./Console-2.3.1/Symfony/Component/Console/Input/InputDefinition.php0000644001161000116100000002711612155624475023004 0ustar arar * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Console\Input; use Symfony\Component\Console\Descriptor\TextDescriptor; use Symfony\Component\Console\Descriptor\XmlDescriptor; /** * 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 * * @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 InputArgument[] $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) { if (!$this->hasArgument($name)) { throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments; 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 InputArgument[] 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 InputOption[] $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())); } if ($option->getShortcut()) { foreach (explode('|', $option->getShortcut()) as $shortcut) { if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) { throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut)); } } } $this->options[$option->getName()] = $option; if ($option->getShortcut()) { foreach (explode('|', $option->getShortcut()) as $shortcut) { $this->shortcuts[$shortcut] = $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 InputOption[] 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 * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asText() { $descriptor = new TextDescriptor(); return $descriptor->describe($this); } /** * 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 * * @deprecated Deprecated since version 2.3, to be removed in 3.0. */ public function asXml($asDom = false) { $descriptor = new XmlDescriptor(); return $descriptor->describe($this, array('as_dom' => $asDom)); } } ./Console-2.3.1/Symfony/Component/Console/Input/StringInput.php0000644001161000116100000000537312155624475022163 0ustar arar * * 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 * * @api */ class StringInput extends ArgvInput { const REGEX_STRING = '([^\s]+?)(?:\s|(?setTokens($this->tokenize($input)); if (null !== $definition) { $this->bind($definition); } } /** * 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) { $tokens = array(); $length = strlen($input); $cursor = 0; while ($cursor < $length) { if (preg_match('/\s+/A', $input, $match, null, $cursor)) { } elseif (preg_match('/([^="\'\s]+?)(=?)('.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; } } ./Console-2.3.1/Symfony/Component/Console/Input/InputOption.php0000644001161000116100000001352612155624475022164 0ustar arar * * 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 * * @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|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts * @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 (is_array($shortcut)) { $shortcut = implode('|', $shortcut); } $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-')); $shortcuts = array_filter($shortcuts); $shortcut = implode('|', $shortcuts); 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 InputOption::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() ; } } ./Console-2.3.1/Symfony/Component/Console/Input/ArgvInput.php0000644001161000116100000002416112155624475021610 0ustar arar * * 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 * * @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); // Convert false values (from a previous call to substr()) to null if (false === $value) { $value = null; } if (null === $value && $option->acceptValue() && count($this->parsed)) { // if option accepts an optional or mandatory argument // let's see if there is one provided $next = array_shift($this->parsed); if (isset($next[0]) && '-' !== $next[0]) { $value = $next; } elseif (empty($next)) { $value = ''; } else { array_unshift($this->parsed, $next); } } if (null === $value) { if ($option->isValueRequired()) { throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name)); } if (!$option->isArray()) { $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; } /** * Returns a stringified representation of the args passed to the command * * @return string */ public function __toString() { $self = $this; $tokens = array_map(function ($token) use ($self) { if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) { return $match[1] . $self->escapeToken($match[2]); } if ($token && $token[0] !== '-') { return $self->escapeToken($token); } return $token; }, $this->tokens); return implode(' ', $tokens); } } ./Console-2.3.1/Symfony/Component/Console/Input/InputArgument.php0000644001161000116100000000632712155624475022477 0ustar arar * * 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 * * @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 InputArgument::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; } } ./Console-2.3.1/Symfony/Component/Console/Input/ArrayInput.php0000644001161000116100000001344512155624475021772 0ustar arar * * 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 * * @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; } /** * Returns a stringified representation of the args passed to the command * * @return string */ public function __toString() { $params = array(); foreach ($this->parameters as $param => $val) { if ($param && '-' === $param[0]) { $params[] = $param . ('' != $val ? '='.$this->escapeToken($val) : ''); } else { $params[] = $this->escapeToken($val); } } return implode(' ', $params); } /** * 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; } } ./Console-2.3.1/Symfony/Component/Console/Input/InputInterface.php0000644001161000116100000001004612155624475022606 0ustar arar * * 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 */ 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); } ./Console-2.3.1/Symfony/Component/Console/Input/Input.php0000644001161000116100000001377612155624475021002 0ustar arar * * 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 */ 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->arguments = array(); $this->options = array(); $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); } /** * Escapes a token through escapeshellarg if it contains unsafe chars * * @param string $token * * @return string */ public function escapeToken($token) { return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token); } } ./Console-2.3.1/Symfony/Component/Console/LICENSE0000644001161000116100000000205112155624475017060 0ustar ararCopyright (c) 2004-2013 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. ./Console-2.3.1/Symfony/Component/Console/Formatter/0000755001161000116100000000000012165326424020012 5ustar arar./Console-2.3.1/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php0000644001161000116100000000263712155624475026567 0ustar arar * * 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 * * @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); } ./Console-2.3.1/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php0000644001161000116100000000533212155624475025727 0ustar arar * * 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 */ 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; } } ./Console-2.3.1/Symfony/Component/Console/Formatter/OutputFormatter.php0000644001161000116100000001427212155624475023723 0ustar arar * * 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 * * @api */ class OutputFormatter implements OutputFormatterInterface { /** * The pattern to phrase the format. */ const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx'; 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('/([^\\\\]?) 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(sprintf('Undefined style: %s', $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 Styled text */ private function applyCurrentStyle($text) { return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text; } } ./Console-2.3.1/Symfony/Component/Console/Formatter/OutputFormatterInterface.php0000644001161000116100000000334312155624475025541 0ustar arar * * 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 * * @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); } ./Console-2.3.1/Symfony/Component/Console/Formatter/OutputFormatterStyle.php0000644001161000116100000001341512155624475024742 0ustar arar * * 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 * * @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); } } ./package.xml0000644001161000116100000005570712155624475011137 0ustar arar Console pear.symfony.com Symfony2 Console Component Symfony2 Console Component Fabien Potencier fabpot fabien@symfony.com yes 2013-06-11 2.3.1 2.3.1 stable stable MIT - 5.3.2 1.4.0