From 4dc4f694ca7baa2448de7ab68b9ecfb8edca53b5 Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Thu, 22 Dec 2016 14:40:27 +0100 Subject: [PATCH 01/15] remove is_writable check on filesystem cache --- src/Symfony/Component/Cache/Adapter/AbstractAdapter.php | 3 +++ .../Component/Cache/Adapter/FilesystemAdapter.php | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php index 1b53e3390c..a8a2d00f6f 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractAdapter.php @@ -16,6 +16,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use Psr\Log\LoggerInterface; use Symfony\Component\Cache\CacheItem; +use Symfony\Component\Cache\Exception\CacheException; /** * @author Nicolas Grekas @@ -129,6 +130,8 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface * @param int $lifetime The lifetime of the cached values, 0 for persisting until manual cleaning * * @return array|bool The identifiers that failed to be cached or a boolean stating if caching succeeded or not + * + * @throws CacheException If write can not be performed */ abstract protected function doSave(array $values, $lifetime); diff --git a/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php b/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php index 81886b4d11..686c532239 100644 --- a/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Cache\Adapter; +use Symfony\Component\Cache\Exception\CacheException; use Symfony\Component\Cache\Exception\InvalidArgumentException; /** @@ -39,9 +40,7 @@ class FilesystemAdapter extends AbstractAdapter if (false === $dir = realpath($dir) ?: (file_exists($dir) ? $dir : false)) { throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory)); } - if (!is_writable($dir .= DIRECTORY_SEPARATOR)) { - throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory)); - } + $dir .= DIRECTORY_SEPARATOR; // On Windows the whole path is limited to 258 chars if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) { throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory)); @@ -141,6 +140,10 @@ class FilesystemAdapter extends AbstractAdapter } } + if (!$ok && !is_writable($this->directory)) { + throw new CacheException(sprintf('Cache directory is not writable (%s)', $this->directory)); + } + return $ok; } From 82275936045d9854a3721b299e8fce54690d444f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 23 Dec 2016 15:07:27 +0100 Subject: [PATCH 02/15] [SecurityBundle] Made collection of user provider unique when injecting them to the RemberMeService --- .../DependencyInjection/Security/Factory/RememberMeFactory.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index 7aa4f5baa0..c6688affb4 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -96,7 +96,8 @@ class RememberMeFactory implements SecurityFactoryInterface if (count($userProviders) === 0) { throw new \RuntimeException('You must configure at least one remember-me aware listener (such as form-login) for each firewall that has remember-me enabled.'); } - $rememberMeServices->replaceArgument(0, $userProviders); + + $rememberMeServices->replaceArgument(0, array_unique($userProviders)); // remember-me listener $listenerId = 'security.authentication.listener.rememberme.'.$id; From 7808b675fcfccb1cfb926c35ad340e1af9c4c3c8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 27 Dec 2016 11:48:22 +0100 Subject: [PATCH 03/15] fixed @return when returning this or static --- src/Symfony/Component/Console/Helper/Table.php | 2 +- .../Component/DependencyInjection/Definition.php | 12 ++++++------ .../Form/ChoiceList/View/ChoiceGroupView.php | 2 +- .../Component/Form/ResolvedFormTypeInterface.php | 2 +- src/Symfony/Component/PropertyInfo/Type.php | 4 ++-- .../Routing/Matcher/Dumper/DumperCollection.php | 4 ++-- .../Component/Routing/RouteCollectionBuilder.php | 4 ++-- src/Symfony/Component/Stopwatch/Section.php | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 260eafe503..77d21ca83b 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -145,7 +145,7 @@ class Table * @param int $columnIndex Column index * @param TableStyle|string $name The style name or a TableStyle instance * - * @return Table + * @return self */ public function setColumnStyle($columnIndex, $name) { diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 8eb548f5a7..3441ebe6c9 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -547,7 +547,7 @@ class Definition * * @param bool $shared Whether the service must be shared or not * - * @return Definition The current instance + * @return self */ public function setShared($shared) { @@ -749,7 +749,7 @@ class Definition * @param bool $status * @param string $template Template message to use if the definition is deprecated * - * @return Definition the current instance + * @return self * * @throws InvalidArgumentException When the message template is invalid. */ @@ -824,7 +824,7 @@ class Definition * * @param string[] $types * - * @return Definition The current instance + * @return self */ public function setAutowiringTypes(array $types) { @@ -852,7 +852,7 @@ class Definition * * @param bool $autowired * - * @return Definition The current instance + * @return self */ public function setAutowired($autowired) { @@ -876,7 +876,7 @@ class Definition * * @param string $type * - * @return Definition The current instance + * @return self */ public function addAutowiringType($type) { @@ -890,7 +890,7 @@ class Definition * * @param string $type * - * @return Definition The current instance + * @return self */ public function removeAutowiringType($type) { diff --git a/src/Symfony/Component/Form/ChoiceList/View/ChoiceGroupView.php b/src/Symfony/Component/Form/ChoiceList/View/ChoiceGroupView.php index 9e648cc360..f3eae3762a 100644 --- a/src/Symfony/Component/Form/ChoiceList/View/ChoiceGroupView.php +++ b/src/Symfony/Component/Form/ChoiceList/View/ChoiceGroupView.php @@ -48,7 +48,7 @@ class ChoiceGroupView implements \IteratorAggregate /** * {@inheritdoc} * - * @return ChoiceGroupView[]|ChoiceView[] + * @return self[]|ChoiceView[] */ public function getIterator() { diff --git a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php index 1601ef62c2..a59052eac5 100644 --- a/src/Symfony/Component/Form/ResolvedFormTypeInterface.php +++ b/src/Symfony/Component/Form/ResolvedFormTypeInterface.php @@ -30,7 +30,7 @@ interface ResolvedFormTypeInterface /** * Returns the parent type. * - * @return ResolvedFormTypeInterface|null The parent type or null + * @return self|null The parent type or null */ public function getParent(); diff --git a/src/Symfony/Component/PropertyInfo/Type.php b/src/Symfony/Component/PropertyInfo/Type.php index 8a55a7cbc2..ad21f91724 100644 --- a/src/Symfony/Component/PropertyInfo/Type.php +++ b/src/Symfony/Component/PropertyInfo/Type.php @@ -148,7 +148,7 @@ class Type * * Only applicable for a collection type. * - * @return Type|null + * @return self|null */ public function getCollectionKeyType() { @@ -160,7 +160,7 @@ class Type * * Only applicable for a collection type. * - * @return Type|null + * @return self|null */ public function getCollectionValueType() { diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php b/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php index 2bfdb2e882..b24c8512ce 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php @@ -38,7 +38,7 @@ class DumperCollection implements \IteratorAggregate /** * Returns the children routes and collections. * - * @return DumperCollection[]|DumperRoute[] Array of DumperCollection|DumperRoute + * @return self[]|DumperRoute[] */ public function all() { @@ -96,7 +96,7 @@ class DumperCollection implements \IteratorAggregate /** * Returns the parent collection. * - * @return DumperCollection|null The parent collection or null if the collection has no parent + * @return self|null The parent collection or null if the collection has no parent */ protected function getParent() { diff --git a/src/Symfony/Component/Routing/RouteCollectionBuilder.php b/src/Symfony/Component/Routing/RouteCollectionBuilder.php index 114c1d60f7..2c9e031723 100644 --- a/src/Symfony/Component/Routing/RouteCollectionBuilder.php +++ b/src/Symfony/Component/Routing/RouteCollectionBuilder.php @@ -55,7 +55,7 @@ class RouteCollectionBuilder * @param string|null $prefix * @param string $type * - * @return RouteCollectionBuilder + * @return self * * @throws FileLoaderLoadException */ @@ -101,7 +101,7 @@ class RouteCollectionBuilder /** * Returns a RouteCollectionBuilder that can be configured and then added with mount(). * - * @return RouteCollectionBuilder + * @return self */ public function createBuilder() { diff --git a/src/Symfony/Component/Stopwatch/Section.php b/src/Symfony/Component/Stopwatch/Section.php index e2d4dec5cb..2337e03140 100644 --- a/src/Symfony/Component/Stopwatch/Section.php +++ b/src/Symfony/Component/Stopwatch/Section.php @@ -53,7 +53,7 @@ class Section * * @param string $id The child section identifier * - * @return Section|null The child section or null when none found + * @return self|null The child section or null when none found */ public function get($id) { From eaca2a4509b4cc58b94595e50d9a9a391ff476b2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 19 Dec 2016 16:58:51 +0100 Subject: [PATCH 04/15] [cache] Bump RedisAdapter timeout to 5s Bump RedisAdapter timeout to 5s because (at least with Predis) 0 means 0s --- src/Symfony/Component/Cache/Adapter/RedisAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php index a636124acb..d0d3b72e50 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php @@ -25,8 +25,8 @@ class RedisAdapter extends AbstractAdapter private static $defaultConnectionOptions = array( 'class' => null, 'persistent' => 0, - 'timeout' => 0, - 'read_timeout' => 0, + 'timeout' => 30, + 'read_timeout' => 30, 'retry_interval' => 0, ); private $redis; From aed6f867820014332e733765003391beb958c589 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 27 Dec 2016 14:36:53 +0100 Subject: [PATCH 05/15] fix merge --- src/Symfony/Component/Cache/Adapter/RedisAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php index d0d3b72e50..3a59e837ee 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php @@ -26,7 +26,7 @@ class RedisAdapter extends AbstractAdapter 'class' => null, 'persistent' => 0, 'timeout' => 30, - 'read_timeout' => 30, + 'read_timeout' => 0, 'retry_interval' => 0, ); private $redis; From ed713aef2bb436b47af4dda7eb35fae2c72ff0be Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 21 Dec 2016 12:36:34 +0100 Subject: [PATCH 06/15] [Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes --- .../UndefinedMethodFatalErrorHandler.php | 8 +++++++- .../UndefinedMethodFatalErrorHandlerTest.php | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php index f734d6bb7d..6fa62b6f24 100644 --- a/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php +++ b/src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php @@ -36,8 +36,13 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className); + if (!class_exists($className) || null === $methods = get_class_methods($className)) { + // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class) + return new UndefinedMethodException($message, $exception); + } + $candidates = array(); - foreach (get_class_methods($className) as $definedMethodName) { + foreach ($methods as $definedMethodName) { $lev = levenshtein($methodName, $definedMethodName); if ($lev <= strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) { $candidates[] = $definedMethodName; @@ -52,6 +57,7 @@ class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface } else { $candidates = '"'.$last; } + $message .= "\nDid you mean to call ".$candidates; } diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php index de7b21c699..22cbc3033b 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php @@ -61,6 +61,15 @@ class UndefinedMethodFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase ), "Attempted to call an undefined method named \"offsetFet\" of class \"SplObjectStorage\".\nDid you mean to call e.g. \"offsetGet\", \"offsetSet\" or \"offsetUnset\"?", ), + array( + array( + 'type' => 1, + 'message' => 'Call to undefined method class@anonymous::test()', + 'file' => '/home/possum/work/symfony/test.php', + 'line' => 11, + ), + 'Attempted to call an undefined method named "test" of class "class@anonymous".', + ), ); } } From 18dfef1e2b5cd84035532de94823ed5a9a2bbc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 27 Dec 2016 15:47:08 +0100 Subject: [PATCH 07/15] [Debug] Wrap call to ->log in a try catch block If something goes wrong in the logger, the application ends up with a blank page. Let's display the original exception. --- src/Symfony/Component/Debug/ErrorHandler.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 9d8ab8060f..8c664c54f9 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -504,7 +504,11 @@ class ErrorHandler } } if ($this->loggedErrors & $type) { - $this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e); + try { + $this->loggers[$type][0]->log($this->loggers[$type][1], $message, $e); + } catch (\Exception $handlerException) { + } catch (\Throwable $handlerException) { + } } if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) { foreach ($this->getFatalErrorHandlers() as $handler) { From 3f3c6e0e5318533a1c84f02f77bc3472f0d9faa3 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 25 Dec 2016 09:24:14 +0000 Subject: [PATCH 08/15] [Config] Improve PHPdoc / IDE autocomplete --- src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php | 2 +- .../Component/Config/Definition/Builder/MergeBuilder.php | 2 +- .../Component/Config/Definition/Builder/NodeDefinition.php | 2 +- .../Component/Config/Definition/Builder/ValidationBuilder.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php index 45878c02fb..10112a813d 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php @@ -198,7 +198,7 @@ class ExprBuilder /** * Returns the related node. * - * @return NodeDefinition + * @return NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition * * @throws \RuntimeException */ diff --git a/src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php index 14240f5251..1d24953df5 100644 --- a/src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/MergeBuilder.php @@ -63,7 +63,7 @@ class MergeBuilder /** * Returns the related node. * - * @return NodeDefinition + * @return NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition */ public function end() { diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php index c8a3a248b4..1b712a3150 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php @@ -107,7 +107,7 @@ abstract class NodeDefinition implements NodeParentInterface /** * Returns the parent node. * - * @return NodeParentInterface|NodeBuilder|NodeDefinition|null The builder of the parent node + * @return NodeParentInterface|NodeBuilder|NodeDefinition|ArrayNodeDefinition|VariableNodeDefinition|null The builder of the parent node */ public function end() { diff --git a/src/Symfony/Component/Config/Definition/Builder/ValidationBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ValidationBuilder.php index e885823892..12aa59a4fd 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ValidationBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ValidationBuilder.php @@ -36,7 +36,7 @@ class ValidationBuilder * * @param \Closure $closure * - * @return ExprBuilder|ValidationBuilder + * @return ExprBuilder|$this */ public function rule(\Closure $closure = null) { From 8e9a5f8009dc22eefbe0bdac62bd2947cc5fbbcc Mon Sep 17 00:00:00 2001 From: Maxime STEINHAUSSER Date: Tue, 13 Dec 2016 15:25:44 +0100 Subject: [PATCH 09/15] [Console] Descriptors should use Helper::strlen --- .../Console/Descriptor/MarkdownDescriptor.php | 5 +- .../Console/Descriptor/TextDescriptor.php | 17 +- .../Descriptor/AbstractDescriptorTest.php | 2 +- .../Descriptor/MarkdownDescriptorTest.php | 18 + .../Tests/Descriptor/TextDescriptorTest.php | 18 + .../DescriptorApplicationMbString.php | 24 ++ .../Fixtures/DescriptorCommandMbString.php | 32 ++ .../Tests/Fixtures/application_mbstring.md | 309 ++++++++++++++++++ .../Tests/Fixtures/application_mbstring.txt | 19 ++ .../Tests/Fixtures/command_mbstring.md | 33 ++ .../Tests/Fixtures/command_mbstring.txt | 13 + 11 files changed, 479 insertions(+), 11 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 2eb9944d62..c2d6243e28 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -94,7 +95,7 @@ class MarkdownDescriptor extends Descriptor $this->write( $command->getName()."\n" - .str_repeat('-', strlen($command->getName()))."\n\n" + .str_repeat('-', Helper::strlen($command->getName()))."\n\n" .'* Description: '.($command->getDescription() ?: '')."\n" .'* Usage:'."\n\n" .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { @@ -121,7 +122,7 @@ class MarkdownDescriptor extends Descriptor $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); - $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName()))); + $this->write($application->getName()."\n".str_repeat('=', Helper::strlen($application->getName()))); foreach ($description->getNamespaces() as $namespace) { if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index eb02c89dfa..c18ed6f224 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputOption; @@ -37,7 +38,7 @@ class TextDescriptor extends Descriptor $default = ''; } - $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName()); + $totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName()); $spacingWidth = $totalWidth - strlen($argument->getName()); $this->writeText(sprintf(' %s %s%s%s', @@ -75,7 +76,7 @@ class TextDescriptor extends Descriptor sprintf('--%s%s', $option->getName(), $value) ); - $spacingWidth = $totalWidth - strlen($synopsis); + $spacingWidth = $totalWidth - Helper::strlen($synopsis); $this->writeText(sprintf(' %s %s%s%s%s', $synopsis, @@ -94,7 +95,7 @@ class TextDescriptor extends Descriptor { $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); foreach ($definition->getArguments() as $argument) { - $totalWidth = max($totalWidth, strlen($argument->getName())); + $totalWidth = max($totalWidth, Helper::strlen($argument->getName())); } if ($definition->getArguments()) { @@ -206,7 +207,7 @@ class TextDescriptor extends Descriptor foreach ($namespace['commands'] as $name) { $this->writeText("\n"); - $spacingWidth = $width - strlen($name); + $spacingWidth = $width - Helper::strlen($name); $this->writeText(sprintf(' %s%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); } } @@ -252,9 +253,9 @@ class TextDescriptor extends Descriptor $widths = array(); foreach ($commands as $command) { - $widths[] = strlen($command->getName()); + $widths[] = Helper::strlen($command->getName()); foreach ($command->getAliases() as $alias) { - $widths[] = strlen($alias); + $widths[] = Helper::strlen($alias); } } @@ -271,10 +272,10 @@ class TextDescriptor extends Descriptor $totalWidth = 0; foreach ($options as $option) { // "-" + shortcut + ", --" + name - $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName()); + $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName()); if ($option->acceptValue()) { - $valueLength = 1 + strlen($option->getName()); // = + value + $valueLength = 1 + Helper::strlen($option->getName()); // = + value $valueLength += $option->isValueOptional() ? 2 : 0; // [ + ] $nameLength += $valueLength; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index c36c4a8e5e..74e95b7569 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -86,7 +86,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase abstract protected function getFormat(); - private function getDescriptionTestData(array $objects) + protected function getDescriptionTestData(array $objects) { $data = array(); foreach ($objects as $name => $object) { diff --git a/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php index c85e8a594b..eb80f58b1c 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php @@ -12,9 +12,27 @@ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\MarkdownDescriptor; +use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; +use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; class MarkdownDescriptorTest extends AbstractDescriptorTest { + public function getDescribeCommandTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getCommands(), + array('command_mbstring' => new DescriptorCommandMbString()) + )); + } + + public function getDescribeApplicationTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getApplications(), + array('application_mbstring' => new DescriptorApplicationMbString()) + )); + } + protected function getDescriptor() { return new MarkdownDescriptor(); diff --git a/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php index 350b67950d..364e29c026 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php @@ -12,9 +12,27 @@ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\TextDescriptor; +use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; +use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; class TextDescriptorTest extends AbstractDescriptorTest { + public function getDescribeCommandTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getCommands(), + array('command_mbstring' => new DescriptorCommandMbString()) + )); + } + + public function getDescribeApplicationTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getApplications(), + array('application_mbstring' => new DescriptorApplicationMbString()) + )); + } + protected function getDescriptor() { return new TextDescriptor(); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php new file mode 100644 index 0000000000..bf170c449f --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php @@ -0,0 +1,24 @@ + + * + * 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 DescriptorApplicationMbString extends Application +{ + public function __construct() + { + parent::__construct('MbString åpplicätion'); + + $this->add(new DescriptorCommandMbString()); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php new file mode 100644 index 0000000000..66de917e29 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php @@ -0,0 +1,32 @@ + + * + * 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 DescriptorCommandMbString extends Command +{ + protected function configure() + { + $this + ->setName('descriptor:åèä') + ->setDescription('command åèä description') + ->setHelp('command åèä help') + ->addUsage('-o|--option_name ') + ->addUsage('') + ->addArgument('argument_åèä', InputArgument::REQUIRED) + ->addOption('option_åèä', 'o', InputOption::VALUE_NONE) + ; + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md new file mode 100644 index 0000000000..ef81f86972 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md @@ -0,0 +1,309 @@ +MbString åpplicätion +==================== + +* help +* list + +**descriptor:** + +* descriptor:åèä + +help +---- + +* Description: Displays help for a command +* Usage: + + * `help [--xml] [--format FORMAT] [--raw] [--] []` + +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: The output format (txt, xml, json, or md) +* Default: `'txt'` + +**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 FORMAT] [--] []` + +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: The output format (txt, xml, json, or md) +* Default: `'txt'` + +descriptor:åèä +-------------- + +* Description: command åèä description +* Usage: + + * `descriptor:åèä [-o|--option_åèä] [--] ` + * `descriptor:åèä -o|--option_name ` + * `descriptor:åèä ` + +command åèä help + +### Arguments: + +**argument_åèä:** + +* Name: argument_åèä +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_åèä:** + +* Name: `--option_åèä` +* 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` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt new file mode 100644 index 0000000000..9d21f829d5 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt @@ -0,0 +1,19 @@ +MbString åpplicätion + +Usage: + command [options] [arguments] + +Options: + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + +Available commands: + help Displays help for a command + list Lists commands + descriptor + descriptor:åèä command åèä description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md new file mode 100644 index 0000000000..2adac53f05 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md @@ -0,0 +1,33 @@ +descriptor:åèä +-------------- + +* Description: command åèä description +* Usage: + + * `descriptor:åèä [-o|--option_åèä] [--] ` + * `descriptor:åèä -o|--option_name ` + * `descriptor:åèä ` + +command åèä help + +### Arguments: + +**argument_åèä:** + +* Name: argument_åèä +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_åèä:** + +* Name: `--option_åèä` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt new file mode 100644 index 0000000000..969a065242 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt @@ -0,0 +1,13 @@ +Usage: + descriptor:åèä [options] [--] + descriptor:åèä -o|--option_name + descriptor:åèä + +Arguments: + argument_åèä + +Options: + -o, --option_åèä + +Help: + command åèä help From 7a603df71ded072c0f6a0e66524acb1b588a6a73 Mon Sep 17 00:00:00 2001 From: Marcin Szepczynski Date: Thu, 29 Dec 2016 12:15:44 +0100 Subject: [PATCH 10/15] Polish translation improvement in Validator component --- .../Validator/Resources/translations/validators.pl.xlf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf index 1d6875fb78..87bb76b8b0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf @@ -36,11 +36,11 @@ This field was not expected. - To pole nie spodziewano. + Tego pola się nie spodziewano. This field is missing. - To pole jest chybianie. + Tego pola brakuje. This value is not a valid date. From 2a778c2d16b91c4519ba6b135fc152ffb4a0c9cc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 29 Dec 2016 22:43:11 +0100 Subject: [PATCH 11/15] fixed @return when returning this or static --- src/Symfony/Component/Console/Helper/Table.php | 4 ++-- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- src/Symfony/Component/HttpFoundation/JsonResponse.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 0e833bf3b8..38729250ee 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -187,7 +187,7 @@ class Table * @param int $columnIndex Column index * @param int $width Minimum column width in characters * - * @return Table + * @return $this */ public function setColumnWidth($columnIndex, $width) { @@ -201,7 +201,7 @@ class Table * * @param array $widths * - * @return Table + * @return $this */ public function setColumnWidths(array $widths) { diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 7512da95e1..71b05d983e 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -694,7 +694,7 @@ class Crawler implements \Countable, \IteratorAggregate * * @param string $value The image alt * - * @return Crawler A new instance of Crawler with the filtered list of nodes + * @return self A new instance of Crawler with the filtered list of nodes */ public function selectImage($value) { diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 8a70b130ce..533775e85b 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -109,7 +109,7 @@ class JsonResponse extends Response * * @param string $json * - * @return JsonResponse + * @return $this * * @throws \InvalidArgumentException */ From 20d8c74bfed449bd3869dba064b442cc9f214060 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 29 Dec 2016 22:47:05 +0100 Subject: [PATCH 12/15] Fixed @return when returning this or static #bis --- src/Symfony/Component/Console/Helper/Table.php | 2 +- .../Component/DependencyInjection/Definition.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 77d21ca83b..d622294ed4 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -145,7 +145,7 @@ class Table * @param int $columnIndex Column index * @param TableStyle|string $name The style name or a TableStyle instance * - * @return self + * @return $this */ public function setColumnStyle($columnIndex, $name) { diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 3441ebe6c9..a002df2875 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -547,7 +547,7 @@ class Definition * * @param bool $shared Whether the service must be shared or not * - * @return self + * @return $this */ public function setShared($shared) { @@ -749,7 +749,7 @@ class Definition * @param bool $status * @param string $template Template message to use if the definition is deprecated * - * @return self + * @return $this * * @throws InvalidArgumentException When the message template is invalid. */ @@ -824,7 +824,7 @@ class Definition * * @param string[] $types * - * @return self + * @return $this */ public function setAutowiringTypes(array $types) { @@ -852,7 +852,7 @@ class Definition * * @param bool $autowired * - * @return self + * @return $this */ public function setAutowired($autowired) { @@ -876,7 +876,7 @@ class Definition * * @param string $type * - * @return self + * @return $this */ public function addAutowiringType($type) { @@ -890,7 +890,7 @@ class Definition * * @param string $type * - * @return self + * @return $this */ public function removeAutowiringType($type) { From 9928c0d44e21201ec86f23b1316e797f1d303f90 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 28 Dec 2016 14:01:35 +0100 Subject: [PATCH 13/15] [Console] OS X Can't call cli_set_process_title php without superuser --- src/Symfony/Component/Console/Command/Command.php | 9 ++++++++- .../Component/Console/Tests/Command/CommandTest.php | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 9bcfdf79ca..ff4075962e 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -227,7 +227,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('Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.'); + } 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()) { diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 2c63387116..1468cbe2ea 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -328,6 +328,9 @@ class CommandTest extends \PHPUnit_Framework_TestCase $command->setProcessTitle('foo'); $this->assertSame(0, $command->run(new StringInput(''), new NullOutput())); if (function_exists('cli_set_process_title')) { + if (null === @cli_get_process_title() && 'Darwin' === PHP_OS) { + $this->markTestSkipped('Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.'); + } $this->assertEquals('foo', cli_get_process_title()); } } From c24269005bbbca3d62399d4d9fe949d28f8055c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Wed, 28 Dec 2016 15:28:00 +0100 Subject: [PATCH 14/15] [Console] Escape default value when dumping help --- .../Component/Console/Descriptor/TextDescriptor.php | 11 +++++++++++ .../Console/Tests/Descriptor/ObjectsProvider.php | 3 +++ .../Tests/Fixtures/input_argument_with_style.json | 7 +++++++ .../Tests/Fixtures/input_argument_with_style.md | 7 +++++++ .../Tests/Fixtures/input_argument_with_style.txt | 1 + .../Tests/Fixtures/input_argument_with_style.xml | 7 +++++++ .../Tests/Fixtures/input_option_with_style.json | 9 +++++++++ .../Tests/Fixtures/input_option_with_style.md | 9 +++++++++ .../Tests/Fixtures/input_option_with_style.txt | 1 + .../Tests/Fixtures/input_option_with_style.xml | 7 +++++++ .../Fixtures/input_option_with_style_array.json | 12 ++++++++++++ .../Tests/Fixtures/input_option_with_style_array.md | 9 +++++++++ .../Tests/Fixtures/input_option_with_style_array.txt | 1 + .../Tests/Fixtures/input_option_with_style_array.xml | 8 ++++++++ 14 files changed, 92 insertions(+) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.xml diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index c18ed6f224..b49b64d5ac 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; @@ -236,6 +237,16 @@ class TextDescriptor extends Descriptor */ private function formatDefaultValue($default) { + if (is_string($default)) { + $default = OutputFormatter::escape($default); + } elseif (is_array($default)) { + foreach ($default as $key => $value) { + if (is_string($value)) { + $default[$key] = OutputFormatter::escape($value); + } + } + } + if (PHP_VERSION_ID < 50400) { return str_replace(array('\/', '\\\\'), array('/', '\\'), json_encode($default)); } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php index 45b3b2fff9..8f825ecb68 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php @@ -31,6 +31,7 @@ class ObjectsProvider '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'), 'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"), + 'input_argument_with_style' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'style'), ); } @@ -43,6 +44,8 @@ class ObjectsProvider 'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()), 'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"), 'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'), + 'input_option_with_style' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', 'style'), + 'input_option_with_style_array' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('Hello', 'world')), ); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.json b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.json new file mode 100644 index 0000000000..9334235109 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.json @@ -0,0 +1,7 @@ +{ + "name": "argument_name", + "is_required": false, + "is_array": false, + "description": "argument description", + "default": "style" +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md new file mode 100644 index 0000000000..45adf2f488 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md @@ -0,0 +1,7 @@ +**argument_name:** + +* Name: argument_name +* Is required: no +* Is array: no +* Description: argument description +* Default: `'style'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.txt new file mode 100644 index 0000000000..35384a6be8 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.txt @@ -0,0 +1 @@ + argument_name argument description [default: "\style\"] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.xml new file mode 100644 index 0000000000..73332c796e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.xml @@ -0,0 +1,7 @@ + + + argument description + + <comment>style</> + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.json new file mode 100644 index 0000000000..df328bf824 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.json @@ -0,0 +1,9 @@ +{ + "name": "--option_name", + "shortcut": "-o", + "accept_value": true, + "is_value_required": true, + "is_multiple": false, + "description": "option description", + "default": "style" +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md new file mode 100644 index 0000000000..3f6dd2369a --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: yes +* Is value required: yes +* Is multiple: no +* Description: option description +* Default: `'style'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.txt new file mode 100644 index 0000000000..880a53518e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.txt @@ -0,0 +1 @@ + -o, --option_name=OPTION_NAME option description [default: "\style\"] diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.xml new file mode 100644 index 0000000000..764b9e6521 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.xml @@ -0,0 +1,7 @@ + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.json b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.json new file mode 100644 index 0000000000..b1754550b5 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.json @@ -0,0 +1,12 @@ +{ + "name": "--option_name", + "shortcut": "-o", + "accept_value": true, + "is_value_required": true, + "is_multiple": true, + "description": "option description", + "default": [ + "Hello", + "world" + ] +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md new file mode 100644 index 0000000000..24e58b5302 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md @@ -0,0 +1,9 @@ +**option_name:** + +* Name: `--option_name` +* Shortcut: `-o` +* Accept value: yes +* Is value required: yes +* Is multiple: yes +* Description: option description +* Default: `array ( 0 => 'Hello', 1 => 'world',)` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.txt new file mode 100644 index 0000000000..265c18c5a4 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.txt @@ -0,0 +1 @@ + -o, --option_name=OPTION_NAME option description [default: ["\Hello\","\world\"]] (multiple values allowed) diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.xml b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.xml new file mode 100644 index 0000000000..09dc865830 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.xml @@ -0,0 +1,8 @@ + + From 97b7fabf519b48333b772924b141f84efdb44c1e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 1 Jan 2017 13:18:05 +0100 Subject: [PATCH 15/15] do not depend on a fixed date in layout tests By default, the `DateType` as well as the `DateTimeType` set the choices being available for the year to a range starting five years in the past. After some time, this will make tests fail when the year of the fixed date being used as the initial data is before the first year being part of the choices. --- src/Symfony/Bridge/Twig/composer.json | 2 +- src/Symfony/Bundle/FrameworkBundle/composer.json | 2 +- .../Form/Tests/AbstractBootstrap3LayoutTest.php | 16 ++++++++-------- .../Component/Form/Tests/AbstractLayoutTest.php | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 74c98e93a5..426bf9a64c 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -22,7 +22,7 @@ "require-dev": { "symfony/asset": "~2.7", "symfony/finder": "~2.3", - "symfony/form": "~2.7.11|~2.8.4", + "symfony/form": "~2.7.23|~2.8.16", "symfony/http-kernel": "~2.3", "symfony/intl": "~2.3", "symfony/routing": "~2.2", diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 9f62cb42e7..ead3235670 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -40,7 +40,7 @@ "symfony/dom-crawler": "~2.0,>=2.0.5", "symfony/intl": "~2.3", "symfony/security": "~2.6", - "symfony/form": "~2.7,>=2.7.2", + "symfony/form": "~2.7.23|~2.8.16", "symfony/class-loader": "~2.1", "symfony/expression-language": "~2.6", "symfony/process": "~2.0,>=2.0.5", diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php index c3e1b3bd8a..5e5c8be680 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php @@ -1333,7 +1333,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest public function testDateTime() { - $form = $this->factory->createNamed('name', 'datetime', '2011-02-03 04:05:06', array( + $form = $this->factory->createNamed('name', 'datetime', date('Y').'-02-03 04:05:06', array( 'input' => 'string', 'with_seconds' => false, )); @@ -1352,7 +1352,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest /following-sibling::select [@id="name_date_year"] [@class="form-control"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] /following-sibling::select [@id="name_time_hour"] [@class="form-control"] @@ -1407,7 +1407,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest public function testDateTimeWithHourAndMinute() { - $data = array('year' => '2011', 'month' => '2', 'day' => '3', 'hour' => '4', 'minute' => '5'); + $data = array('year' => date('Y'), 'month' => '2', 'day' => '3', 'hour' => '4', 'minute' => '5'); $form = $this->factory->createNamed('name', 'datetime', $data, array( 'input' => 'array', @@ -1429,7 +1429,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest /following-sibling::select [@id="name_date_year"] [@class="form-control"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] /following-sibling::select [@id="name_time_hour"] [@class="form-control"] @@ -1446,7 +1446,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest public function testDateTimeWithSeconds() { - $form = $this->factory->createNamed('name', 'datetime', '2011-02-03 04:05:06', array( + $form = $this->factory->createNamed('name', 'datetime', date('Y').'-02-03 04:05:06', array( 'input' => 'string', 'with_seconds' => true, )); @@ -1466,7 +1466,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest /following-sibling::select [@id="name_date_year"] [@class="form-control"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] /following-sibling::select [@id="name_time_hour"] [@class="form-control"] @@ -1556,7 +1556,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest public function testDateChoice() { - $form = $this->factory->createNamed('name', 'date', '2011-02-03', array( + $form = $this->factory->createNamed('name', 'date', date('Y').'-02-03', array( 'input' => 'string', 'widget' => 'choice', )); @@ -1576,7 +1576,7 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest /following-sibling::select [@id="name_year"] [@class="form-control"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] ] [count(./select)=3] ' diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 05f52249a9..1678a4bb2b 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -1226,7 +1226,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg public function testDateTime() { - $form = $this->factory->createNamed('name', 'datetime', '2011-02-03 04:05:06', array( + $form = $this->factory->createNamed('name', 'datetime', date('Y').'-02-03 04:05:06', array( 'input' => 'string', 'with_seconds' => false, )); @@ -1245,7 +1245,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg [./option[@value="3"][@selected="selected"]] /following-sibling::select [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -1305,7 +1305,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg public function testDateTimeWithHourAndMinute() { - $data = array('year' => '2011', 'month' => '2', 'day' => '3', 'hour' => '4', 'minute' => '5'); + $data = array('year' => date('Y'), 'month' => '2', 'day' => '3', 'hour' => '4', 'minute' => '5'); $form = $this->factory->createNamed('name', 'datetime', $data, array( 'input' => 'array', @@ -1326,7 +1326,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg [./option[@value="3"][@selected="selected"]] /following-sibling::select [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -1346,7 +1346,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg public function testDateTimeWithSeconds() { - $form = $this->factory->createNamed('name', 'datetime', '2011-02-03 04:05:06', array( + $form = $this->factory->createNamed('name', 'datetime', date('Y').'-02-03 04:05:06', array( 'input' => 'string', 'with_seconds' => true, )); @@ -1365,7 +1365,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg [./option[@value="3"][@selected="selected"]] /following-sibling::select [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -1452,7 +1452,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg public function testDateChoice() { - $form = $this->factory->createNamed('name', 'date', '2011-02-03', array( + $form = $this->factory->createNamed('name', 'date', date('Y').'-02-03', array( 'input' => 'string', 'widget' => 'choice', )); @@ -1468,7 +1468,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg [./option[@value="3"][@selected="selected"]] /following-sibling::select [@id="name_year"] - [./option[@value="2011"][@selected="selected"]] + [./option[@value="'.date('Y').'"][@selected="selected"]] ] [count(./select)=3] '