Augmentation vers version 3.3.0
This commit is contained in:
142
vendor/symfony/console/Command/Command.php
vendored
142
vendor/symfony/console/Command/Command.php
vendored
@@ -12,8 +12,6 @@
|
||||
namespace Symfony\Component\Console\Command;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
||||
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
@@ -22,7 +20,6 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
@@ -32,21 +29,38 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
/**
|
||||
* @var string|null The default command name
|
||||
*/
|
||||
protected static $defaultName;
|
||||
|
||||
private $application;
|
||||
private $name;
|
||||
private $processTitle;
|
||||
private $aliases = array();
|
||||
private $aliases = [];
|
||||
private $definition;
|
||||
private $help;
|
||||
private $description;
|
||||
private $hidden = false;
|
||||
private $help = '';
|
||||
private $description = '';
|
||||
private $ignoreValidationErrors = false;
|
||||
private $applicationDefinitionMerged = false;
|
||||
private $applicationDefinitionMergedWithArgs = false;
|
||||
private $code;
|
||||
private $synopsis = array();
|
||||
private $usages = array();
|
||||
private $synopsis = [];
|
||||
private $usages = [];
|
||||
private $helperSet;
|
||||
|
||||
/**
|
||||
* @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()
|
||||
*
|
||||
@@ -56,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)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +105,7 @@ class Command
|
||||
/**
|
||||
* Gets the helper set.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
* @return HelperSet|null A HelperSet instance
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
@@ -105,7 +115,7 @@ class Command
|
||||
/**
|
||||
* Gets the application instance for this command.
|
||||
*
|
||||
* @return Application An Application instance
|
||||
* @return Application|null An Application instance
|
||||
*/
|
||||
public function getApplication()
|
||||
{
|
||||
@@ -262,17 +272,13 @@ class Command
|
||||
*
|
||||
* @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()) {
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
// Bug in PHP5: https://bugs.php.net/bug.php?id=64761
|
||||
// Bug in PHP5: https://bugs.php.net/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.
|
||||
@@ -341,11 +347,15 @@ class Command
|
||||
*/
|
||||
public function getDefinition()
|
||||
{
|
||||
if (null === $this->definition) {
|
||||
throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', \get_class($this)));
|
||||
}
|
||||
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -363,9 +373,9 @@ class Command
|
||||
* Adds an argument.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
||||
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|null $default The default value (for self::OPTIONAL mode only)
|
||||
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
|
||||
*
|
||||
* @throws InvalidArgumentException When argument mode is not valid
|
||||
*
|
||||
@@ -382,10 +392,10 @@ class Command
|
||||
* Adds an option.
|
||||
*
|
||||
* @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 int|null $mode The option mode: One of the VALUE_* constants
|
||||
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
|
||||
* @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
|
||||
*
|
||||
* @throws InvalidArgumentException If option mode is invalid or incompatible
|
||||
*
|
||||
@@ -443,13 +453,33 @@ class Command
|
||||
/**
|
||||
* Returns the command name.
|
||||
*
|
||||
* @return string The command name
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
@@ -507,15 +537,16 @@ class Command
|
||||
public function getProcessedHelp()
|
||||
{
|
||||
$name = $this->name;
|
||||
$isSingleCommand = $this->application && $this->application->isSingleCommand();
|
||||
|
||||
$placeholders = array(
|
||||
$placeholders = [
|
||||
'%command.name%',
|
||||
'%command.full_name%',
|
||||
);
|
||||
$replacements = array(
|
||||
];
|
||||
$replacements = [
|
||||
$name,
|
||||
$_SERVER['PHP_SELF'].' '.$name,
|
||||
);
|
||||
$isSingleCommand ? $_SERVER['PHP_SELF'] : $_SERVER['PHP_SELF'].' '.$name,
|
||||
];
|
||||
|
||||
return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
|
||||
}
|
||||
@@ -619,49 +650,6 @@ class Command
|
||||
return $this->helperSet->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Symfony 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 Symfony 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.
|
||||
*
|
||||
|
||||
15
vendor/symfony/console/Command/HelpCommand.php
vendored
15
vendor/symfony/console/Command/HelpCommand.php
vendored
@@ -35,12 +35,11 @@ class HelpCommand extends Command
|
||||
|
||||
$this
|
||||
->setName('help')
|
||||
->setDefinition(array(
|
||||
->setDefinition([
|
||||
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'),
|
||||
))
|
||||
])
|
||||
->setDescription('Displays help for a command')
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command displays help for a given command:
|
||||
@@ -71,17 +70,11 @@ 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(
|
||||
$helper->describe($output, $this->command, [
|
||||
'format' => $input->getOption('format'),
|
||||
'raw_text' => $input->getOption('raw'),
|
||||
));
|
||||
]);
|
||||
|
||||
$this->command = null;
|
||||
}
|
||||
|
||||
15
vendor/symfony/console/Command/ListCommand.php
vendored
15
vendor/symfony/console/Command/ListCommand.php
vendored
@@ -68,18 +68,12 @@ 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(
|
||||
$helper->describe($output, $this->getApplication(), [
|
||||
'format' => $input->getOption('format'),
|
||||
'raw_text' => $input->getOption('raw'),
|
||||
'namespace' => $input->getArgument('namespace'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,11 +81,10 @@ EOF
|
||||
*/
|
||||
private function createDefinition()
|
||||
{
|
||||
return new InputDefinition(array(
|
||||
return new InputDefinition([
|
||||
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'),
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
72
vendor/symfony/console/Command/LockableTrait.php
vendored
Normal file
72
vendor/symfony/console/Command/LockableTrait.php
vendored
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user