summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Command
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-12-15 11:24:35 -0800
committerFrédéric Guillot <fred@kanboard.net>2017-12-15 11:55:42 -0800
commita93b8e10f5954be0853eec693c13e84c4bd9e6f2 (patch)
treeeda5de9494b819235616e8623bb3393e9cc373af /vendor/symfony/console/Command
parent2c72a283f2d51034f85f4e2ca8b194d304a3c433 (diff)
Kanboard requires at least PHP 5.6 now
Diffstat (limited to 'vendor/symfony/console/Command')
-rw-r--r--vendor/symfony/console/Command/Command.php164
-rw-r--r--vendor/symfony/console/Command/HelpCommand.php12
-rw-r--r--vendor/symfony/console/Command/ListCommand.php7
-rw-r--r--vendor/symfony/console/Command/LockableTrait.php72
4 files changed, 142 insertions, 113 deletions
diff --git a/vendor/symfony/console/Command/Command.php b/vendor/symfony/console/Command/Command.php
index 6acbe219..06930425 100644
--- a/vendor/symfony/console/Command/Command.php
+++ b/vendor/symfony/console/Command/Command.php
@@ -11,14 +11,11 @@
namespace Symfony\Component\Console\Command;
-use Symfony\Component\Console\Descriptor\TextDescriptor;
-use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Exception\ExceptionInterface;
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\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
@@ -32,11 +29,17 @@ use Symfony\Component\Console\Exception\LogicException;
*/
class Command
{
+ /**
+ * @var string|null The default command name
+ */
+ protected static $defaultName;
+
private $application;
private $name;
private $processTitle;
private $aliases = array();
private $definition;
+ private $hidden = false;
private $help;
private $description;
private $ignoreValidationErrors = false;
@@ -48,8 +51,17 @@ class Command
private $helperSet;
/**
- * Constructor.
- *
+ * @return string|null The default command name or null when no default name is set
+ */
+ public static function getDefaultName()
+ {
+ $class = get_called_class();
+ $r = new \ReflectionProperty($class, 'defaultName');
+
+ return $class === $r->class ? static::$defaultName : null;
+ }
+
+ /**
* @param string|null $name The name of the command; passing null means it must be set in configure()
*
* @throws LogicException When the command name is empty
@@ -58,15 +70,11 @@ class Command
{
$this->definition = new InputDefinition();
- if (null !== $name) {
+ if (null !== $name || null !== $name = static::getDefaultName()) {
$this->setName($name);
}
$this->configure();
-
- if (!$this->name) {
- throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
- }
}
/**
@@ -79,11 +87,6 @@ class Command
$this->ignoreValidationErrors = true;
}
- /**
- * Sets the application instance for this command.
- *
- * @param Application $application An Application instance
- */
public function setApplication(Application $application = null)
{
$this->application = $application;
@@ -94,11 +97,6 @@ class Command
}
}
- /**
- * Sets the helper set.
- *
- * @param HelperSet $helperSet A HelperSet instance
- */
public function setHelperSet(HelperSet $helperSet)
{
$this->helperSet = $helperSet;
@@ -152,9 +150,6 @@ class Command
* 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|int null or 0 if everything went fine, or an error code
*
* @throws LogicException When this abstract method is not implemented
@@ -172,9 +167,6 @@ class Command
* This method is executed before the InputDefinition is validated.
* This means that this is the only place where the command can
* interactively ask for values of missing required arguments.
- *
- * @param InputInterface $input An InputInterface instance
- * @param OutputInterface $output An OutputInterface instance
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
@@ -185,9 +177,6 @@ class Command
*
* 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)
{
@@ -200,12 +189,9 @@ class Command
* 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 int The command exit code
*
- * @throws \Exception
+ * @throws \Exception When binding input fails. Bypass this by calling {@link ignoreValidationErrors()}.
*
* @see setCode()
* @see execute()
@@ -232,7 +218,14 @@ class Command
if (null !== $this->processTitle) {
if (function_exists('cli_set_process_title')) {
- cli_set_process_title($this->processTitle);
+ if (false === @cli_set_process_title($this->processTitle)) {
+ if ('Darwin' === PHP_OS) {
+ $output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
+ } else {
+ $error = error_get_last();
+ trigger_error($error['message'], E_USER_WARNING);
+ }
+ }
} elseif (function_exists('setproctitle')) {
setproctitle($this->processTitle);
} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
@@ -270,22 +263,26 @@ class Command
*
* @param callable $code A callable(InputInterface $input, OutputInterface $output)
*
- * @return Command The current instance
+ * @return $this
*
* @throws InvalidArgumentException
*
* @see execute()
*/
- public function setCode($code)
+ public function setCode(callable $code)
{
- if (!is_callable($code)) {
- throw new InvalidArgumentException('Invalid callable provided to Command::setCode.');
- }
-
- if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
+ if ($code instanceof \Closure) {
$r = new \ReflectionFunction($code);
if (null === $r->getClosureThis()) {
- $code = \Closure::bind($code, $this);
+ if (\PHP_VERSION_ID < 70000) {
+ // Bug in PHP5: https://bugs.php.net/bug.php?id=64761
+ // This means that we cannot bind static closures and therefore we must
+ // ignore any errors here. There is no way to test if the closure is
+ // bindable.
+ $code = @\Closure::bind($code, $this);
+ } else {
+ $code = \Closure::bind($code, $this);
+ }
}
}
@@ -326,7 +323,7 @@ class Command
*
* @param array|InputDefinition $definition An array of argument and option instances or a definition instance
*
- * @return Command The current instance
+ * @return $this
*/
public function setDefinition($definition)
{
@@ -352,7 +349,7 @@ class Command
}
/**
- * Gets the InputDefinition to be used to create XML and Text representations of this Command.
+ * Gets the InputDefinition to be used to create 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.
@@ -374,7 +371,7 @@ class Command
* @param string $description A description text
* @param mixed $default The default value (for InputArgument::OPTIONAL mode only)
*
- * @return Command The current instance
+ * @return $this
*/
public function addArgument($name, $mode = null, $description = '', $default = null)
{
@@ -392,7 +389,7 @@ class Command
* @param string $description A description text
* @param mixed $default The default value (must be null for InputOption::VALUE_NONE)
*
- * @return Command The current instance
+ * @return $this
*/
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
{
@@ -411,7 +408,7 @@ class Command
*
* @param string $name The command name
*
- * @return Command The current instance
+ * @return $this
*
* @throws InvalidArgumentException When the name is invalid
*/
@@ -434,7 +431,7 @@ class Command
*
* @param string $title The process title
*
- * @return Command The current instance
+ * @return $this
*/
public function setProcessTitle($title)
{
@@ -454,11 +451,31 @@ class Command
}
/**
+ * @param bool $hidden Whether or not the command should be hidden from the list of commands
+ *
+ * @return Command The current instance
+ */
+ public function setHidden($hidden)
+ {
+ $this->hidden = (bool) $hidden;
+
+ return $this;
+ }
+
+ /**
+ * @return bool whether the command should be publicly shown or not
+ */
+ public function isHidden()
+ {
+ return $this->hidden;
+ }
+
+ /**
* Sets the description for the command.
*
* @param string $description The description for the command
*
- * @return Command The current instance
+ * @return $this
*/
public function setDescription($description)
{
@@ -482,7 +499,7 @@ class Command
*
* @param string $help The help for the command
*
- * @return Command The current instance
+ * @return $this
*/
public function setHelp($help)
{
@@ -528,7 +545,7 @@ class Command
*
* @param string[] $aliases An array of aliases for the command
*
- * @return Command The current instance
+ * @return $this
*
* @throws InvalidArgumentException When an alias is invalid
*/
@@ -579,6 +596,8 @@ class Command
* Add a command usage example.
*
* @param string $usage The usage, it'll be prefixed with the command name
+ *
+ * @return $this
*/
public function addUsage($usage)
{
@@ -621,49 +640,6 @@ class Command
}
/**
- * Returns a text representation of the command.
- *
- * @return string A string representing the command
- *
- * @deprecated since version 2.3, to be removed in 3.0.
- */
- public function asText()
- {
- @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0.', E_USER_DEPRECATED);
-
- $descriptor = new TextDescriptor();
- $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
- $descriptor->describe($output, $this, array('raw_output' => true));
-
- return $output->fetch();
- }
-
- /**
- * Returns an XML representation of the command.
- *
- * @param bool $asDom Whether to return a DOM or an XML string
- *
- * @return string|\DOMDocument An XML string representing the command
- *
- * @deprecated since version 2.3, to be removed in 3.0.
- */
- public function asXml($asDom = false)
- {
- @trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0.', E_USER_DEPRECATED);
-
- $descriptor = new XmlDescriptor();
-
- if ($asDom) {
- return $descriptor->getCommandDocument($this);
- }
-
- $output = new BufferedOutput();
- $descriptor->describe($output, $this);
-
- return $output->fetch();
- }
-
- /**
* Validates a command name.
*
* It must be non-empty and parts can optionally be separated by ":".
diff --git a/vendor/symfony/console/Command/HelpCommand.php b/vendor/symfony/console/Command/HelpCommand.php
index c0e7b388..112679b3 100644
--- a/vendor/symfony/console/Command/HelpCommand.php
+++ b/vendor/symfony/console/Command/HelpCommand.php
@@ -37,7 +37,6 @@ class HelpCommand extends Command
->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, 'The output format (txt, xml, json, or md)', 'txt'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
))
@@ -57,11 +56,6 @@ EOF
;
}
- /**
- * Sets the command.
- *
- * @param Command $command The command to set
- */
public function setCommand(Command $command)
{
$this->command = $command;
@@ -76,12 +70,6 @@ EOF
$this->command = $this->getApplication()->find($input->getArgument('command_name'));
}
- if ($input->getOption('xml')) {
- @trigger_error('The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead.', E_USER_DEPRECATED);
-
- $input->setOption('format', 'xml');
- }
-
$helper = new DescriptorHelper();
$helper->describe($output, $this->command, array(
'format' => $input->getOption('format'),
diff --git a/vendor/symfony/console/Command/ListCommand.php b/vendor/symfony/console/Command/ListCommand.php
index 5e1b926a..179ddea5 100644
--- a/vendor/symfony/console/Command/ListCommand.php
+++ b/vendor/symfony/console/Command/ListCommand.php
@@ -68,12 +68,6 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- if ($input->getOption('xml')) {
- @trigger_error('The --xml option was deprecated in version 2.7 and will be removed in version 3.0. Use the --format option instead.', E_USER_DEPRECATED);
-
- $input->setOption('format', 'xml');
- }
-
$helper = new DescriptorHelper();
$helper->describe($output, $this->getApplication(), array(
'format' => $input->getOption('format'),
@@ -89,7 +83,6 @@ EOF
{
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, 'The output format (txt, xml, json, or md)', 'txt'),
));
diff --git a/vendor/symfony/console/Command/LockableTrait.php b/vendor/symfony/console/Command/LockableTrait.php
new file mode 100644
index 00000000..308ebf28
--- /dev/null
+++ b/vendor/symfony/console/Command/LockableTrait.php
@@ -0,0 +1,72 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Console\Command;
+
+use Symfony\Component\Console\Exception\LogicException;
+use Symfony\Component\Console\Exception\RuntimeException;
+use Symfony\Component\Lock\Factory;
+use Symfony\Component\Lock\Lock;
+use Symfony\Component\Lock\Store\FlockStore;
+use Symfony\Component\Lock\Store\SemaphoreStore;
+
+/**
+ * Basic lock feature for commands.
+ *
+ * @author Geoffrey Brier <geoffrey.brier@gmail.com>
+ */
+trait LockableTrait
+{
+ /** @var Lock */
+ private $lock;
+
+ /**
+ * Locks a command.
+ *
+ * @return bool
+ */
+ private function lock($name = null, $blocking = false)
+ {
+ if (!class_exists(SemaphoreStore::class)) {
+ throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.');
+ }
+
+ if (null !== $this->lock) {
+ throw new LogicException('A lock is already in place.');
+ }
+
+ if (SemaphoreStore::isSupported($blocking)) {
+ $store = new SemaphoreStore();
+ } else {
+ $store = new FlockStore();
+ }
+
+ $this->lock = (new Factory($store))->createLock($name ?: $this->getName());
+ if (!$this->lock->acquire($blocking)) {
+ $this->lock = null;
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Releases the command lock if there is one.
+ */
+ private function release()
+ {
+ if ($this->lock) {
+ $this->lock->release();
+ $this->lock = null;
+ }
+ }
+}