From 0642911ede99b3c072fb6b30d9433fc8afed80ff Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 21 Apr 2015 19:09:11 +0100 Subject: [PATCH 01/12] [FrameworkBundle] Add a doctrine cache service definition for validator mapping --- .../FrameworkBundle/Resources/config/validator.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml index ccfd44e5ca483..c0bf73a94e981 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml @@ -39,6 +39,16 @@ %validator.mapping.cache.prefix% + + + + + %validator.mapping.cache.prefix% + + + + + From b93bcc1153f00e7078987690bb3b628fe4445c7e Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sun, 14 Jun 2015 20:11:27 +0200 Subject: [PATCH 02/12] Fixed colspan issues with multiple render() calls --- .../Component/Console/Helper/Table.php | 39 ++++++++++--------- .../Console/Tests/Helper/TableTest.php | 37 +++++++++++++++--- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 392d4652ef586..d480774630f9f 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -205,24 +205,26 @@ public function setRow($column, array $row) public function render() { $this->calculateNumberOfColumns(); - $this->rows = $this->buildTableRows($this->rows); - $this->headers = $this->buildTableRows($this->headers); + $rows = $this->buildTableRows($this->rows); + $headers = $this->buildTableRows($this->headers); + + $this->calculateColumnsWidth(array_merge($headers, $rows)); $this->renderRowSeparator(); - if (!empty($this->headers)) { - foreach ($this->headers as $header) { + if (!empty($headers)) { + foreach ($headers as $header) { $this->renderRow($header, $this->style->getCellHeaderFormat()); $this->renderRowSeparator(); } } - foreach ($this->rows as $row) { + foreach ($rows as $row) { if ($row instanceof TableSeparator) { $this->renderRowSeparator(); } else { $this->renderRow($row, $this->style->getCellRowFormat()); } } - if (!empty($this->rows)) { + if (!empty($rows)) { $this->renderRowSeparator(); } @@ -246,7 +248,7 @@ private function renderRowSeparator() $markup = $this->style->getCrossingChar(); for ($column = 0; $column < $count; $column++) { - $markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->getColumnWidth($column)).$this->style->getCrossingChar(); + $markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->columnWidths[$column]).$this->style->getCrossingChar(); } $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup)); @@ -292,11 +294,11 @@ private function renderRow(array $row, $cellFormat) private function renderCell(array $row, $column, $cellFormat) { $cell = isset($row[$column]) ? $row[$column] : ''; - $width = $this->getColumnWidth($column); + $width = $this->columnWidths[$column]; if ($cell instanceof TableCell && $cell->getColspan() > 1) { // add the width of the following columns(numbers of colspan). foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) { - $width += $this->getColumnSeparatorWidth() + $this->getColumnWidth($nextColumn); + $width += $this->getColumnSeparatorWidth() + $this->columnWidths[$nextColumn]; } } @@ -509,21 +511,20 @@ private function getRowColumns($row) * * @return int */ - private function getColumnWidth($column) + private function calculateColumnsWidth($rows) { - if (isset($this->columnWidths[$column])) { - return $this->columnWidths[$column]; - } + for ($column = 0; $column < $this->numberOfColumns; $column++) { + $lengths = array(); + foreach ($rows as $row) { + if ($row instanceof TableSeparator) { + continue; + } - foreach (array_merge($this->headers, $this->rows) as $row) { - if ($row instanceof TableSeparator) { - continue; + $lengths[] = $this->getCellWidth($row, $column); } - $lengths[] = $this->getCellWidth($row, $column); + $this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2; } - - return $this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2; } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 3db51f45b0ab9..973b066561628 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -180,10 +180,10 @@ public function testRenderProvider() array( array('ISBN', 'Title', 'Author'), array( - array("99921-58-10-7", "Divine\nComedy", "Dante Alighieri"), - array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."), - array("9971-5-0210-2", "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."), - array("960-425-059-0", "The Lord of the Rings", "J. R. R.\nTolkien"), + array('99921-58-10-7', "Divine\nComedy", 'Dante Alighieri'), + array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."), + array('9971-5-0210-2', "Harry Potter\nand the Chamber of Secrets", "Rowling\nJoanne K."), + array('960-425-059-0', 'The Lord of the Rings', "J. R. R.\nTolkien"), ), 'default', << 3, 'colspan' => 1)), + new TableCell('9971-5-0210-0', array('rowspan' => 3, 'colspan' => 1)), 'Dante Alighieri', ), array(new TableSeparator()), @@ -547,6 +547,33 @@ public function testRowSeparator() | Bar3 | +------+ +TABLE; + + $this->assertEquals($expected, $this->getOutputContent($output)); + } + + public function testRenderMultiCalls() + { + $table = new Table($output = $this->getOutputStream()); + $table->setRows(array( + array(new TableCell('foo', array('colspan' => 2))), + )); + $table->render(); + $table->render(); + $table->render(); + + $expected = +<<
assertEquals($expected, $this->getOutputContent($output)); From f42c77710b84bc2b06886df18a89b0862d6aa057 Mon Sep 17 00:00:00 2001 From: "Issei.M" Date: Sat, 20 Jun 2015 17:41:53 +0900 Subject: [PATCH 03/12] [Form] moved data trimming logic of TrimListener into StringUtil --- src/Symfony/Component/Form/CHANGELOG.md | 1 + .../Core/EventListener/TrimListener.php | 7 +- .../Core/EventListener/TrimListenerTest.php | 63 ---------------- .../Form/Tests/Util/StringUtilTest.php | 72 +++++++++++++++++++ .../Component/Form/Util/StringUtil.php | 42 +++++++++++ 5 files changed, 117 insertions(+), 68 deletions(-) create mode 100644 src/Symfony/Component/Form/Tests/Util/StringUtilTest.php create mode 100644 src/Symfony/Component/Form/Util/StringUtil.php diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index 330f0b1417e25..76b2da1da319d 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * added the html5 "range" FormType * deprecated the "cascade_validation" option in favor of setting "constraints" with the Valid constraint + * moved data trimming logic of TrimListener into StringUtil 2.7.0 ----- diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php index db291e0e5b669..260e2699f56f8 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php @@ -14,6 +14,7 @@ use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Form\Util\StringUtil; /** * Trims string data. @@ -30,11 +31,7 @@ public function preSubmit(FormEvent $event) return; } - if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $data)) { - $event->setData($result); - } else { - $event->setData(trim($data)); - } + $event->setData(StringUtil::trim($data)); } /** diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php index 3818c7861f234..959eb928d20eb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php @@ -39,67 +39,4 @@ public function testTrimSkipNonStrings() $this->assertSame(1234, $event->getData()); } - - /** - * @dataProvider spaceProvider - */ - public function testTrimUtf8Separators($hex) - { - if (!function_exists('mb_convert_encoding')) { - $this->markTestSkipped('The "mb_convert_encoding" function is not available'); - } - - // Convert hexadecimal representation into binary - // H: hex string, high nibble first (UCS-2BE) - // *: repeat until end of string - $binary = pack('H*', $hex); - - // Convert UCS-2BE to UTF-8 - $symbol = mb_convert_encoding($binary, 'UTF-8', 'UCS-2BE'); - $symbol = $symbol."ab\ncd".$symbol; - - $form = $this->getMock('Symfony\Component\Form\Test\FormInterface'); - $event = new FormEvent($form, $symbol); - - $filter = new TrimListener(); - $filter->preSubmit($event); - - $this->assertSame("ab\ncd", $event->getData()); - } - - public function spaceProvider() - { - return array( - // separators - array('0020'), - array('00A0'), - array('1680'), -// array('180E'), - array('2000'), - array('2001'), - array('2002'), - array('2003'), - array('2004'), - array('2005'), - array('2006'), - array('2007'), - array('2008'), - array('2009'), - array('200A'), - array('2028'), - array('2029'), - array('202F'), - array('205F'), - array('3000'), - // controls - array('0009'), - array('000A'), - array('000B'), - array('000C'), - array('000D'), - array('0085'), - // zero width space -// array('200B'), - ); - } } diff --git a/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php b/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php new file mode 100644 index 0000000000000..7836852100b35 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php @@ -0,0 +1,72 @@ +assertEquals('Foo!', StringUtil::trim($data)); + } + + /** + * @dataProvider spaceProvider + */ + public function testTrimUtf8Separators($hex) + { + if (!function_exists('mb_convert_encoding')) { + $this->markTestSkipped('The "mb_convert_encoding" function is not available'); + } + + // Convert hexadecimal representation into binary + // H: hex string, high nibble first (UCS-2BE) + // *: repeat until end of string + $binary = pack('H*', $hex); + + // Convert UCS-2BE to UTF-8 + $symbol = mb_convert_encoding($binary, 'UTF-8', 'UCS-2BE'); + $symbol = $symbol."ab\ncd".$symbol; + + $this->assertSame("ab\ncd", StringUtil::trim($symbol)); + } + + public function spaceProvider() + { + return array( + // separators + array('0020'), + array('00A0'), + array('1680'), +// array('180E'), + array('2000'), + array('2001'), + array('2002'), + array('2003'), + array('2004'), + array('2005'), + array('2006'), + array('2007'), + array('2008'), + array('2009'), + array('200A'), + array('2028'), + array('2029'), + array('202F'), + array('205F'), + array('3000'), + // controls + array('0009'), + array('000A'), + array('000B'), + array('000C'), + array('000D'), + array('0085'), + // zero width space +// array('200B'), + ); + } +} diff --git a/src/Symfony/Component/Form/Util/StringUtil.php b/src/Symfony/Component/Form/Util/StringUtil.php new file mode 100644 index 0000000000000..2f51e74afcaac --- /dev/null +++ b/src/Symfony/Component/Form/Util/StringUtil.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Util; + +/** + * @author Issei Murasawa + * @author Bernhard Schussek + */ +class StringUtil +{ + /** + * This class should not be instantiated. + */ + private function __construct() + { + } + + /** + * Returns the trimmed data. + * + * @param string $string + * + * @return string + */ + public static function trim($string) + { + if (null !== $result = @preg_replace('/^[\pZ\p{Cc}]+|[\pZ\p{Cc}]+$/u', '', $string)) { + return $result; + } + + return trim($string); + } +} From f36075817ba1afd4c36d85dcb0c9ded417421f1b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 22 Jun 2015 19:39:18 +0200 Subject: [PATCH 04/12] [Debug] Allow throwing from __toString() with `return trigger_error($e, E_USER_ERROR);` --- src/Symfony/Component/Debug/ErrorHandler.php | 47 ++++++++++++++++++- .../Debug/Tests/ErrorHandlerTest.php | 27 +++++++++++ .../Debug/Tests/Fixtures/ToStringThrower.php | 24 ++++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Debug/Tests/Fixtures/ToStringThrower.php diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 2d8a9167b20b7..5af132ddc3260 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -100,6 +100,7 @@ class ErrorHandler private static $reservedMemory; private static $stackedErrors = array(); private static $stackedErrorLevels = array(); + private static $toStringException = null; /** * Same init value as thrownErrors. @@ -377,7 +378,10 @@ public function handleError($type, $message, $file, $line, array $context, array } if ($throw) { - if (($this->scopedErrors & $type) && class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) { + if (null !== self::$toStringException) { + $throw = self::$toStringException; + self::$toStringException = null; + } elseif (($this->scopedErrors & $type) && class_exists('Symfony\Component\Debug\Exception\ContextErrorException')) { // Checking for class existence is a work around for https://bugs.php.net/42098 $throw = new ContextErrorException($this->levels[$type].': '.$message, 0, $type, $file, $line, $context); } else { @@ -392,6 +396,47 @@ public function handleError($type, $message, $file, $line, array $context, array $throw->errorHandlerCanary = new ErrorHandlerCanary(); } + if (E_USER_ERROR & $type) { + $backtrace = $backtrace ?: $throw->getTrace(); + + for ($i = 1; isset($backtrace[$i]); ++$i) { + if (isset($backtrace[$i]['function'], $backtrace[$i]['type'], $backtrace[$i - 1]['function']) + && '__toString' === $backtrace[$i]['function'] + && '->' === $backtrace[$i]['type'] + && !isset($backtrace[$i - 1]['class']) + && ('trigger_error' === $backtrace[$i - 1]['function'] || 'user_error' === $backtrace[$i - 1]['function']) + ) { + // Here, we know trigger_error() has been called from __toString(). + // HHVM is fine with throwing from __toString() but PHP triggers a fatal error instead. + // A small convention allows working around the limitation: + // given a caught $e exception in __toString(), quitting the method with + // `return trigger_error($e, E_USER_ERROR);` allows this error handler + // to make $e get through the __toString() barrier. + + foreach ($context as $e) { + if (($e instanceof \Exception || $e instanceof \Throwable) && $e->__toString() === $message) { + if (1 === $i) { + // On HHVM + $throw = $e; + break; + } + self::$toStringException = $e; + + return true; + } + } + + if (1 < $i) { + // On PHP (not on HHVM), display the original error message instead of the default one. + $this->handleException($throw); + + // Stop the process by giving back the error to the native handler. + return false; + } + } + } + } + throw $throw; } diff --git a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php index 852976e0560db..1441397be6999 100644 --- a/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php @@ -268,6 +268,33 @@ public function testHandleError() } } + public function testHandleUserError() + { + try { + $handler = ErrorHandler::register(); + $handler->throwAt(0, true); + + $e = null; + $x = new \Exception('Foo'); + + try { + $f = new Fixtures\ToStringThrower($x); + $f .= ''; // Trigger $f->__toString() + } catch (\Exception $e) { + } + + $this->assertSame($x, $e); + + restore_error_handler(); + restore_exception_handler(); + } catch (\Exception $e) { + restore_error_handler(); + restore_exception_handler(); + + throw $e; + } + } + public function testHandleException() { try { diff --git a/src/Symfony/Component/Debug/Tests/Fixtures/ToStringThrower.php b/src/Symfony/Component/Debug/Tests/Fixtures/ToStringThrower.php new file mode 100644 index 0000000000000..40a5fb7f8c852 --- /dev/null +++ b/src/Symfony/Component/Debug/Tests/Fixtures/ToStringThrower.php @@ -0,0 +1,24 @@ +exception = $e; + } + + public function __toString() + { + try { + throw $this->exception; + } catch (\Exception $e) { + // Using user_error() here is on purpose so we do not forget + // that this alias also should work alongside with trigger_error(). + return user_error($e, E_USER_ERROR); + } + } +} From 6c4a676d099558ebaa1d59b119a1246adea9228c Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Sun, 14 Jun 2015 23:41:59 -0300 Subject: [PATCH 05/12] Add "shared" flag and deprecate scopes concept --- UPGRADE-2.8.md | 71 +++++++++++++++++++ .../LazyProxy/PhpDumper/ProxyDumper.php | 4 +- src/Symfony/Bridge/ProxyManager/composer.json | 2 +- .../Console/Descriptor/JsonDescriptor.php | 6 +- .../Console/Descriptor/MarkdownDescriptor.php | 6 +- .../Console/Descriptor/TextDescriptor.php | 7 +- .../Console/Descriptor/XmlDescriptor.php | 5 +- .../FrameworkBundle/Resources/config/test.xml | 6 +- .../Fixtures/Descriptor/builder_1_public.json | 1 + .../Fixtures/Descriptor/builder_1_public.md | 1 + .../Fixtures/Descriptor/builder_1_public.xml | 2 +- .../Descriptor/builder_1_services.json | 2 + .../Fixtures/Descriptor/builder_1_services.md | 2 + .../Descriptor/builder_1_services.xml | 4 +- .../Fixtures/Descriptor/builder_1_tag1.json | 1 + .../Fixtures/Descriptor/builder_1_tag1.md | 1 + .../Fixtures/Descriptor/builder_1_tag1.xml | 2 +- .../Fixtures/Descriptor/builder_1_tags.json | 2 + .../Fixtures/Descriptor/builder_1_tags.md | 2 + .../Fixtures/Descriptor/builder_1_tags.xml | 4 +- .../Fixtures/Descriptor/definition_1.json | 1 + .../Tests/Fixtures/Descriptor/definition_1.md | 1 + .../Fixtures/Descriptor/definition_1.txt | 1 + .../Fixtures/Descriptor/definition_1.xml | 2 +- .../Fixtures/Descriptor/definition_2.json | 1 + .../Tests/Fixtures/Descriptor/definition_2.md | 1 + .../Fixtures/Descriptor/definition_2.txt | 1 + .../Fixtures/Descriptor/definition_2.xml | 2 +- ...acy_synchronized_service_definition_1.json | 1 + ...egacy_synchronized_service_definition_1.md | 1 + ...gacy_synchronized_service_definition_1.txt | 1 + ...gacy_synchronized_service_definition_1.xml | 2 +- ...acy_synchronized_service_definition_2.json | 1 + ...egacy_synchronized_service_definition_2.md | 1 + ...gacy_synchronized_service_definition_2.txt | 1 + ...gacy_synchronized_service_definition_2.xml | 2 +- .../Form/UserLoginFormType.php | 12 ++-- .../Functional/app/CsrfFormLogin/config.yml | 3 +- .../Bundle/SecurityBundle/composer.json | 2 +- .../WebProfilerExtensionTest.php | 4 -- .../DependencyInjection/CHANGELOG.md | 2 + .../Compiler/CheckDefinitionValidityPass.php | 8 ++- .../Compiler/CheckReferenceValidityPass.php | 10 +-- .../Compiler/InlineServiceDefinitionsPass.php | 6 +- .../ResolveDefinitionTemplatesPass.php | 2 +- .../ResolveReferencesToAliasesPass.php | 2 +- .../DependencyInjection/Container.php | 33 +++++++++ .../DependencyInjection/ContainerBuilder.php | 20 +++++- .../ContainerInterface.php | 12 ++++ .../DependencyInjection/Definition.php | 51 ++++++++++++- .../Dumper/GraphvizDumper.php | 4 +- .../DependencyInjection/Dumper/PhpDumper.php | 16 ++--- .../DependencyInjection/Dumper/XmlDumper.php | 7 +- .../DependencyInjection/Dumper/YamlDumper.php | 8 ++- .../Loader/XmlFileLoader.php | 12 +++- .../Loader/YamlFileLoader.php | 9 ++- .../schema/dic/services/services-1.0.xsd | 1 + .../DependencyInjection/Reference.php | 10 ++- .../Component/DependencyInjection/Scope.php | 2 + .../DependencyInjection/ScopeInterface.php | 2 + .../CheckDefinitionValidityPassTest.php | 13 ++++ .../CheckReferenceValidityPassTest.php | 8 +++ .../InlineServiceDefinitionsPassTest.php | 58 +++++++++++++++ .../ResolveDefinitionTemplatesPassTest.php | 3 + .../ResolveInvalidReferencesPassTest.php | 3 + .../Tests/ContainerBuilderTest.php | 15 +++- .../Tests/ContainerTest.php | 46 ++++++++++-- .../Tests/DefinitionTest.php | 13 ++++ .../Tests/Dumper/GraphvizDumperTest.php | 5 +- .../Tests/Fixtures/containers/container9.php | 4 +- ...container18.php => legacy-container18.php} | 0 .../Fixtures/containers/legacy-container9.php | 5 ++ .../Fixtures/graphviz/legacy-services9.dot | 1 + .../Tests/Fixtures/xml/legacy-services6.xml | 3 + .../Tests/Fixtures/xml/legacy-services9.xml | 2 + .../Tests/Fixtures/xml/services6.xml | 4 +- .../Tests/Fixtures/xml/services9.xml | 2 +- .../Tests/Fixtures/yaml/legacy-services6.yml | 3 + .../Tests/Fixtures/yaml/legacy-services9.yml | 4 ++ .../Tests/Fixtures/yaml/services6.yml | 4 +- .../Tests/Fixtures/yaml/services9.yml | 2 +- .../Tests/Loader/XmlFileLoaderTest.php | 7 +- .../Tests/Loader/YamlFileLoaderTest.php | 7 +- .../ContainerAwareEventDispatcherTest.php | 4 ++ 84 files changed, 515 insertions(+), 90 deletions(-) rename src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/{container18.php => legacy-container18.php} (100%) diff --git a/UPGRADE-2.8.md b/UPGRADE-2.8.md index a58bb1834fe3e..966f1f4711132 100644 --- a/UPGRADE-2.8.md +++ b/UPGRADE-2.8.md @@ -65,3 +65,74 @@ Translator $messages = array_replace_recursive($catalogue->all(), $messages); } ``` + +DependencyInjection +------------------- + + * The concept of scopes were deprecated, the deprecated methods are: + + - `Symfony\Component\DependencyInjection\ContainerBuilder::getScopes()` + - `Symfony\Component\DependencyInjection\ContainerBuilder::getScopeChildren()` + - `Symfony\Component\DependencyInjection\ContainerInterface::enterScope()` + - `Symfony\Component\DependencyInjection\ContainerInterface::leaveScope()` + - `Symfony\Component\DependencyInjection\ContainerInterface::addScope()` + - `Symfony\Component\DependencyInjection\ContainerInterface::hasScope()` + - `Symfony\Component\DependencyInjection\ContainerInterface::isScopeActive()` + - `Symfony\Component\DependencyInjection\Definition::setScope()` + - `Symfony\Component\DependencyInjection\Definition::getScope()` + - `Symfony\Component\DependencyInjection\Reference::isStrict()` + + Also, the `$scope` and `$strict` parameters of `Symfony\Component\DependencyInjection\ContainerInterface::set()` and `Symfony\Component\DependencyInjection\Reference` respectively were deprecated. + + * A new `shared` flag has been added to the service definition + in replacement of the `prototype` scope. + + Before: + + ```php + use Symfony\Component\DependencyInjection\ContainerBuilder; + + $container = new ContainerBuilder(); + $container + ->register('foo', 'stdClass') + ->setScope(ContainerBuilder::SCOPE_PROTOTYPE) + ; + ``` + + ```yml + services: + foo: + class: stdClass + scope: prototype + ``` + + ```xml + + + + ``` + + After: + + ```php + use Symfony\Component\DependencyInjection\ContainerBuilder; + + $container = new ContainerBuilder(); + $container + ->register('foo', 'stdClass') + ->setShared(false) + ; + ``` + + ```yml + services: + foo: + class: stdClass + shared: false + ``` + + ```xml + + + + ``` diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index bba5055d0085d..076484567aae6 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -68,9 +68,9 @@ public function getProxyFactoryCode(Definition $definition, $id) { $instantiation = 'return'; - if (ContainerInterface::SCOPE_CONTAINER === $definition->getScope()) { + if ($definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) { $instantiation .= " \$this->services['$id'] ="; - } elseif (ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { + } elseif ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) { $instantiation .= " \$this->services['$id'] = \$this->scopedServices['$scope']['$id'] ="; } diff --git a/src/Symfony/Bridge/ProxyManager/composer.json b/src/Symfony/Bridge/ProxyManager/composer.json index 1e0209760eb0f..b37bf7b875759 100644 --- a/src/Symfony/Bridge/ProxyManager/composer.json +++ b/src/Symfony/Bridge/ProxyManager/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=5.3.9", - "symfony/dependency-injection": "~2.3|~3.0.0", + "symfony/dependency-injection": "~2.8|~3.0.0", "ocramius/proxy-manager": "~0.4|~1.0" }, "require-dev": { diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 5981a700c77a1..57780d2e52fd3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -213,12 +213,16 @@ private function getContainerDefinitionData(Definition $definition, $omitTags = { $data = array( 'class' => (string) $definition->getClass(), - 'scope' => $definition->getScope(), + 'scope' => $definition->getScope(false), 'public' => $definition->isPublic(), 'synthetic' => $definition->isSynthetic(), 'lazy' => $definition->isLazy(), ); + if (method_exists($definition, 'isShared')) { + $data['shared'] = $definition->isShared(); + } + if (method_exists($definition, 'isSynchronized')) { $data['synchronized'] = $definition->isSynchronized(false); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php index 8231c874779d3..8f5437146bb57 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php @@ -179,12 +179,16 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o protected function describeContainerDefinition(Definition $definition, array $options = array()) { $output = '- Class: `'.$definition->getClass().'`' - ."\n".'- Scope: `'.$definition->getScope().'`' + ."\n".'- Scope: `'.$definition->getScope(false).'`' ."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no') ."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no') ."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no') ; + if (method_exists($definition, 'isShared')) { + $output .= "\n".'- Shared: '.($definition->isShared() ? 'yes' : 'no'); + } + if (method_exists($definition, 'isSynchronized')) { $output .= "\n".'- Synchronized: '.($definition->isSynchronized(false) ? 'yes' : 'no'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php index 6916832060773..024da4d3b94c0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php @@ -174,7 +174,7 @@ protected function describeContainerServices(ContainerBuilder $builder, array $o $serviceIds = isset($options['tag']) && $options['tag'] ? array_keys($builder->findTaggedServiceIds($options['tag'])) : $builder->getServiceIds(); $maxTags = array(); - foreach ($serviceIds as $key => $serviceId) { + foreach ($serviceIds as $key => $serviceId) { $definition = $this->resolveServiceDefinition($builder, $serviceId); if ($definition instanceof Definition) { // filter out private services unless shown explicitly @@ -261,10 +261,13 @@ protected function describeContainerDefinition(Definition $definition, array $op $description[] = 'Tags -'; } - $description[] = sprintf('Scope %s', $definition->getScope()); + $description[] = sprintf('Scope %s', $definition->getScope(false)); $description[] = sprintf('Public %s', $definition->isPublic() ? 'yes' : 'no'); $description[] = sprintf('Synthetic %s', $definition->isSynthetic() ? 'yes' : 'no'); $description[] = sprintf('Lazy %s', $definition->isLazy() ? 'yes' : 'no'); + if (method_exists($definition, 'isShared')) { + $description[] = sprintf('Shared %s', $definition->isShared() ? 'yes' : 'no'); + } if (method_exists($definition, 'isSynchronized')) { $description[] = sprintf('Synchronized %s', $definition->isSynchronized(false) ? 'yes' : 'no'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php index e62c71a2a018e..c9e6f7eb731a3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php @@ -362,10 +362,13 @@ private function getContainerDefinitionDocument(Definition $definition, $id = nu } } - $serviceXML->setAttribute('scope', $definition->getScope()); + $serviceXML->setAttribute('scope', $definition->getScope(false)); $serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false'); $serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false'); $serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false'); + if (method_exists($definition, 'isShared')) { + $serviceXML->setAttribute('shared', $definition->isShared() ? 'true' : 'false'); + } if (method_exists($definition, 'isSynchronized')) { $serviceXML->setAttribute('synchronized', $definition->isSynchronized(false) ? 'true' : 'false'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml index 4e609a06e5d95..428ba0c8ee48a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml @@ -13,16 +13,16 @@ - + %test.client.parameters% - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json index 047f4e8c16a48..9be35dad0705e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json @@ -6,6 +6,7 @@ "public": true, "synthetic": false, "lazy": true, + "shared": true, "synchronized": false, "abstract": true, "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md index 1c3b958bd92ca..de404d24d0f59 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.md @@ -12,6 +12,7 @@ definition_1 - Public: yes - Synthetic: no - Lazy: yes +- Shared: yes - Synchronized: no - Abstract: yes - Factory Class: `Full\Qualified\FactoryClass` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml index b21190dc7983e..59a1e85c6bb8a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.xml @@ -2,7 +2,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json index 3397fd67acd6e..c76d13ee4234d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json @@ -6,6 +6,7 @@ "public": true, "synthetic": false, "lazy": true, + "shared": true, "synchronized": false, "abstract": true, "file": null, @@ -21,6 +22,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md index b3018b80b7f3b..3a3de41c409e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.md @@ -12,6 +12,7 @@ definition_1 - Public: yes - Synthetic: no - Lazy: yes +- Shared: yes - Synchronized: no - Abstract: yes - Factory Class: `Full\Qualified\FactoryClass` @@ -25,6 +26,7 @@ definition_2 - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml index 7aecc4f629e7f..5ceee2772a993 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.xml @@ -2,10 +2,10 @@ - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json index 53bf114e81e04..40a3da00963af 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json @@ -6,6 +6,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md index 56a2c390779aa..c0d4f11e33261 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.md @@ -12,6 +12,7 @@ definition_2 - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml index d6ac0b750b169..51bb9c254f545 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.xml @@ -1,6 +1,6 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json index 3837b95cb89e9..6844d2d18076b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json @@ -6,6 +6,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", @@ -20,6 +21,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md index 6577037f9c00f..551c9cb24b298 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.md @@ -12,6 +12,7 @@ definition_2 - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` @@ -30,6 +31,7 @@ definition_2 - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml index be9d2f015bd2c..01f324860885f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.xml @@ -1,12 +1,12 @@ - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json index 8de781dfc45a5..92f1300b4bd51 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json @@ -4,6 +4,7 @@ "public": true, "synthetic": false, "lazy": true, + "shared": true, "synchronized": false, "abstract": true, "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md index 68d3569732c61..6c18a6c2bbf82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.md @@ -3,6 +3,7 @@ - Public: yes - Synthetic: no - Lazy: yes +- Shared: yes - Synchronized: no - Abstract: yes - Factory Class: `Full\Qualified\FactoryClass` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt index af495497dd35d..4c37faccf29ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt @@ -5,6 +5,7 @@ Public yes Synthetic no Lazy yes +Shared yes Synchronized no Abstract yes Factory Class Full\Qualified\FactoryClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml index 92a9bbd70bd30..ec8a8cefa9e47 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.xml @@ -1,4 +1,4 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json index 9d58434c17e1b..22a094928a48a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json @@ -4,6 +4,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md index 6b2f14651d300..8668587994270 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.md @@ -3,6 +3,7 @@ - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt index 28a00d583b090..62fc7d2dc6c33 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt @@ -8,6 +8,7 @@ Public no Synthetic yes Lazy no +Shared yes Synchronized no Abstract no Required File /path/to/file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml index f128e522e5990..ce9b1d05220c6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.xml @@ -1,5 +1,5 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json index 6372d9e5b56df..b7a5dec87df72 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.json @@ -4,6 +4,7 @@ "public": true, "synthetic": false, "lazy": true, + "shared": true, "synchronized": true, "abstract": true, "file": null, diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md index d9832a1511ab2..f527ab9ff8749 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.md @@ -3,6 +3,7 @@ - Public: yes - Synthetic: no - Lazy: yes +- Shared: yes - Synchronized: yes - Abstract: yes - Factory Class: `Full\Qualified\FactoryClass` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt index 3d9cbb2077c3b..09340efcf5d82 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.txt @@ -5,6 +5,7 @@ Public yes Synthetic no Lazy yes +Shared yes Synchronized yes Abstract yes Factory Class Full\Qualified\FactoryClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.xml index 75d0820244579..6088d9a21b5a8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_1.xml @@ -1,2 +1,2 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json index 278a5bfed413b..bb0f5685f36a6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.json @@ -4,6 +4,7 @@ "public": false, "synthetic": true, "lazy": false, + "shared": true, "synchronized": false, "abstract": false, "file": "\/path\/to\/file", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md index f552debbf18bc..43227638d88a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.md @@ -3,6 +3,7 @@ - Public: no - Synthetic: yes - Lazy: no +- Shared: yes - Synchronized: no - Abstract: no - File: `/path/to/file` diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt index 28a00d583b090..62fc7d2dc6c33 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.txt @@ -8,6 +8,7 @@ Public no Synthetic yes Lazy no +Shared yes Synchronized no Abstract no Required File /path/to/file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml index dd3e2e06d7174..7a2154487d1eb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/legacy_synchronized_service_definition_2.xml @@ -1,5 +1,5 @@ - + val1 diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php index d76d8fd629bba..04d41752c83ea 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Security; @@ -29,14 +29,14 @@ */ class UserLoginFormType extends AbstractType { - private $request; + private $requestStack; /** - * @param Request $request A request instance + * @param RequestStack $requestStack A RequestStack instance */ - public function __construct(Request $request) + public function __construct(RequestStack $requestStack) { - $this->request = $request; + $this->requestStack = $requestStack; } /** @@ -50,7 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('_target_path', 'hidden') ; - $request = $this->request; + $request = $this->requestStack->getCurrentRequest(); /* Note: since the Security component's form login listener intercepts * the POST request, this form will never really be bound to the diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml index e1e2b0e883933..2b97bd5a66384 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml @@ -4,9 +4,8 @@ imports: services: csrf_form_login.form.type: class: Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\CsrfFormLoginBundle\Form\UserLoginFormType - scope: request arguments: - - @request + - @request_stack tags: - { name: form.type, alias: user_login } diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 94847e822be59..0bab4dbcbbec6 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -29,7 +29,7 @@ "symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0", "symfony/form": "~2.7|~3.0.0", "symfony/framework-bundle": "~2.7|~3.0.0", - "symfony/http-foundation": "~2.3|~3.0.0", + "symfony/http-foundation": "~2.4|~3.0.0", "symfony/twig-bundle": "~2.7|~3.0.0", "symfony/twig-bridge": "~2.7|~3.0.0", "symfony/process": "~2.0,>=2.0.5|~3.0.0", diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php index 132315fd23c82..00d17cee42acd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php @@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\DependencyInjection\Scope; class WebProfilerExtensionTest extends TestCase { @@ -49,8 +48,6 @@ protected function setUp() $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $this->container = new ContainerBuilder(); - $this->container->addScope(new Scope('request')); - $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')); $this->container->register('twig', 'Twig_Environment'); $this->container->setParameter('kernel.bundles', array()); @@ -125,7 +122,6 @@ private function getDumpedContainer() eval('?>'.$dumper->dump(array('class' => $class))); $container = new $class(); - $container->enterScope('request'); $container->set('kernel', $this->kernel); return $container; diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 9f35827ecba37..7c4ff51e8cdd7 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -5,6 +5,8 @@ CHANGELOG ----- * allowed specifying a directory to recursively load all configuration files it contains + * deprecated the concept of scopes + * added `Definition::setShared()` and `Definition::isShared()` 2.7.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index 219e66313d13b..e54ee60abbcaf 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -25,6 +25,7 @@ * - non synthetic, non abstract services always have a class set * - synthetic services are always public * - synthetic services are always of non-prototype scope + * - shared services are always of non-prototype scope * * @author Johannes M. Schmitt */ @@ -46,10 +47,15 @@ public function process(ContainerBuilder $container) } // synthetic service has non-prototype scope - if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) { + if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) { throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id)); } + // shared service has non-prototype scope + if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) { + throw new RuntimeException(sprintf('A shared service ("%s") cannot be of scope "prototype".', $id)); + } + if ($definition->getFactory() && ($definition->getFactoryClass(false) || $definition->getFactoryService(false) || $definition->getFactoryMethod(false))) { throw new RuntimeException(sprintf('A service ("%s") can use either the old or the new factory syntax, not both.', $id)); } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php index 3d4988d2e6653..b4526edec84b4 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckReferenceValidityPass.php @@ -46,10 +46,10 @@ public function process(ContainerBuilder $container) { $this->container = $container; - $children = $this->container->getScopeChildren(); + $children = $this->container->getScopeChildren(false); $ancestors = array(); - $scopes = $this->container->getScopes(); + $scopes = $this->container->getScopes(false); foreach ($scopes as $name => $parent) { $ancestors[$name] = array($parent); @@ -65,7 +65,7 @@ public function process(ContainerBuilder $container) $this->currentId = $id; $this->currentDefinition = $definition; - $this->currentScope = $scope = $definition->getScope(); + $this->currentScope = $scope = $definition->getScope(false); if (ContainerInterface::SCOPE_CONTAINER === $scope) { $this->currentScopeChildren = array_keys($scopes); @@ -125,7 +125,7 @@ private function validateScope(Reference $reference, Definition $definition = nu return; } - if (!$reference->isStrict()) { + if (!$reference->isStrict(false)) { return; } @@ -133,7 +133,7 @@ private function validateScope(Reference $reference, Definition $definition = nu return; } - if ($this->currentScope === $scope = $definition->getScope()) { + if ($this->currentScope === $scope = $definition->getScope(false)) { return; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 026700d2263d6..c3c4ef5fd6540 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -92,7 +92,7 @@ private function inlineArguments(ContainerBuilder $container, array $arguments) if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) { $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId)); - if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) { + if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false)) { $arguments[$k] = $definition; } else { $arguments[$k] = clone $definition; @@ -119,7 +119,7 @@ private function inlineArguments(ContainerBuilder $container, array $arguments) */ private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition) { - if (ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) { + if (!$definition->isShared() || ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) { return true; } @@ -152,6 +152,6 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini return false; } - return $container->getDefinition(reset($ids))->getScope() === $definition->getScope(); + return $container->getDefinition(reset($ids))->getScope(false) === $definition->getScope(false); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php index 0efc6b500b5d4..daaee8159d488 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php @@ -153,7 +153,7 @@ private function resolveDefinition($id, DefinitionDecorator $definition) // these attributes are always taken from the child $def->setAbstract($definition->isAbstract()); - $def->setScope($definition->getScope()); + $def->setScope($definition->getScope(false), false); $def->setTags($definition->getTags()); // set new definition on container diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php index c90d76f48adf5..3111d7f0916a3 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php @@ -68,7 +68,7 @@ private function processArguments(array $arguments) $defId = $this->getDefinitionId($id = (string) $argument); if ($defId !== $id) { - $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict()); + $arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict(false)); } } } diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index f0db5de6bc4e6..2b9fc5f4877a7 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -180,6 +180,8 @@ public function setParameter($name, $value) * Setting a service to null resets the service: has() returns false and get() * behaves in the same way as if the service was never created. * + * Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0. + * * @param string $id The service identifier * @param object $service The service instance * @param string $scope The scope of the service @@ -191,6 +193,10 @@ public function setParameter($name, $value) */ public function set($id, $service, $scope = self::SCOPE_CONTAINER) { + if (!in_array($scope, array('container', 'request')) || ('request' === $scope && 'request' !== $id)) { + @trigger_error('The concept of container scopes is deprecated since version 2.8 and will be removed in 3.0. Omit the third parameter.', E_USER_DEPRECATED); + } + if (self::SCOPE_PROTOTYPE === $scope) { throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id)); } @@ -397,9 +403,15 @@ public function getServiceIds() * @throws InvalidArgumentException When the scope does not exist * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function enterScope($name) { + if ('request' !== $name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + if (!isset($this->scopes[$name])) { throw new InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name)); } @@ -445,9 +457,15 @@ public function enterScope($name) * @throws InvalidArgumentException if the scope is not active * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function leaveScope($name) { + if ('request' !== $name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + if (!isset($this->scopedServices[$name])) { throw new InvalidArgumentException(sprintf('The scope "%s" is not active.', $name)); } @@ -492,12 +510,17 @@ public function leaveScope($name) * @throws InvalidArgumentException * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function addScope(ScopeInterface $scope) { $name = $scope->getName(); $parentScope = $scope->getParentName(); + if ('request' !== $name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) { throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name)); } @@ -526,9 +549,15 @@ public function addScope(ScopeInterface $scope) * @return bool * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function hasScope($name) { + if ('request' !== $name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return isset($this->scopes[$name]); } @@ -542,9 +571,13 @@ public function hasScope($name) * @return bool * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function isScopeActive($name) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + return isset($this->scopedServices[$name]); } diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index e697814bb10fd..5ac89cde57317 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -358,9 +358,15 @@ public function getCompiler() * @return array An array of scopes * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ - public function getScopes() + public function getScopes($triggerDeprecationError = true) { + if ($triggerDeprecationError) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return $this->scopes; } @@ -370,15 +376,23 @@ public function getScopes() * @return array An array of scope children. * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ - public function getScopeChildren() + public function getScopeChildren($triggerDeprecationError = true) { + if ($triggerDeprecationError) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return $this->scopeChildren; } /** * Sets a service. * + * Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0. + * * @param string $id The service identifier * @param object $service The service instance * @param string $scope The scope @@ -1176,7 +1190,7 @@ private function callMethod($service, $call) */ private function shareService(Definition $definition, $service, $id) { - if (self::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { + if ($definition->isShared() && self::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) { if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) { throw new InactiveScopeException($id, $scope); } diff --git a/src/Symfony/Component/DependencyInjection/ContainerInterface.php b/src/Symfony/Component/DependencyInjection/ContainerInterface.php index 19e800b3144da..39683a6d66751 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerInterface.php +++ b/src/Symfony/Component/DependencyInjection/ContainerInterface.php @@ -34,6 +34,8 @@ interface ContainerInterface /** * Sets a service. * + * Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0. + * * @param string $id The service identifier * @param object $service The service instance * @param string $scope The scope of the service @@ -110,6 +112,8 @@ public function setParameter($name, $value); * @param string $name * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function enterScope($name); @@ -119,6 +123,8 @@ public function enterScope($name); * @param string $name * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function leaveScope($name); @@ -128,6 +134,8 @@ public function leaveScope($name); * @param ScopeInterface $scope * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function addScope(ScopeInterface $scope); @@ -139,6 +147,8 @@ public function addScope(ScopeInterface $scope); * @return bool * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function hasScope($name); @@ -152,6 +162,8 @@ public function hasScope($name); * @return bool * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ public function isScopeActive($name); } diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 71447fab12ae8..e68e8b3cb813c 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -29,6 +29,7 @@ class Definition private $factoryClass; private $factoryMethod; private $factoryService; + private $shared = true; private $scope = ContainerInterface::SCOPE_CONTAINER; private $properties = array(); private $calls = array(); @@ -94,6 +95,7 @@ public function getFactory() * @return Definition The current instance * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function setFactoryClass($factoryClass) @@ -111,6 +113,7 @@ public function setFactoryClass($factoryClass) * @return string|null The factory class name * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function getFactoryClass($triggerDeprecationError = true) @@ -130,6 +133,7 @@ public function getFactoryClass($triggerDeprecationError = true) * @return Definition The current instance * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function setFactoryMethod($factoryMethod) @@ -182,6 +186,7 @@ public function getDecoratedService() * @return string|null The factory method name * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function getFactoryMethod($triggerDeprecationError = true) @@ -201,6 +206,7 @@ public function getFactoryMethod($triggerDeprecationError = true) * @return Definition The current instance * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function setFactoryService($factoryService) @@ -218,6 +224,7 @@ public function setFactoryService($factoryService) * @return string|null The factory service id * * @api + * * @deprecated since version 2.6, to be removed in 3.0. */ public function getFactoryService($triggerDeprecationError = true) @@ -597,6 +604,34 @@ public function getFile() return $this->file; } + /** + * Sets if the service must be shared or not. + * + * @param bool $shared Whether the service must be shared or not + * + * @return Definition The current instance + * + * @api + */ + public function setShared($shared) + { + $this->shared = (bool) $shared; + + return $this; + } + + /** + * Whether this service is shared. + * + * @return bool + * + * @api + */ + public function isShared() + { + return $this->shared; + } + /** * Sets the scope of the service. * @@ -605,9 +640,15 @@ public function getFile() * @return Definition The current instance * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ - public function setScope($scope) + public function setScope($scope, $triggerDeprecationError = true) { + if ($triggerDeprecationError) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + $this->scope = $scope; return $this; @@ -619,9 +660,15 @@ public function setScope($scope) * @return string * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ - public function getScope() + public function getScope($triggerDeprecationError = true) { + if ($triggerDeprecationError) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return $this->scope; } diff --git a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php index 5f35a1e5bb116..70e19af52f55f 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php @@ -173,7 +173,7 @@ private function findNodes() } catch (ParameterNotFoundException $e) { } - $nodes[$id] = array('class' => str_replace('\\', '\\\\', $className), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted'))); + $nodes[$id] = array('class' => str_replace('\\', '\\\\', $className), 'attributes' => array_merge($this->options['node.definition'], array('style' => $definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false) ? 'filled' : 'dotted'))); $container->setDefinition($id, new Definition('stdClass')); } @@ -201,7 +201,7 @@ private function cloneContainer() $container->setDefinitions($this->container->getDefinitions()); $container->setAliases($this->container->getAliases()); $container->setResources($this->container->getResources()); - foreach ($this->container->getScopes() as $scope => $parentScope) { + foreach ($this->container->getScopes(false) as $scope => $parentScope) { $container->addScope(new Scope($scope, $parentScope)); } foreach ($this->container->getExtensions() as $extension) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 9c2b6dd54d3ca..d3347a03c41cf 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -382,9 +382,9 @@ private function addServiceInstance($id, $definition) $isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition); $instantiation = ''; - if (!$isProxyCandidate && ContainerInterface::SCOPE_CONTAINER === $definition->getScope()) { + if (!$isProxyCandidate && $definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) { $instantiation = "\$this->services['$id'] = ".($simple ? '' : '$instance'); - } elseif (!$isProxyCandidate && ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope()) { + } elseif (!$isProxyCandidate && $definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) { $instantiation = "\$this->services['$id'] = \$this->scopedServices['$scope']['$id'] = ".($simple ? '' : '$instance'); } elseif (!$simple) { $instantiation = '$instance'; @@ -578,7 +578,7 @@ private function addService($id, $definition) $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(false), $definition->getFactoryMethod(false)); } - $scope = $definition->getScope(); + $scope = $definition->getScope(false); if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) { if ($return && 0 === strpos($return[count($return) - 1], '@return')) { $return[] = ''; @@ -589,7 +589,7 @@ private function addService($id, $definition) $return = implode("\n * ", $return); $doc = ''; - if (ContainerInterface::SCOPE_PROTOTYPE !== $scope) { + if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) { $doc .= <<container->getScopes()) > 0) { + if (count($scopes = $this->container->getScopes(false)) > 0) { $code .= "\n"; $code .= " \$this->scopes = ".$this->dumpValue($scopes).";\n"; - $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren()).";\n"; + $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren(false)).";\n"; } $code .= $this->addMethodMap(); @@ -907,9 +907,9 @@ public function __construct() EOF; $code .= "\n"; - if (count($scopes = $this->container->getScopes()) > 0) { + if (count($scopes = $this->container->getScopes(false)) > 0) { $code .= " \$this->scopes = ".$this->dumpValue($scopes).";\n"; - $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren()).";\n"; + $code .= " \$this->scopeChildren = ".$this->dumpValue($this->container->getScopeChildren(false)).";\n"; } else { $code .= " \$this->scopes = array();\n"; $code .= " \$this->scopeChildren = array();\n"; diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index 40486c4595543..1f9183f418de8 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -126,7 +126,10 @@ private function addService($definition, $id, \DOMElement $parent) if ($definition->getFactoryService(false)) { $service->setAttribute('factory-service', $definition->getFactoryService(false)); } - if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope()) { + if (!$definition->isShared()) { + $service->setAttribute('shared', 'false'); + } + if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) { $service->setAttribute('scope', $scope); } if (!$definition->isPublic()) { @@ -283,7 +286,7 @@ private function convertParameters($parameters, $type, \DOMElement $parent, $key } elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) { $element->setAttribute('on-invalid', 'ignore'); } - if (!$value->isStrict()) { + if (!$value->isStrict(false)) { $element->setAttribute('strict', 'false'); } } elseif ($value instanceof Definition) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index 832929cd049c0..e1a5709dd32e2 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -128,7 +128,11 @@ private function addService($id, $definition) $code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12)); } - if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope()) { + if (!$definition->isShared()) { + $code .= " shared: false\n"; + } + + if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) { $code .= sprintf(" scope: %s\n", $scope); } @@ -212,7 +216,7 @@ private function addParameters() } /** - * Dumps callable to YAML format + * Dumps callable to YAML format. * * @param callable $callable * diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 523c01cea4938..93bb3a139d056 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -148,7 +148,7 @@ private function parseDefinition(\DOMElement $service, $file) $definition = new Definition(); } - foreach (array('class', 'scope', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) { + foreach (array('class', 'shared', 'public', 'factory-class', 'factory-method', 'factory-service', 'synthetic', 'lazy', 'abstract') as $key) { if ($value = $service->getAttribute($key)) { if (in_array($key, array('factory-class', 'factory-method', 'factory-service'))) { @trigger_error(sprintf('The "%s" attribute in file "%s" is deprecated since version 2.6 and will be removed in 3.0. Use the "factory" element instead.', $key, $file), E_USER_DEPRECATED); @@ -158,6 +158,16 @@ private function parseDefinition(\DOMElement $service, $file) } } + if ($value = $service->getAttribute('scope')) { + $triggerDeprecation = 'request' !== (string) $service->getAttribute('id'); + + if ($triggerDeprecation) { + @trigger_error(sprintf('The "scope" attribute in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $file), E_USER_DEPRECATED); + } + + $definition->setScope(XmlUtils::phpize($value), false); + } + if ($value = $service->getAttribute('synchronized')) { $triggerDeprecation = 'request' !== (string) $service->getAttribute('id'); diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index e10cfe2a4bce3..c0239c2f90bfa 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -163,8 +163,15 @@ private function parseDefinition($id, $service, $file) $definition->setClass($service['class']); } + if (isset($service['shared'])) { + $definition->setShared($service['shared']); + } + if (isset($service['scope'])) { - $definition->setScope($service['scope']); + if ('request' !== $id) { + @trigger_error(sprintf('The "scope" key in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $file), E_USER_DEPRECATED); + } + $definition->setScope($service['scope'], false); } if (isset($service['synthetic'])) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd index ac2cba7a80ce0..11f869c04ac22 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd +++ b/src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd @@ -87,6 +87,7 @@ + diff --git a/src/Symfony/Component/DependencyInjection/Reference.php b/src/Symfony/Component/DependencyInjection/Reference.php index 88084880f80c4..6bb117abb67cf 100644 --- a/src/Symfony/Component/DependencyInjection/Reference.php +++ b/src/Symfony/Component/DependencyInjection/Reference.php @@ -27,6 +27,8 @@ class Reference /** * Constructor. * + * Note: The $strict parameter is deprecated since version 2.8 and will be removed in 3.0. + * * @param string $id The service identifier * @param int $invalidBehavior The behavior when the service does not exist * @param bool $strict Sets how this reference is validated @@ -64,9 +66,15 @@ public function getInvalidBehavior() * Returns true when this Reference is strict. * * @return bool + * + * @deprecated since version 2.8, to be removed in 3.0. */ - public function isStrict() + public function isStrict($triggerDeprecationError = true) { + if ($triggerDeprecationError) { + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return $this->strict; } } diff --git a/src/Symfony/Component/DependencyInjection/Scope.php b/src/Symfony/Component/DependencyInjection/Scope.php index 161229e44bc58..c97c887584744 100644 --- a/src/Symfony/Component/DependencyInjection/Scope.php +++ b/src/Symfony/Component/DependencyInjection/Scope.php @@ -17,6 +17,8 @@ * @author Johannes M. Schmitt * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ class Scope implements ScopeInterface { diff --git a/src/Symfony/Component/DependencyInjection/ScopeInterface.php b/src/Symfony/Component/DependencyInjection/ScopeInterface.php index 81ac67cc4d57e..69d57685a248d 100644 --- a/src/Symfony/Component/DependencyInjection/ScopeInterface.php +++ b/src/Symfony/Component/DependencyInjection/ScopeInterface.php @@ -17,6 +17,8 @@ * @author Johannes M. Schmitt * * @api + * + * @deprecated since version 2.8, to be removed in 3.0. */ interface ScopeInterface { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php index 4e8efdc8b4fa3..e0639825f009f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckDefinitionValidityPassTest.php @@ -30,6 +30,7 @@ public function testProcessDetectsSyntheticNonPublicDefinitions() /** * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @group legacy */ public function testProcessDetectsSyntheticPrototypeDefinitions() { @@ -39,6 +40,18 @@ public function testProcessDetectsSyntheticPrototypeDefinitions() $this->process($container); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException + * @group legacy + */ + public function testProcessDetectsSharedPrototypeDefinitions() + { + $container = new ContainerBuilder(); + $container->register('a')->setShared(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE); + + $this->process($container); + } + /** * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php index cd4448a96abf4..45cf279e374a8 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckReferenceValidityPassTest.php @@ -19,6 +19,9 @@ class CheckReferenceValidityPassTest extends \PHPUnit_Framework_TestCase { + /** + * @group legacy + */ public function testProcessIgnoresScopeWideningIfNonStrictReference() { $container = new ContainerBuilder(); @@ -30,6 +33,7 @@ public function testProcessIgnoresScopeWideningIfNonStrictReference() /** * @expectedException \RuntimeException + * @group legacy */ public function testProcessDetectsScopeWidening() { @@ -40,6 +44,9 @@ public function testProcessDetectsScopeWidening() $this->process($container); } + /** + * @group legacy + */ public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict() { $container = new ContainerBuilder(); @@ -54,6 +61,7 @@ public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict() /** * @expectedException \RuntimeException + * @group legacy */ public function testProcessDetectsCrossScopeHierarchyReference() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 590ca4cfae2f9..038843416327c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -41,6 +41,29 @@ public function testProcess() $this->assertSame($container->getDefinition('inlinable.service'), $arguments[0]); } + public function testProcessDoesNotInlinesWhenAliasedServiceIsShared() + { + $container = new ContainerBuilder(); + $container + ->register('foo') + ->setPublic(false) + ; + $container->setAlias('moo', 'foo'); + + $container + ->register('service') + ->setArguments(array($ref = new Reference('foo'))) + ; + + $this->process($container); + + $arguments = $container->getDefinition('service')->getArguments(); + $this->assertSame($ref, $arguments[0]); + } + + /** + * @group legacy + */ public function testProcessDoesNotInlineWhenAliasedServiceIsNotOfPrototypeScope() { $container = new ContainerBuilder(); @@ -61,6 +84,38 @@ public function testProcessDoesNotInlineWhenAliasedServiceIsNotOfPrototypeScope( $this->assertSame($ref, $arguments[0]); } + public function testProcessDoesInlineNonSharedService() + { + $container = new ContainerBuilder(); + $container + ->register('foo') + ->setShared(false) + ; + $container + ->register('bar') + ->setPublic(false) + ->setShared(false) + ; + $container->setAlias('moo', 'bar'); + + $container + ->register('service') + ->setArguments(array(new Reference('foo'), $ref = new Reference('moo'), new Reference('bar'))) + ; + + $this->process($container); + + $arguments = $container->getDefinition('service')->getArguments(); + $this->assertEquals($container->getDefinition('foo'), $arguments[0]); + $this->assertNotSame($container->getDefinition('foo'), $arguments[0]); + $this->assertSame($ref, $arguments[1]); + $this->assertEquals($container->getDefinition('bar'), $arguments[2]); + $this->assertNotSame($container->getDefinition('bar'), $arguments[2]); + } + + /** + * @group legacy + */ public function testProcessDoesInlineServiceOfPrototypeScope() { $container = new ContainerBuilder(); @@ -188,6 +243,9 @@ public function testProcessDoesNotInlineReferenceWhenUsedByInlineFactory() $this->assertSame($ref, $args[0]); } + /** + * @group legacy + */ public function testProcessInlinesOnlyIfSameScope() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php index fb2bb5fca3055..0060b35e9a595 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php @@ -79,6 +79,9 @@ public function testProcessDoesNotCopyAbstract() $this->assertFalse($def->isAbstract()); } + /** + * @group legacy + */ public function testProcessDoesNotCopyScope() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php index 72058868d44ea..498baf82fc986 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInvalidReferencesPassTest.php @@ -61,6 +61,9 @@ public function testProcessRemovesPropertiesOnInvalid() $this->assertEquals(array(), $def->getProperties()); } + /** + * @group legacy + */ public function testStrictFlagIsPreserved() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 8155e0b7c6b87..7e5564c92b0ea 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -117,10 +117,21 @@ public function testGet() $this->assertEquals('Circular reference detected for service "baz", path: "baz".', $e->getMessage(), '->get() throws a LogicException if the service has a circular reference to itself'); } - $builder->register('foobar', 'stdClass')->setScope('container'); $this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared'); } + /** + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::get + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::setShared + */ + public function testNonSharedServicesReturnsDifferentInstances() + { + $builder = new ContainerBuilder(); + $builder->register('bar', 'stdClass')->setShared(false); + + $this->assertNotSame($builder->get('bar'), $builder->get('bar')); + } + /** * @covers \Symfony\Component\DependencyInjection\ContainerBuilder::get * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException @@ -143,6 +154,7 @@ public function testGetUnsetLoadingServiceWhenCreateServiceThrowsAnException() /** * @covers Symfony\Component\DependencyInjection\ContainerBuilder::get + * @group legacy */ public function testGetReturnsNullOnInactiveScope() { @@ -154,6 +166,7 @@ public function testGetReturnsNullOnInactiveScope() /** * @covers Symfony\Component\DependencyInjection\ContainerBuilder::get + * @group legacy */ public function testGetReturnsNullOnInactiveScopeWhenServiceIsCreatedByAMethod() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index dd8358e929962..603269ccc6962 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -171,6 +171,7 @@ public function testSetWithNullResetTheService() /** * @expectedException \InvalidArgumentException + * @group legacy */ public function testSetDoesNotAllowPrototypeScope() { @@ -180,6 +181,7 @@ public function testSetDoesNotAllowPrototypeScope() /** * @expectedException \RuntimeException + * @group legacy */ public function testSetDoesNotAllowInactiveScope() { @@ -188,6 +190,9 @@ public function testSetDoesNotAllowInactiveScope() $c->set('foo', new \stdClass(), 'foo'); } + /** + * @group legacy + */ public function testSetAlsoSetsScopedService() { $c = new Container(); @@ -200,6 +205,9 @@ public function testSetAlsoSetsScopedService() $this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped service'); } + /** + * @group legacy + */ public function testSetAlsoCallsSynchronizeService() { $c = new ProjectServiceContainer(); @@ -273,6 +281,7 @@ public function testGetCircularReference() /** * @covers Symfony\Component\DependencyInjection\Container::get + * @group legacy */ public function testGetReturnsNullOnInactiveScope() { @@ -311,6 +320,9 @@ public function testInitialized() $this->assertTrue($sc->initialized('alias'), '->initialized() returns true for alias if aliased service is initialized'); } + /** + * @group legacy + */ public function testEnterLeaveCurrentScope() { $container = new ProjectServiceContainer(); @@ -336,6 +348,9 @@ public function testEnterLeaveCurrentScope() $this->assertSame($scopedFoo1, $scopedFoo3); } + /** + * @group legacy + */ public function testEnterLeaveScopeWithChildScopes() { $container = new Container(); @@ -366,6 +381,9 @@ public function testEnterLeaveScopeWithChildScopes() $this->assertFalse($container->has('a')); } + /** + * @group legacy + */ public function testEnterScopeRecursivelyWithInactiveChildScopes() { $container = new Container(); @@ -407,6 +425,9 @@ public function testEnterScopeRecursivelyWithInactiveChildScopes() $this->assertTrue($container->has('a')); } + /** + * @group legacy + */ public function testEnterChildScopeRecursively() { $container = new Container(); @@ -444,6 +465,7 @@ public function testEnterChildScopeRecursively() /** * @expectedException \InvalidArgumentException + * @group legacy */ public function testEnterScopeNotAdded() { @@ -453,6 +475,7 @@ public function testEnterScopeNotAdded() /** * @expectedException \RuntimeException + * @group legacy */ public function testEnterScopeDoesNotAllowInactiveParentScope() { @@ -462,6 +485,9 @@ public function testEnterScopeDoesNotAllowInactiveParentScope() $container->enterScope('bar'); } + /** + * @group legacy + */ public function testLeaveScopeNotActive() { $container = new Container(); @@ -486,7 +512,8 @@ public function testLeaveScopeNotActive() /** * @expectedException \InvalidArgumentException - * @dataProvider getBuiltInScopes + * @dataProvider getLegacyBuiltInScopes + * @group legacy */ public function testAddScopeDoesNotAllowBuiltInScopes($scope) { @@ -496,6 +523,7 @@ public function testAddScopeDoesNotAllowBuiltInScopes($scope) /** * @expectedException \InvalidArgumentException + * @group legacy */ public function testAddScopeDoesNotAllowExistingScope() { @@ -506,7 +534,8 @@ public function testAddScopeDoesNotAllowExistingScope() /** * @expectedException \InvalidArgumentException - * @dataProvider getInvalidParentScopes + * @dataProvider getLegacyInvalidParentScopes + * @group legacy */ public function testAddScopeDoesNotAllowInvalidParentScope($scope) { @@ -514,6 +543,9 @@ public function testAddScopeDoesNotAllowInvalidParentScope($scope) $c->addScope(new Scope('foo', $scope)); } + /** + * @group legacy + */ public function testAddScope() { $c = new Container(); @@ -529,6 +561,9 @@ public function testAddScope() $this->assertSame(array('foo' => array('bar', 'baz'), 'bar' => array('baz'), 'baz' => array()), $this->getField($c, 'scopeChildren')); } + /** + * @group legacy + */ public function testHasScope() { $c = new Container(); @@ -577,6 +612,9 @@ public function testGetThrowsExceptionOnServiceConfiguration() $this->assertFalse($c->initialized('throws_exception_on_service_configuration')); } + /** + * @group legacy + */ public function testIsScopeActive() { $c = new Container(); @@ -593,7 +631,7 @@ public function testIsScopeActive() $this->assertFalse($c->isScopeActive('foo')); } - public function getInvalidParentScopes() + public function getLegacyInvalidParentScopes() { return array( array(ContainerInterface::SCOPE_PROTOTYPE), @@ -601,7 +639,7 @@ public function getInvalidParentScopes() ); } - public function getBuiltInScopes() + public function getLegacyBuiltInScopes() { return array( array(ContainerInterface::SCOPE_CONTAINER), diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index b501f11839017..4bac0e2a0baf2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -127,9 +127,22 @@ public function testSetGetFile() $this->assertEquals('foo', $def->getFile(), '->getFile() returns the file to include'); } + /** + * @covers Symfony\Component\DependencyInjection\Definition::setShared + * @covers Symfony\Component\DependencyInjection\Definition::isShared + */ + public function testSetIsShared() + { + $def = new Definition('stdClass'); + $this->assertTrue($def->isShared(), '->isShared() returns true by default'); + $this->assertSame($def, $def->setShared(false), '->setShared() implements a fluent interface'); + $this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared'); + } + /** * @covers Symfony\Component\DependencyInjection\Definition::setScope * @covers Symfony\Component\DependencyInjection\Definition::getScope + * @group legacy */ public function testSetGetScope() { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php index 5da11359fa8b5..1b75712b7952e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php @@ -81,9 +81,12 @@ public function testDumpWithUnresolvedParameter() $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services'); } + /** + * @group legacy + */ public function testDumpWithScopes() { - $container = include self::$fixturesPath.'/containers/container18.php'; + $container = include self::$fixturesPath.'/containers/legacy-container18.php'; $dumper = new GraphvizDumper($container); $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services'); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index e97a2dda69ccb..d9b65a43fe261 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -28,12 +28,11 @@ $container ->register('bar', 'Bar\FooClass') ->setArguments(array('foo', new Reference('foo.baz'), new Parameter('foo_bar'))) - ->setScope('container') ->setConfigurator(array(new Reference('foo.baz'), 'configure')) ; $container ->register('foo_bar', '%foo_class%') - ->setScope('prototype') + ->setShared(false) ; $container->getParameterBag()->clear(); $container->getParameterBag()->add(array( @@ -93,7 +92,6 @@ $container ->register('new_factory', 'FactoryClass') ->setProperty('foo', 'bar') - ->setScope('container') ->setPublic(false) ; $container diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container18.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container18.php similarity index 100% rename from src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container18.php rename to src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container18.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php index 9f4210c9d5b7f..22dc44a4e4312 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/legacy-container9.php @@ -30,8 +30,13 @@ setFactoryService('foo.baz')-> setFactoryMethod('getInstance') ; +$container + ->register('foo_bar', '%foo_class%') + ->setScope('prototype') +; $container->getParameterBag()->clear(); $container->getParameterBag()->add(array( + 'foo_class' => 'Bar\FooClass', 'baz_class' => 'BazClass', 'foo' => 'bar', )); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/legacy-services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/legacy-services9.dot index 4e8dfb977495e..ce52c6dcd01c4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/legacy-services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/legacy-services9.dot @@ -6,6 +6,7 @@ digraph sc { node_foo [label="foo\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_foo_baz [label="foo.baz\nBazClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_foo_bar [label="foo_bar\nBar\\FooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"]; node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"]; node_bar [label="bar\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foo -> node_foo_baz [label="" style="filled"]; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services6.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services6.xml index 708e10fd5dcd7..c8e6e30bc9db6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services6.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services6.xml @@ -6,6 +6,9 @@ + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml index 5692ba13ea202..dc55972a287e3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml @@ -1,6 +1,7 @@ + Bar\FooClass BazClass bar @@ -32,5 +33,6 @@ + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml index 9eb7b8915e627..a1a320bd826d4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services6.xml @@ -6,9 +6,7 @@ - - - + %path%/foo.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index c4ddc416b4636..f1e6e98efaf67 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -40,7 +40,7 @@ %foo_bar% - + %path%foo.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services6.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services6.yml index 46ac679940e13..2e702bff2f89b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services6.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services6.yml @@ -1,6 +1,9 @@ services: constructor: { class: FooClass, factory_method: getInstance } factory_service: { class: BazClass, factory_method: getInstance, factory_service: baz_factory } + scope.container: { class: FooClass, scope: container } + scope.custom: { class: FooClass, scope: custom } + scope.prototype: { class: FooClass, scope: prototype } request: class: Request synthetic: true diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml index 64d17262aa307..6a5f03d9b87e4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml @@ -1,4 +1,5 @@ parameters: + foo_class: Bar\FooClass baz_class: BazClass foo: bar @@ -26,3 +27,6 @@ services: class: Bar factory_method: getInstance factory_service: foo.baz + foo_bar: + class: %foo_class% + scope: prototype diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml index 78abf4d155521..2186620045cc9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml @@ -1,9 +1,7 @@ services: foo: { class: FooClass } baz: { class: BazClass } - scope.container: { class: FooClass, scope: container } - scope.custom: { class: FooClass, scope: custom } - scope.prototype: { class: FooClass, scope: prototype } + not_shared: { class: FooClass, shared: false } file: { class: FooClass, file: %path%/foo.php } arguments: { class: FooClass, arguments: [foo, @foo, [true, false]] } configurator1: { class: FooClass, configurator: sc_configure } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index fdab85fc7e058..ddb5d3a96abdf 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -27,7 +27,7 @@ services: configurator: ['@foo.baz', configure] foo_bar: class: %foo_class% - scope: prototype + shared: false method_call1: class: Bar\FooClass file: %path%foo.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 8bf524ae4f32f..581dc675fb3fd 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -204,6 +204,9 @@ public function testLegacyLoadServices() $this->assertNull($services['factory_service']->getClass()); $this->assertEquals('baz_factory', $services['factory_service']->getFactoryService()); $this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod()); + $this->assertEquals('container', $services['scope.container']->getScope()); + $this->assertEquals('custom', $services['scope.custom']->getScope()); + $this->assertEquals('prototype', $services['scope.prototype']->getScope()); $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag'); $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag'); $this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag'); @@ -217,11 +220,9 @@ public function testLoadServices() $loader->load('services6.xml'); $services = $container->getDefinitions(); $this->assertTrue(isset($services['foo']), '->load() parses elements'); + $this->assertFalse($services['not_shared']->isShared(), '->load() parses shared flag'); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts element to Definition instances'); $this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute'); - $this->assertEquals('container', $services['scope.container']->getScope()); - $this->assertEquals('custom', $services['scope.custom']->getScope()); - $this->assertEquals('prototype', $services['scope.prototype']->getScope()); $this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag'); $this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags'); $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 28cf0ebf6252a..058f5b66dffd1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -133,6 +133,9 @@ public function testLegacyLoadServices() $this->assertEquals('BazClass', $services['factory_service']->getClass()); $this->assertEquals('baz_factory', $services['factory_service']->getFactoryService()); $this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod()); + $this->assertEquals('container', $services['scope.container']->getScope()); + $this->assertEquals('custom', $services['scope.custom']->getScope()); + $this->assertEquals('prototype', $services['scope.prototype']->getScope()); $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag'); $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag'); $this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag'); @@ -146,11 +149,9 @@ public function testLoadServices() $loader->load('services6.yml'); $services = $container->getDefinitions(); $this->assertTrue(isset($services['foo']), '->load() parses service elements'); + $this->assertFalse($services['not_shared']->isShared(), '->load() parses the shared flag'); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $services['foo'], '->load() converts service element to Definition instances'); $this->assertEquals('FooClass', $services['foo']->getClass(), '->load() parses the class attribute'); - $this->assertEquals('container', $services['scope.container']->getScope()); - $this->assertEquals('custom', $services['scope.custom']->getScope()); - $this->assertEquals('prototype', $services['scope.prototype']->getScope()); $this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag'); $this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags'); $this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag'); diff --git a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php index 6f2fbcb9df9ad..18a4b3f794af8 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php @@ -92,6 +92,7 @@ public function testPreventDuplicateListenerService() /** * @expectedException \InvalidArgumentException + * @group legacy */ public function testTriggerAListenerServiceOutOfScope() { @@ -111,6 +112,9 @@ public function testTriggerAListenerServiceOutOfScope() $dispatcher->dispatch('onEvent'); } + /** + * @group legacy + */ public function testReEnteringAScope() { $event = new Event(); From b7030cc19e8cf05257c8bd1f309783eedc647131 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Wed, 24 Jun 2015 21:50:08 +0200 Subject: [PATCH 06/12] Make service not shared when prototype scope is set --- .../Component/DependencyInjection/Definition.php | 4 ++++ .../DependencyInjection/Tests/DefinitionTest.php | 13 +++++++++++++ .../Tests/Fixtures/xml/legacy-services9.xml | 2 +- .../Tests/Fixtures/yaml/legacy-services9.yml | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index e68e8b3cb813c..4e99cca77ac08 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -649,6 +649,10 @@ public function setScope($scope, $triggerDeprecationError = true) @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED); } + if (ContainerInterface::SCOPE_PROTOTYPE === $scope) { + $this->setShared(false); + } + $this->scope = $scope; return $this; diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 4bac0e2a0baf2..d67f1d7224a20 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Tests; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ContainerInterface; class DefinitionTest extends \PHPUnit_Framework_TestCase { @@ -139,6 +140,18 @@ public function testSetIsShared() $this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared'); } + /** + * @group legacy + */ + public function testPrototypeScopedDefinitionAreNotShared() + { + $def = new Definition('stdClass'); + $def->setScope(ContainerInterface::SCOPE_PROTOTYPE); + + $this->assertFalse($def->isShared()); + $this->assertEquals(ContainerInterface::SCOPE_PROTOTYPE, $def->getScope()); + } + /** * @covers Symfony\Component\DependencyInjection\Definition::setScope * @covers Symfony\Component\DependencyInjection\Definition::getScope diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml index dc55972a287e3..dcb312a1e9f4c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy-services9.xml @@ -33,6 +33,6 @@ - + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml index 6a5f03d9b87e4..c7e80ea5b8c07 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy-services9.yml @@ -29,4 +29,5 @@ services: factory_service: foo.baz foo_bar: class: %foo_class% + shared: false scope: prototype From d144dbb7334344ed32bfd21fa5c0f5f0ea4074ef Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 26 Jun 2015 16:37:18 +0200 Subject: [PATCH 07/12] [DependencyInjection] improve deprecation messages Also include the service id in the deprecation message. --- .../Component/DependencyInjection/Loader/XmlFileLoader.php | 2 +- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 93bb3a139d056..f6d61d540ee24 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -162,7 +162,7 @@ private function parseDefinition(\DOMElement $service, $file) $triggerDeprecation = 'request' !== (string) $service->getAttribute('id'); if ($triggerDeprecation) { - @trigger_error(sprintf('The "scope" attribute in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $file), E_USER_DEPRECATED); + @trigger_error(sprintf('The "scope" attribute of service "%s" in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', (string) $service->getAttribute('id'), $file), E_USER_DEPRECATED); } $definition->setScope(XmlUtils::phpize($value), false); diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index c0239c2f90bfa..c60a54197b409 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -169,7 +169,7 @@ private function parseDefinition($id, $service, $file) if (isset($service['scope'])) { if ('request' !== $id) { - @trigger_error(sprintf('The "scope" key in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $file), E_USER_DEPRECATED); + @trigger_error(sprintf('The "scope" key of service "%s" in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED); } $definition->setScope($service['scope'], false); } From 1583fadbe95836b4d25db49cf141e34eb028927a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 28 Jun 2015 16:53:41 +0200 Subject: [PATCH 08/12] add option to force web server startup The `server:start` command will report an error message when a lock file does exist. However, this means that you cannot restart the web server process if the previously running process terminated accidentally or if it was terminated by the user without executing the `server:stop` command (e.g. by using the system's `kill` command or the task manager). This commit adds a `--force` option that makes it possible to launch the web server process even if a lock file does exist. --- .../Bundle/FrameworkBundle/Command/ServerStartCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php index d9eccc4d613e2..6300e9774a25d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerStartCommand.php @@ -37,6 +37,7 @@ protected function configure() new InputOption('port', 'p', InputOption::VALUE_REQUIRED, 'Address port number', '8000'), new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root', null), new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'), + new InputOption('force', 'f', InputOption::VALUE_NONE, 'Force web server startup'), )) ->setName('server:start') ->setDescription('Starts PHP built-in web server in the background') @@ -110,8 +111,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $address = $address.':'.$input->getOption('port'); } - if ($this->isOtherServerProcessRunning($address)) { + if (!$input->getOption('force') && $this->isOtherServerProcessRunning($address)) { $output->writeln(sprintf('A process is already listening on http://%s.', $address)); + $output->writeln(sprintf('Use the --force option if the server process terminated unexpectedly to start a new web server process.')); return 1; } From 1df4ebecfd36b5103915b1c001a7068aeaddaa51 Mon Sep 17 00:00:00 2001 From: twifty Date: Tue, 7 Apr 2015 03:31:40 +0800 Subject: [PATCH 09/12] added remove option to ignoreExtraKeys --- .../Component/Config/Definition/ArrayNode.php | 8 +++++++- .../Definition/Builder/ArrayNodeDefinition.php | 8 ++++++-- .../Config/Tests/Definition/ArrayNodeTest.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index 05ae1fdcd99e1..c88552dcda33e 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -29,6 +29,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface protected $addIfNotSet = false; protected $performDeepMerging = true; protected $ignoreExtraKeys = false; + protected $removeExtraKeys = true; protected $normalizeKeys = true; public function setNormalizeKeys($normalizeKeys) @@ -140,10 +141,12 @@ public function setPerformDeepMerging($boolean) * Whether extra keys should just be ignore without an exception. * * @param bool $boolean To allow extra keys + * @param bool $remove To remove extra keys */ - public function setIgnoreExtraKeys($boolean) + public function setIgnoreExtraKeys($boolean, $remove = true) { $this->ignoreExtraKeys = (bool) $boolean; + $this->removeExtraKeys = $this->ignoreExtraKeys && $remove; } /** @@ -300,6 +303,9 @@ protected function normalizeValue($value) if (isset($this->children[$name])) { $normalized[$name] = $this->children[$name]->normalize($val); unset($value[$name]); + } elseif (false === $this->removeExtraKeys) { + $normalized[$name] = $val; + unset($value[$name]); } } diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index c64b2ecfdb91b..fb34cfa8f71f7 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -24,6 +24,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition { protected $performDeepMerging = true; protected $ignoreExtraKeys = false; + protected $removeExtraKeys = true; protected $children = array(); protected $prototype; protected $atLeastOne = false; @@ -284,11 +285,14 @@ public function performNoDeepMerging() * you want to send an entire configuration array through a special * tree that processes only part of the array. * + * @param bool $remove Whether to remove the extra keys + * * @return ArrayNodeDefinition */ - public function ignoreExtraKeys() + public function ignoreExtraKeys($remove = true) { $this->ignoreExtraKeys = true; + $this->removeExtraKeys = $remove; return $this; } @@ -393,7 +397,7 @@ protected function createNode() $node->addEquivalentValue(false, $this->falseEquivalent); $node->setPerformDeepMerging($this->performDeepMerging); $node->setRequired($this->required); - $node->setIgnoreExtraKeys($this->ignoreExtraKeys); + $node->setIgnoreExtraKeys($this->ignoreExtraKeys, $this->removeExtraKeys); $node->setNormalizeKeys($this->normalizeKeys); if (null !== $this->normalization) { diff --git a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php index 291c2fd2cce06..c88fc13f07a7f 100644 --- a/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/ArrayNodeTest.php @@ -50,6 +50,21 @@ public function testIgnoreExtraKeysNoException() $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true'); } + /** + * Tests that extra keys are not removed when + * ignoreExtraKeys second option is set to false. + * + * Related to testExceptionThrownOnUnrecognizedChild + */ + public function testIgnoreExtraKeysNotRemoved() + { + $node = new ArrayNode('roo'); + $node->setIgnoreExtraKeys(true, false); + + $data = array('foo' => 'bar'); + $this->assertSame($data, $node->normalize($data)); + } + /** * @dataProvider getPreNormalizationTests */ From 268210bcece1814b48c2633747865bc96feb6d7a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 28 Jun 2015 20:28:18 +0200 Subject: [PATCH 10/12] fixed CS --- src/Symfony/Component/Config/Definition/ArrayNode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Definition/ArrayNode.php b/src/Symfony/Component/Config/Definition/ArrayNode.php index c88552dcda33e..7c9c14594304c 100644 --- a/src/Symfony/Component/Config/Definition/ArrayNode.php +++ b/src/Symfony/Component/Config/Definition/ArrayNode.php @@ -141,7 +141,7 @@ public function setPerformDeepMerging($boolean) * Whether extra keys should just be ignore without an exception. * * @param bool $boolean To allow extra keys - * @param bool $remove To remove extra keys + * @param bool $remove To remove extra keys */ public function setIgnoreExtraKeys($boolean, $remove = true) { From 96cce38b00c7c2186f082584eb468688e2d873d9 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 27 May 2015 16:05:37 -0400 Subject: [PATCH 11/12] Warmup twig templates in non-standard paths (closes #12507) --- .../CacheWarmer/TemplateCacheCacheWarmer.php | 43 ++++++++++++++++++- .../DependencyInjection/TwigExtension.php | 2 + .../TwigBundle/Resources/config/twig.xml | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index 65827eba5a6b8..5dde9406914a4 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -11,9 +11,11 @@ namespace Symfony\Bundle\TwigBundle\CacheWarmer; +use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinderInterface; +use Symfony\Component\Templating\TemplateReference; /** * Generates the Twig cache for all templates. @@ -27,14 +29,16 @@ class TemplateCacheCacheWarmer implements CacheWarmerInterface { protected $container; protected $finder; + private $paths; /** * Constructor. * * @param ContainerInterface $container The dependency injection container * @param TemplateFinderInterface $finder The template paths cache warmer + * @param array $paths Additional twig paths to warm */ - public function __construct(ContainerInterface $container, TemplateFinderInterface $finder) + public function __construct(ContainerInterface $container, TemplateFinderInterface $finder, array $paths = array()) { // We don't inject the Twig environment directly as it depends on the // template locator (via the loader) which might be a cached one. @@ -42,6 +46,7 @@ public function __construct(ContainerInterface $container, TemplateFinderInterfa // has been warmed up $this->container = $container; $this->finder = $finder; + $this->paths = $paths; } /** @@ -53,7 +58,13 @@ public function warmUp($cacheDir) { $twig = $this->container->get('twig'); - foreach ($this->finder->findAllTemplates() as $template) { + $templates = $this->finder->findAllTemplates(); + + foreach ($this->paths as $path => $namespace) { + $templates = array_merge($templates, $this->findTemplatesInFolder($namespace, $path)); + } + + foreach ($templates as $template) { if ('twig' !== $template->get('engine')) { continue; } @@ -75,4 +86,32 @@ public function isOptional() { return true; } + + /** + * Find templates in the given directory. + * + * @param string $namespace The namespace for these templates + * @param string $dir The folder where to look for templates + * + * @return array An array of templates of type TemplateReferenceInterface + */ + private function findTemplatesInFolder($namespace, $dir) + { + if (!is_dir($dir)) { + return array(); + } + + $templates = array(); + $finder = new Finder(); + + foreach ($finder->files()->followLinks()->in($dir) as $file) { + $name = $file->getRelativePathname(); + $templates[] = new TemplateReference( + $namespace ? sprintf('@%s/%s', $namespace, $name) : $name, + 'twig' + ); + } + + return $templates; + } } diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index df49f8b37217f..7b6a676a52cac 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -77,6 +77,8 @@ public function load(array $configs, ContainerBuilder $container) } } + $container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']); + // register bundles as Twig namespaces foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { $dir = $container->getParameter('kernel.root_dir').'/Resources/'.$bundle.'/views'; diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 9e1a11777418c..c06a82f06ec64 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -48,6 +48,7 @@ + From cb9c069c0ffdbf2154c362aa8610ae79180035f0 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 3 Nov 2014 11:15:16 +0100 Subject: [PATCH 12/12] [Validator] Added missing error codes and turned codes into UUIDs --- .../Component/Validator/Constraints/Blank.php | 6 +++++ .../Validator/Constraints/BlankValidator.php | 2 ++ .../Validator/Constraints/CardScheme.php | 4 ++-- .../Validator/Constraints/Choice.php | 6 ++--- .../Validator/Constraints/Collection.php | 4 ++-- .../Component/Validator/Constraints/Count.php | 4 ++-- .../Validator/Constraints/Country.php | 6 +++++ .../Constraints/CountryValidator.php | 2 ++ .../Validator/Constraints/Currency.php | 6 +++++ .../Constraints/CurrencyValidator.php | 2 ++ .../Component/Validator/Constraints/Date.php | 4 ++-- .../Validator/Constraints/DateTime.php | 6 ++--- .../Component/Validator/Constraints/Email.php | 6 ++--- .../Validator/Constraints/Expression.php | 6 +++++ .../Constraints/ExpressionValidator.php | 2 ++ .../Component/Validator/Constraints/File.php | 10 ++++----- .../Component/Validator/Constraints/Iban.php | 10 ++++----- .../Component/Validator/Constraints/Image.php | 22 +++++++++---------- .../Component/Validator/Constraints/Ip.php | 6 +++++ .../Validator/Constraints/IpValidator.php | 2 ++ .../Validator/Constraints/IsFalse.php | 6 +++++ .../Constraints/IsFalseValidator.php | 2 ++ .../Validator/Constraints/IsNull.php | 6 +++++ .../Validator/Constraints/IsNullValidator.php | 2 ++ .../Validator/Constraints/IsTrue.php | 6 +++++ .../Validator/Constraints/IsTrueValidator.php | 2 ++ .../Component/Validator/Constraints/Isbn.php | 10 ++++----- .../Component/Validator/Constraints/Issn.php | 12 +++++----- .../Validator/Constraints/Language.php | 6 +++++ .../Constraints/LanguageValidator.php | 2 ++ .../Validator/Constraints/Length.php | 6 +++-- .../Validator/Constraints/LengthValidator.php | 2 ++ .../Validator/Constraints/Locale.php | 6 +++++ .../Validator/Constraints/LocaleValidator.php | 2 ++ .../Component/Validator/Constraints/Luhn.php | 4 ++-- .../Validator/Constraints/NotBlank.php | 6 +++++ .../Constraints/NotBlankValidator.php | 2 ++ .../Validator/Constraints/NotNull.php | 6 +++++ .../Constraints/NotNullValidator.php | 13 ++++++++++- .../Component/Validator/Constraints/Range.php | 12 +++++----- .../Validator/Constraints/RangeValidator.php | 12 +++++----- .../Component/Validator/Constraints/Regex.php | 6 +++++ .../Validator/Constraints/RegexValidator.php | 2 ++ .../Component/Validator/Constraints/Time.php | 4 ++-- .../Component/Validator/Constraints/Type.php | 6 +++++ .../Validator/Constraints/TypeValidator.php | 2 ++ .../Component/Validator/Constraints/Url.php | 6 +++++ .../Validator/Constraints/UrlValidator.php | 12 ++++++---- .../Component/Validator/Constraints/Uuid.php | 12 +++++----- .../Tests/Constraints/BlankValidatorTest.php | 1 + .../Constraints/CountryValidatorTest.php | 1 + .../Constraints/CurrencyValidatorTest.php | 1 + .../Constraints/ExpressionValidatorTest.php | 12 +++++++--- .../Validator/Tests/Constraints/FileTest.php | 11 +++++----- .../Tests/Constraints/IpValidatorTest.php | 12 ++++++++++ .../Constraints/IsFalseValidatorTest.php | 1 + .../Tests/Constraints/IsNullValidatorTest.php | 1 + .../Tests/Constraints/IsTrueValidatorTest.php | 1 + .../Constraints/LanguageValidatorTest.php | 1 + .../Tests/Constraints/LengthValidatorTest.php | 1 + .../Tests/Constraints/LocaleValidatorTest.php | 1 + .../Constraints/NotBlankValidatorTest.php | 4 ++++ .../Constraints/NotNullValidatorTest.php | 5 ++++- .../Tests/Constraints/RangeValidatorTest.php | 18 +++++++-------- .../Tests/Constraints/RegexValidatorTest.php | 1 + .../Tests/Constraints/TypeValidatorTest.php | 2 ++ .../Tests/Constraints/UrlValidatorTest.php | 1 + 67 files changed, 268 insertions(+), 98 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/Blank.php b/src/Symfony/Component/Validator/Constraints/Blank.php index 766ce6c7bbbec..f74050a1c75b5 100644 --- a/src/Symfony/Component/Validator/Constraints/Blank.php +++ b/src/Symfony/Component/Validator/Constraints/Blank.php @@ -23,5 +23,11 @@ */ class Blank extends Constraint { + const NOT_BLANK_ERROR = '183ad2de-533d-4796-a439-6d3c3852b549'; + + protected static $errorNames = array( + self::NOT_BLANK_ERROR => 'NOT_BLANK_ERROR', + ); + public $message = 'This value should be blank.'; } diff --git a/src/Symfony/Component/Validator/Constraints/BlankValidator.php b/src/Symfony/Component/Validator/Constraints/BlankValidator.php index 2d26e4a91b808..2d76c77e8fc87 100644 --- a/src/Symfony/Component/Validator/Constraints/BlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/BlankValidator.php @@ -36,10 +36,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Blank::NOT_BLANK_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Blank::NOT_BLANK_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/CardScheme.php b/src/Symfony/Component/Validator/Constraints/CardScheme.php index 14f3b5d8cf0c1..40c32e879e83f 100644 --- a/src/Symfony/Component/Validator/Constraints/CardScheme.php +++ b/src/Symfony/Component/Validator/Constraints/CardScheme.php @@ -24,8 +24,8 @@ */ class CardScheme extends Constraint { - const NOT_NUMERIC_ERROR = 1; - const INVALID_FORMAT_ERROR = 2; + const NOT_NUMERIC_ERROR = 'a2ad9231-e827-485f-8a1e-ef4d9a6d5c2e'; + const INVALID_FORMAT_ERROR = 'a8faedbf-1c2f-4695-8d22-55783be8efed'; protected static $errorNames = array( self::NOT_NUMERIC_ERROR => 'NOT_NUMERIC_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Choice.php b/src/Symfony/Component/Validator/Constraints/Choice.php index 39a64574d0d29..302df202b0991 100644 --- a/src/Symfony/Component/Validator/Constraints/Choice.php +++ b/src/Symfony/Component/Validator/Constraints/Choice.php @@ -23,9 +23,9 @@ */ class Choice extends Constraint { - const NO_SUCH_CHOICE_ERROR = 1; - const TOO_FEW_ERROR = 2; - const TOO_MANY_ERROR = 3; + const NO_SUCH_CHOICE_ERROR = '8e179f1b-97aa-4560-a02f-2a8b42e49df7'; + const TOO_FEW_ERROR = '11edd7eb-5872-4b6e-9f12-89923999fd0e'; + const TOO_MANY_ERROR = '9bd98e49-211c-433f-8630-fd1c2d0f08c3'; protected static $errorNames = array( self::NO_SUCH_CHOICE_ERROR => 'NO_SUCH_CHOICE_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Collection.php b/src/Symfony/Component/Validator/Constraints/Collection.php index 708c8ed47730e..57fc93832fff3 100644 --- a/src/Symfony/Component/Validator/Constraints/Collection.php +++ b/src/Symfony/Component/Validator/Constraints/Collection.php @@ -23,8 +23,8 @@ */ class Collection extends Composite { - const MISSING_FIELD_ERROR = 1; - const NO_SUCH_FIELD_ERROR = 2; + const MISSING_FIELD_ERROR = '2fa2158c-2a7f-484b-98aa-975522539ff8'; + const NO_SUCH_FIELD_ERROR = '7703c766-b5d5-4cef-ace7-ae0dd82304e9'; protected static $errorNames = array( self::MISSING_FIELD_ERROR => 'MISSING_FIELD_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Count.php b/src/Symfony/Component/Validator/Constraints/Count.php index a3e12fe1342d8..4fe97104692b1 100644 --- a/src/Symfony/Component/Validator/Constraints/Count.php +++ b/src/Symfony/Component/Validator/Constraints/Count.php @@ -24,8 +24,8 @@ */ class Count extends Constraint { - const TOO_FEW_ERROR = 1; - const TOO_MANY_ERROR = 2; + const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69'; + const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169'; protected static $errorNames = array( self::TOO_FEW_ERROR => 'TOO_FEW_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Country.php b/src/Symfony/Component/Validator/Constraints/Country.php index ff6f3d0e0a539..c3e91fb123cf6 100644 --- a/src/Symfony/Component/Validator/Constraints/Country.php +++ b/src/Symfony/Component/Validator/Constraints/Country.php @@ -23,5 +23,11 @@ */ class Country extends Constraint { + const NO_SUCH_COUNTRY_ERROR = '8f900c12-61bd-455d-9398-996cd040f7f0'; + + protected static $errorNames = array( + self::NO_SUCH_COUNTRY_ERROR => 'NO_SUCH_COUNTRY_ERROR', + ); + public $message = 'This value is not a valid country.'; } diff --git a/src/Symfony/Component/Validator/Constraints/CountryValidator.php b/src/Symfony/Component/Validator/Constraints/CountryValidator.php index 8139adf943119..0e1d3851969f2 100644 --- a/src/Symfony/Component/Validator/Constraints/CountryValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CountryValidator.php @@ -50,10 +50,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Currency.php b/src/Symfony/Component/Validator/Constraints/Currency.php index c09fe88bf27e9..2b4498dc0da2d 100644 --- a/src/Symfony/Component/Validator/Constraints/Currency.php +++ b/src/Symfony/Component/Validator/Constraints/Currency.php @@ -23,5 +23,11 @@ */ class Currency extends Constraint { + const NO_SUCH_CURRENCY_ERROR = '69945ac1-2db4-405f-bec7-d2772f73df52'; + + protected static $errorNames = array( + self::NO_SUCH_CURRENCY_ERROR => 'NO_SUCH_CURRENCY_ERROR', + ); + public $message = 'This value is not a valid currency.'; } diff --git a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php index 9c41dc4a100ee..c13219e377909 100644 --- a/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CurrencyValidator.php @@ -50,10 +50,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Currency::NO_SUCH_CURRENCY_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Currency::NO_SUCH_CURRENCY_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Date.php b/src/Symfony/Component/Validator/Constraints/Date.php index 2bc444f71af68..f960ac765d06f 100644 --- a/src/Symfony/Component/Validator/Constraints/Date.php +++ b/src/Symfony/Component/Validator/Constraints/Date.php @@ -23,8 +23,8 @@ */ class Date extends Constraint { - const INVALID_FORMAT_ERROR = 1; - const INVALID_DATE_ERROR = 2; + const INVALID_FORMAT_ERROR = '69819696-02ac-4a99-9ff0-14e127c4d1bc'; + const INVALID_DATE_ERROR = '3c184ce5-b31d-4de7-8b76-326da7b2be93'; protected static $errorNames = array( self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/DateTime.php b/src/Symfony/Component/Validator/Constraints/DateTime.php index ae67ff30efb4b..a1e9d22df73b5 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTime.php +++ b/src/Symfony/Component/Validator/Constraints/DateTime.php @@ -23,9 +23,9 @@ */ class DateTime extends Constraint { - const INVALID_FORMAT_ERROR = 1; - const INVALID_DATE_ERROR = 2; - const INVALID_TIME_ERROR = 3; + const INVALID_FORMAT_ERROR = '1a9da513-2640-4f84-9b6a-4d99dcddc628'; + const INVALID_DATE_ERROR = 'd52afa47-620d-4d99-9f08-f4d85b36e33c'; + const INVALID_TIME_ERROR = '5e797c9d-74f7-4098-baa3-94390c447b27'; protected static $errorNames = array( self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Email.php b/src/Symfony/Component/Validator/Constraints/Email.php index 36977177bdfd1..d1191a43137e4 100644 --- a/src/Symfony/Component/Validator/Constraints/Email.php +++ b/src/Symfony/Component/Validator/Constraints/Email.php @@ -23,9 +23,9 @@ */ class Email extends Constraint { - const INVALID_FORMAT_ERROR = 1; - const MX_CHECK_FAILED_ERROR = 2; - const HOST_CHECK_FAILED_ERROR = 3; + const INVALID_FORMAT_ERROR = 'bd79c0ab-ddba-46cc-a703-a7a4b08de310'; + const MX_CHECK_FAILED_ERROR = 'bf447c1c-0266-4e10-9c6c-573df282e413'; + const HOST_CHECK_FAILED_ERROR = '7da53a8b-56f3-4288-bb3e-ee9ede4ef9a1'; protected static $errorNames = array( self::INVALID_FORMAT_ERROR => 'STRICT_CHECK_FAILED_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Expression.php b/src/Symfony/Component/Validator/Constraints/Expression.php index dfa242c31a40c..3329bd2494028 100644 --- a/src/Symfony/Component/Validator/Constraints/Expression.php +++ b/src/Symfony/Component/Validator/Constraints/Expression.php @@ -22,6 +22,12 @@ */ class Expression extends Constraint { + const EXPRESSION_FAILED_ERROR = '6b3befbc-2f01-4ddf-be21-b57898905284'; + + protected static $errorNames = array( + self::EXPRESSION_FAILED_ERROR => 'EXPRESSION_FAILED_ERROR', + ); + public $message = 'This value is not valid.'; public $expression; diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 15d51f9ff10c0..031bf420ce530 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -88,10 +88,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/File.php b/src/Symfony/Component/Validator/Constraints/File.php index ae0ad67395594..ce0c102842519 100644 --- a/src/Symfony/Component/Validator/Constraints/File.php +++ b/src/Symfony/Component/Validator/Constraints/File.php @@ -26,11 +26,11 @@ class File extends Constraint { // Check the Image constraint for clashes if adding new constants here - const NOT_FOUND_ERROR = 1; - const NOT_READABLE_ERROR = 2; - const EMPTY_ERROR = 3; - const TOO_LARGE_ERROR = 4; - const INVALID_MIME_TYPE_ERROR = 5; + const NOT_FOUND_ERROR = 'd2a3fb6e-7ddc-4210-8fbf-2ab345ce1998'; + const NOT_READABLE_ERROR = 'c20c92a4-5bfa-4202-9477-28e800e0f6ff'; + const EMPTY_ERROR = '5d743385-9775-4aa5-8ff5-495fb1e60137'; + const TOO_LARGE_ERROR = 'df8637af-d466-48c6-a59d-e7126250a654'; + const INVALID_MIME_TYPE_ERROR = '744f00bc-4389-4c74-92de-9a43cde55534'; protected static $errorNames = array( self::NOT_FOUND_ERROR => 'NOT_FOUND_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Iban.php b/src/Symfony/Component/Validator/Constraints/Iban.php index 66ce09ae1a630..a0d6b0982d645 100644 --- a/src/Symfony/Component/Validator/Constraints/Iban.php +++ b/src/Symfony/Component/Validator/Constraints/Iban.php @@ -23,11 +23,11 @@ */ class Iban extends Constraint { - const TOO_SHORT_ERROR = 1; - const INVALID_COUNTRY_CODE_ERROR = 2; - const INVALID_CHARACTERS_ERROR = 3; - const INVALID_CASE_ERROR = 4; - const CHECKSUM_FAILED_ERROR = 5; + const TOO_SHORT_ERROR = '88e5e319-0aeb-4979-a27e-3d9ce0c16166'; + const INVALID_COUNTRY_CODE_ERROR = 'de78ee2c-bd50-44e2-aec8-3d8228aeadb9'; + const INVALID_CHARACTERS_ERROR = '8d3d85e4-784f-4719-a5bc-d9e40d45a3a5'; + const INVALID_CASE_ERROR = 'f4bf62fe-03ec-42af-a53b-68e21b1e7274'; + const CHECKSUM_FAILED_ERROR = 'b9401321-f9bf-4dcb-83c1-f31094440795'; protected static $errorNames = array( self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Image.php b/src/Symfony/Component/Validator/Constraints/Image.php index 904ef97b492b1..6d9d2c5046cbe 100644 --- a/src/Symfony/Component/Validator/Constraints/Image.php +++ b/src/Symfony/Component/Validator/Constraints/Image.php @@ -22,18 +22,16 @@ */ class Image extends File { - // Don't reuse values used in File - - const SIZE_NOT_DETECTED_ERROR = 10; - const TOO_WIDE_ERROR = 11; - const TOO_NARROW_ERROR = 12; - const TOO_HIGH_ERROR = 13; - const TOO_LOW_ERROR = 14; - const RATIO_TOO_BIG_ERROR = 15; - const RATIO_TOO_SMALL_ERROR = 16; - const SQUARE_NOT_ALLOWED_ERROR = 17; - const LANDSCAPE_NOT_ALLOWED_ERROR = 18; - const PORTRAIT_NOT_ALLOWED_ERROR = 19; + const SIZE_NOT_DETECTED_ERROR = '6d55c3f4-e58e-4fe3-91ee-74b492199956'; + const TOO_WIDE_ERROR = '7f87163d-878f-47f5-99ba-a8eb723a1ab2'; + const TOO_NARROW_ERROR = '9afbd561-4f90-4a27-be62-1780fc43604a'; + const TOO_HIGH_ERROR = '7efae81c-4877-47ba-aa65-d01ccb0d4645'; + const TOO_LOW_ERROR = 'aef0cb6a-c07f-4894-bc08-1781420d7b4c'; + const RATIO_TOO_BIG_ERROR = '70cafca6-168f-41c9-8c8c-4e47a52be643'; + const RATIO_TOO_SMALL_ERROR = '59b8c6ef-bcf2-4ceb-afff-4642ed92f12e'; + const SQUARE_NOT_ALLOWED_ERROR = '5d41425b-facb-47f7-a55a-de9fbe45cb46'; + const LANDSCAPE_NOT_ALLOWED_ERROR = '6f895685-7cf2-4d65-b3da-9029c5581d88'; + const PORTRAIT_NOT_ALLOWED_ERROR = '65608156-77da-4c79-a88c-02ef6d18c782'; // Include the mapping from the base class diff --git a/src/Symfony/Component/Validator/Constraints/Ip.php b/src/Symfony/Component/Validator/Constraints/Ip.php index 27f0b2d0fda1b..2633f467327cc 100644 --- a/src/Symfony/Component/Validator/Constraints/Ip.php +++ b/src/Symfony/Component/Validator/Constraints/Ip.php @@ -46,6 +46,8 @@ class Ip extends Constraint const V6_ONLY_PUBLIC = '6_public'; const ALL_ONLY_PUBLIC = 'all_public'; + const INVALID_IP_ERROR = 'b1b427ae-9f6f-41b0-aa9b-84511fbb3c5b'; + protected static $versions = array( self::V4, self::V6, @@ -64,6 +66,10 @@ class Ip extends Constraint self::ALL_ONLY_PUBLIC, ); + protected static $errorNames = array( + self::INVALID_IP_ERROR => 'INVALID_IP_ERROR', + ); + public $version = self::V4; public $message = 'This is not a valid IP address.'; diff --git a/src/Symfony/Component/Validator/Constraints/IpValidator.php b/src/Symfony/Component/Validator/Constraints/IpValidator.php index 8ec8068e79d58..7815510f0823f 100644 --- a/src/Symfony/Component/Validator/Constraints/IpValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IpValidator.php @@ -99,10 +99,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Ip::INVALID_IP_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Ip::INVALID_IP_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/IsFalse.php b/src/Symfony/Component/Validator/Constraints/IsFalse.php index 7b1b72bd51110..945f3a2cde7a7 100644 --- a/src/Symfony/Component/Validator/Constraints/IsFalse.php +++ b/src/Symfony/Component/Validator/Constraints/IsFalse.php @@ -23,5 +23,11 @@ */ class IsFalse extends Constraint { + const NOT_FALSE_ERROR = 'd53a91b0-def3-426a-83d7-269da7ab4200'; + + protected static $errorNames = array( + self::NOT_FALSE_ERROR => 'NOT_FALSE_ERROR', + ); + public $message = 'This value should be false.'; } diff --git a/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php b/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php index f5215588f21e7..7e330e4dd7276 100644 --- a/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsFalseValidator.php @@ -39,10 +39,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsFalse::NOT_FALSE_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsFalse::NOT_FALSE_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/IsNull.php b/src/Symfony/Component/Validator/Constraints/IsNull.php index 3e7fef112c72c..ea0b0febba139 100644 --- a/src/Symfony/Component/Validator/Constraints/IsNull.php +++ b/src/Symfony/Component/Validator/Constraints/IsNull.php @@ -23,5 +23,11 @@ */ class IsNull extends Constraint { + const NOT_NULL_ERROR = '60d2f30b-8cfa-4372-b155-9656634de120'; + + protected static $errorNames = array( + self::NOT_NULL_ERROR => 'NOT_NULL_ERROR', + ); + public $message = 'This value should be null.'; } diff --git a/src/Symfony/Component/Validator/Constraints/IsNullValidator.php b/src/Symfony/Component/Validator/Constraints/IsNullValidator.php index 162f6182fffcc..4a7ada83877c5 100644 --- a/src/Symfony/Component/Validator/Constraints/IsNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsNullValidator.php @@ -36,10 +36,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsNull::NOT_NULL_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsNull::NOT_NULL_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/IsTrue.php b/src/Symfony/Component/Validator/Constraints/IsTrue.php index c0be6b8272d6f..37049ebb3f48d 100644 --- a/src/Symfony/Component/Validator/Constraints/IsTrue.php +++ b/src/Symfony/Component/Validator/Constraints/IsTrue.php @@ -23,5 +23,11 @@ */ class IsTrue extends Constraint { + const NOT_TRUE_ERROR = '2beabf1c-54c0-4882-a928-05249b26e23b'; + + protected static $errorNames = array( + self::NOT_TRUE_ERROR => 'NOT_TRUE_ERROR', + ); + public $message = 'This value should be true.'; } diff --git a/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php b/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php index 206c63d9a7949..fc044ca59c252 100644 --- a/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IsTrueValidator.php @@ -40,10 +40,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsTrue::NOT_TRUE_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(IsTrue::NOT_TRUE_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Isbn.php b/src/Symfony/Component/Validator/Constraints/Isbn.php index 35cb82204e245..3c4251b39ea7c 100644 --- a/src/Symfony/Component/Validator/Constraints/Isbn.php +++ b/src/Symfony/Component/Validator/Constraints/Isbn.php @@ -23,11 +23,11 @@ */ class Isbn extends Constraint { - const TOO_SHORT_ERROR = 1; - const TOO_LONG_ERROR = 2; - const INVALID_CHARACTERS_ERROR = 3; - const CHECKSUM_FAILED_ERROR = 4; - const TYPE_NOT_RECOGNIZED_ERROR = 5; + const TOO_SHORT_ERROR = '949acbb0-8ef5-43ed-a0e9-032dfd08ae45'; + const TOO_LONG_ERROR = '3171387d-f80a-47b3-bd6e-60598545316a'; + const INVALID_CHARACTERS_ERROR = '23d21cea-da99-453d-98b1-a7d916fbb339'; + const CHECKSUM_FAILED_ERROR = '2881c032-660f-46b6-8153-d352d9706640'; + const TYPE_NOT_RECOGNIZED_ERROR = 'fa54a457-f042-441f-89c4-066ee5bdd3e1'; protected static $errorNames = array( self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Issn.php b/src/Symfony/Component/Validator/Constraints/Issn.php index 39716a28cce30..a2fecdd35c386 100644 --- a/src/Symfony/Component/Validator/Constraints/Issn.php +++ b/src/Symfony/Component/Validator/Constraints/Issn.php @@ -22,12 +22,12 @@ */ class Issn extends Constraint { - const TOO_SHORT_ERROR = 1; - const TOO_LONG_ERROR = 2; - const MISSING_HYPHEN_ERROR = 3; - const INVALID_CHARACTERS_ERROR = 4; - const INVALID_CASE_ERROR = 5; - const CHECKSUM_FAILED_ERROR = 6; + const TOO_SHORT_ERROR = '6a20dd3d-f463-4460-8e7b-18a1b98abbfb'; + const TOO_LONG_ERROR = '37cef893-5871-464e-8b12-7fb79324833c'; + const MISSING_HYPHEN_ERROR = '2983286f-8134-4693-957a-1ec4ef887b15'; + const INVALID_CHARACTERS_ERROR = 'a663d266-37c2-4ece-a914-ae891940c588'; + const INVALID_CASE_ERROR = '7b6dd393-7523-4a6c-b84d-72b91bba5e1a'; + const CHECKSUM_FAILED_ERROR = 'b0f92dbc-667c-48de-b526-ad9586d43e85'; protected static $errorNames = array( self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Language.php b/src/Symfony/Component/Validator/Constraints/Language.php index e7c29dc64b8ca..190885ce865b9 100644 --- a/src/Symfony/Component/Validator/Constraints/Language.php +++ b/src/Symfony/Component/Validator/Constraints/Language.php @@ -23,5 +23,11 @@ */ class Language extends Constraint { + const NO_SUCH_LANGUAGE_ERROR = 'ee65fec4-9a20-4202-9f39-ca558cd7bdf7'; + + protected static $errorNames = array( + self::NO_SUCH_LANGUAGE_ERROR => 'NO_SUCH_LANGUAGE_ERROR', + ); + public $message = 'This value is not a valid language.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php index cc8581f819e0a..a0f89bbbee0a2 100644 --- a/src/Symfony/Component/Validator/Constraints/LanguageValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LanguageValidator.php @@ -50,10 +50,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Language::NO_SUCH_LANGUAGE_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Language::NO_SUCH_LANGUAGE_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Length.php b/src/Symfony/Component/Validator/Constraints/Length.php index 8d004805cb106..356dea0db32ed 100644 --- a/src/Symfony/Component/Validator/Constraints/Length.php +++ b/src/Symfony/Component/Validator/Constraints/Length.php @@ -24,12 +24,14 @@ */ class Length extends Constraint { - const TOO_SHORT_ERROR = 1; - const TOO_LONG_ERROR = 2; + const TOO_SHORT_ERROR = '9ff3fdc4-b214-49db-8718-39c315e33d45'; + const TOO_LONG_ERROR = 'd94b19cc-114f-4f44-9cc4-4138e80a87b9'; + const INVALID_CHARACTERS_ERROR = '35e6a710-aa2e-4719-b58e-24b35749b767'; protected static $errorNames = array( self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', self::TOO_LONG_ERROR => 'TOO_LONG_ERROR', + self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', ); public $maxMessage = 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.'; diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index bfa7b19f340b1..9597f3869ac1b 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -70,12 +70,14 @@ public function validate($value, Constraint $constraint) ->setParameter('{{ value }}', $this->formatValue($stringValue)) ->setParameter('{{ charset }}', $constraint->charset) ->setInvalidValue($value) + ->setCode(Length::INVALID_CHARACTERS_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->charsetMessage) ->setParameter('{{ value }}', $this->formatValue($stringValue)) ->setParameter('{{ charset }}', $constraint->charset) ->setInvalidValue($value) + ->setCode(Length::INVALID_CHARACTERS_ERROR) ->addViolation(); } diff --git a/src/Symfony/Component/Validator/Constraints/Locale.php b/src/Symfony/Component/Validator/Constraints/Locale.php index 12a55464a6359..bb85be246afd8 100644 --- a/src/Symfony/Component/Validator/Constraints/Locale.php +++ b/src/Symfony/Component/Validator/Constraints/Locale.php @@ -23,5 +23,11 @@ */ class Locale extends Constraint { + const NO_SUCH_LOCALE_ERROR = 'a0af4293-1f1a-4a1c-a328-979cba6182a2'; + + protected static $errorNames = array( + self::NO_SUCH_LOCALE_ERROR => 'NO_SUCH_LOCALE_ERROR', + ); + public $message = 'This value is not a valid locale.'; } diff --git a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php index a5f69271e6e0b..daf404c141141 100644 --- a/src/Symfony/Component/Validator/Constraints/LocaleValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LocaleValidator.php @@ -50,10 +50,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Locale::NO_SUCH_LOCALE_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Locale::NO_SUCH_LOCALE_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Luhn.php b/src/Symfony/Component/Validator/Constraints/Luhn.php index 24f5bc77ab76c..67f152d29dc53 100644 --- a/src/Symfony/Component/Validator/Constraints/Luhn.php +++ b/src/Symfony/Component/Validator/Constraints/Luhn.php @@ -25,8 +25,8 @@ */ class Luhn extends Constraint { - const INVALID_CHARACTERS_ERROR = 1; - const CHECKSUM_FAILED_ERROR = 2; + const INVALID_CHARACTERS_ERROR = 'dfad6d23-1b74-4374-929b-5cbb56fc0d9e'; + const CHECKSUM_FAILED_ERROR = '4d760774-3f50-4cd5-a6d5-b10a3299d8d3'; protected static $errorNames = array( self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/NotBlank.php b/src/Symfony/Component/Validator/Constraints/NotBlank.php index c578c6d81f3a0..f7242ce0d1836 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlank.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlank.php @@ -23,5 +23,11 @@ */ class NotBlank extends Constraint { + const IS_BLANK_ERROR = 'c1051bb4-d103-4f74-8988-acbcafc7fdc3'; + + protected static $errorNames = array( + self::IS_BLANK_ERROR => 'IS_BLANK_ERROR', + ); + public $message = 'This value should not be blank.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php index a435701cf2605..3714d7930ed26 100644 --- a/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotBlankValidator.php @@ -36,10 +36,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(NotBlank::IS_BLANK_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(NotBlank::IS_BLANK_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/NotNull.php b/src/Symfony/Component/Validator/Constraints/NotNull.php index 60416c76ec2d4..1701bf7bdcb3e 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNull.php +++ b/src/Symfony/Component/Validator/Constraints/NotNull.php @@ -23,5 +23,11 @@ */ class NotNull extends Constraint { + const IS_NULL_ERROR = 'ad32d13f-c3d4-423b-909a-857b961eb720'; + + protected static $errorNames = array( + self::IS_NULL_ERROR => 'IS_NULL_ERROR', + ); + public $message = 'This value should not be null.'; } diff --git a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php index a7a905ae14948..e43b7a4c5e2b8 100644 --- a/src/Symfony/Component/Validator/Constraints/NotNullValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NotNullValidator.php @@ -13,6 +13,7 @@ use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Exception\UnexpectedTypeException; /** @@ -32,7 +33,17 @@ public function validate($value, Constraint $constraint) } if (null === $value) { - $this->context->addViolation($constraint->message); + if ($this->context instanceof ExecutionContextInterface) { + $this->context->buildViolation($constraint->message) + ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(NotNull::IS_NULL_ERROR) + ->addViolation(); + } else { + $this->buildViolation($constraint->message) + ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(NotNull::IS_NULL_ERROR) + ->addViolation(); + } } } } diff --git a/src/Symfony/Component/Validator/Constraints/Range.php b/src/Symfony/Component/Validator/Constraints/Range.php index a12afffbedb8c..199163b3ab37f 100644 --- a/src/Symfony/Component/Validator/Constraints/Range.php +++ b/src/Symfony/Component/Validator/Constraints/Range.php @@ -24,14 +24,14 @@ */ class Range extends Constraint { - const INVALID_VALUE_ERROR = 1; - const BEYOND_RANGE_ERROR = 2; - const BELOW_RANGE_ERROR = 3; + const INVALID_CHARACTERS_ERROR = 'ad9a9798-7a99-4df7-8ce9-46e416a1e60b'; + const TOO_HIGH_ERROR = '2d28afcb-e32e-45fb-a815-01c431a86a69'; + const TOO_LOW_ERROR = '76454e69-502c-46c5-9643-f447d837c4d5'; protected static $errorNames = array( - self::INVALID_VALUE_ERROR => 'INVALID_VALUE_ERROR', - self::BEYOND_RANGE_ERROR => 'BEYOND_RANGE_ERROR', - self::BELOW_RANGE_ERROR => 'BELOW_RANGE_ERROR', + self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR', + self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR', + self::TOO_LOW_ERROR => 'TOO_LOW_ERROR', ); public $minMessage = 'This value should be {{ limit }} or more.'; diff --git a/src/Symfony/Component/Validator/Constraints/RangeValidator.php b/src/Symfony/Component/Validator/Constraints/RangeValidator.php index 8f5fddac2ade9..05ef3b47c752b 100644 --- a/src/Symfony/Component/Validator/Constraints/RangeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RangeValidator.php @@ -38,12 +38,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->invalidMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) - ->setCode(Range::INVALID_VALUE_ERROR) + ->setCode(Range::INVALID_CHARACTERS_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->invalidMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) - ->setCode(Range::INVALID_VALUE_ERROR) + ->setCode(Range::INVALID_CHARACTERS_ERROR) ->addViolation(); } @@ -72,13 +72,13 @@ public function validate($value, Constraint $constraint) $this->context->buildViolation($constraint->maxMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE)) - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->maxMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($max, self::PRETTY_DATE)) - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->addViolation(); } @@ -90,13 +90,13 @@ public function validate($value, Constraint $constraint) $this->context->buildViolation($constraint->minMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE)) - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->minMessage) ->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE)) ->setParameter('{{ limit }}', $this->formatValue($min, self::PRETTY_DATE)) - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Regex.php b/src/Symfony/Component/Validator/Constraints/Regex.php index 3cdf5146fd407..e0a11b5c08553 100644 --- a/src/Symfony/Component/Validator/Constraints/Regex.php +++ b/src/Symfony/Component/Validator/Constraints/Regex.php @@ -23,6 +23,12 @@ */ class Regex extends Constraint { + const REGEX_FAILED_ERROR = 'de1e3db3-5ed4-4941-aae4-59f3667cc3a3'; + + protected static $errorNames = array( + self::REGEX_FAILED_ERROR => 'REGEX_FAILED_ERROR', + ); + public $message = 'This value is not valid.'; public $pattern; public $htmlPattern; diff --git a/src/Symfony/Component/Validator/Constraints/RegexValidator.php b/src/Symfony/Component/Validator/Constraints/RegexValidator.php index 45ba9793ef537..1edbde1923690 100644 --- a/src/Symfony/Component/Validator/Constraints/RegexValidator.php +++ b/src/Symfony/Component/Validator/Constraints/RegexValidator.php @@ -49,10 +49,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Regex::REGEX_FAILED_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Regex::REGEX_FAILED_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Time.php b/src/Symfony/Component/Validator/Constraints/Time.php index 7998c6f9519b6..e65ebc00d47ed 100644 --- a/src/Symfony/Component/Validator/Constraints/Time.php +++ b/src/Symfony/Component/Validator/Constraints/Time.php @@ -23,8 +23,8 @@ */ class Time extends Constraint { - const INVALID_FORMAT_ERROR = 1; - const INVALID_TIME_ERROR = 2; + const INVALID_FORMAT_ERROR = '9d27b2bb-f755-4fbf-b725-39b1edbdebdf'; + const INVALID_TIME_ERROR = '8532f9e1-84b2-4d67-8989-0818bc38533b'; protected static $errorNames = array( self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR', diff --git a/src/Symfony/Component/Validator/Constraints/Type.php b/src/Symfony/Component/Validator/Constraints/Type.php index fc4cc72eb685f..f8ff9d88bdcf8 100644 --- a/src/Symfony/Component/Validator/Constraints/Type.php +++ b/src/Symfony/Component/Validator/Constraints/Type.php @@ -23,6 +23,12 @@ */ class Type extends Constraint { + const INVALID_TYPE_ERROR = 'ba785a8c-82cb-4283-967c-3cf342181b40'; + + protected static $errorNames = array( + self::INVALID_TYPE_ERROR => 'INVALID_TYPE_ERROR', + ); + public $message = 'This value should be of type {{ type }}.'; public $type; diff --git a/src/Symfony/Component/Validator/Constraints/TypeValidator.php b/src/Symfony/Component/Validator/Constraints/TypeValidator.php index 30ad278de1b77..55a27bec3a953 100644 --- a/src/Symfony/Component/Validator/Constraints/TypeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TypeValidator.php @@ -53,11 +53,13 @@ public function validate($value, Constraint $constraint) $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setParameter('{{ type }}', $constraint->type) + ->setCode(Type::INVALID_TYPE_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setParameter('{{ type }}', $constraint->type) + ->setCode(Type::INVALID_TYPE_ERROR) ->addViolation(); } } diff --git a/src/Symfony/Component/Validator/Constraints/Url.php b/src/Symfony/Component/Validator/Constraints/Url.php index 7b8ef3fb626cf..6c8ebb7744619 100644 --- a/src/Symfony/Component/Validator/Constraints/Url.php +++ b/src/Symfony/Component/Validator/Constraints/Url.php @@ -23,6 +23,12 @@ */ class Url extends Constraint { + const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229'; + + protected static $errorNames = array( + self::INVALID_URL_ERROR => 'INVALID_URL_ERROR', + ); + public $message = 'This value is not a valid URL.'; public $dnsMessage = 'The host could not be resolved.'; public $protocols = array('http', 'https'); diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index b38f8dafab305..b308b20e6448f 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -63,10 +63,12 @@ public function validate($value, Constraint $constraint) if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Url::INVALID_URL_ERROR) ->addViolation(); } else { $this->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setCode(Url::INVALID_URL_ERROR) ->addViolation(); } @@ -79,12 +81,14 @@ public function validate($value, Constraint $constraint) if (!checkdnsrr($host, 'ANY')) { if ($this->context instanceof ExecutionContextInterface) { $this->context->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->addViolation(); + ->setParameter('{{ value }}', $this->formatValue($host)) + ->setCode(Url::INVALID_URL_ERROR) + ->addViolation(); } else { $this->buildViolation($constraint->dnsMessage) - ->setParameter('{{ value }}', $this->formatValue($host)) - ->addViolation(); + ->setParameter('{{ value }}', $this->formatValue($host)) + ->setCode(Url::INVALID_URL_ERROR) + ->addViolation(); } } } diff --git a/src/Symfony/Component/Validator/Constraints/Uuid.php b/src/Symfony/Component/Validator/Constraints/Uuid.php index 3c67a3af0c163..83627800791c4 100644 --- a/src/Symfony/Component/Validator/Constraints/Uuid.php +++ b/src/Symfony/Component/Validator/Constraints/Uuid.php @@ -21,12 +21,12 @@ */ class Uuid extends Constraint { - const TOO_SHORT_ERROR = 1; - const TOO_LONG_ERROR = 2; - const INVALID_CHARACTERS_ERROR = 3; - const INVALID_HYPHEN_PLACEMENT_ERROR = 4; - const INVALID_VERSION_ERROR = 5; - const INVALID_VARIANT_ERROR = 6; + const TOO_SHORT_ERROR = 'aa314679-dac9-4f54-bf97-b2049df8f2a3'; + const TOO_LONG_ERROR = '494897dd-36f8-4d31-8923-71a8d5f3000d'; + const INVALID_CHARACTERS_ERROR = '51120b12-a2bc-41bf-aa53-cd73daf330d0'; + const INVALID_HYPHEN_PLACEMENT_ERROR = '98469c83-0309-4f5d-bf95-a496dcaa869c'; + const INVALID_VERSION_ERROR = '21ba13b4-b185-4882-ac6f-d147355987eb'; + const INVALID_VARIANT_ERROR = '164ef693-2b9d-46de-ad7f-836201f0c2db'; protected static $errorNames = array( self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR', diff --git a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php index a7f3d7dd58406..17d8bfbc2e80b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php @@ -54,6 +54,7 @@ public function testInvalidValues($value, $valueAsString) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $valueAsString) + ->setCode(Blank::NOT_BLANK_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index b13351181a43f..1f66de2aa95dd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -89,6 +89,7 @@ public function testInvalidCountries($country) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$country.'"') + ->setCode(Country::NO_SUCH_COUNTRY_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index e5bb060d9c903..c59fc638f70f6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -103,6 +103,7 @@ public function testInvalidCurrencies($currency) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$currency.'"') + ->setCode(Currency::NO_SUCH_CURRENCY_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index 3d4ef75978a6f..742c2027c5b7f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -40,6 +40,7 @@ public function testExpressionIsEvaluatedWithNullValue() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'null') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } @@ -54,6 +55,7 @@ public function testExpressionIsEvaluatedWithEmptyStringValue() $this->buildViolation('myMessage') ->setParameter('{{ value }}', '""') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } @@ -87,6 +89,7 @@ public function testFailingExpressionAtObjectLevel() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'object') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } @@ -123,8 +126,9 @@ public function testFailingExpressionAtPropertyLevel() $this->validator->validate('2', $constraint); $this->buildViolation('myMessage') - ->setParameter('{{ value }}', '"2"') ->atPath('data') + ->setParameter('{{ value }}', '"2"') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } @@ -167,8 +171,9 @@ public function testFailingExpressionAtNestedPropertyLevel() $this->validator->validate('2', $constraint); $this->buildViolation('myMessage') - ->setParameter('{{ value }}', '"2"') ->atPath('reference.data') + ->setParameter('{{ value }}', '"2"') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } @@ -207,8 +212,9 @@ public function testFailingExpressionAtPropertyLevelWithoutRoot() $this->validator->validate('2', $constraint); $this->buildViolation('myMessage') - ->setParameter('{{ value }}', '"2"') ->atPath('') + ->setParameter('{{ value }}', '"2"') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php index 2ee46813bf8b0..4b28fd44f366f 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php @@ -17,8 +17,8 @@ class FileTest extends \PHPUnit_Framework_TestCase { /** * @param mixed $maxSize - * @param int bytes - * @param bool $bytes + * @param int $bytes + * @param bool $binaryFormat * @dataProvider provideValidSizes */ public function testMaxSize($maxSize, $bytes, $binaryFormat) @@ -31,13 +31,12 @@ public function testMaxSize($maxSize, $bytes, $binaryFormat) /** * @param mixed $maxSize - * @param int $bytes * @dataProvider provideInValidSizes - * @expectedException Symfony\Component\Validator\Exception\ConstraintDefinitionException + * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ - public function testInvalideMaxSize($maxSize) + public function testInvalidMaxSize($maxSize) { - $file = new File(array('maxSize' => $maxSize)); + new File(array('maxSize' => $maxSize)); } /** diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php index fc40e6104e14b..439d45cc050fc 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php @@ -153,6 +153,7 @@ public function testInvalidIpsV4($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -185,6 +186,7 @@ public function testInvalidPrivateIpsV4($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -211,6 +213,7 @@ public function testInvalidReservedIpsV4($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -237,6 +240,7 @@ public function testInvalidPublicIpsV4($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -259,6 +263,7 @@ public function testInvalidIpsV6($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -295,6 +300,7 @@ public function testInvalidPrivateIpsV6($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -321,6 +327,7 @@ public function testInvalidReservedIpsV6($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -346,6 +353,7 @@ public function testInvalidPublicIpsV6($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -368,6 +376,7 @@ public function testInvalidIpsAll($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -390,6 +399,7 @@ public function testInvalidPrivateIpsAll($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -412,6 +422,7 @@ public function testInvalidReservedIpsAll($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } @@ -434,6 +445,7 @@ public function testInvalidPublicIpsAll($ip) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$ip.'"') + ->setCode(Ip::INVALID_IP_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsFalseValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsFalseValidatorTest.php index a63d8466ad814..46cadecaf65af 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsFalseValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsFalseValidatorTest.php @@ -51,6 +51,7 @@ public function testTrueIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'true') + ->setCode(IsFalse::NOT_FALSE_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsNullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsNullValidatorTest.php index 885048b9bd603..5a5575313b731 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsNullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsNullValidatorTest.php @@ -47,6 +47,7 @@ public function testInvalidValues($value, $valueAsString) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $valueAsString) + ->setCode(IsNull::NOT_NULL_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IsTrueValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IsTrueValidatorTest.php index a4f0a4aaeba43..1c5927da4bf4d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IsTrueValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IsTrueValidatorTest.php @@ -51,6 +51,7 @@ public function testFalseIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'false') + ->setCode(IsTrue::NOT_TRUE_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index 6f7c3900e5351..56824b785bdbd 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -89,6 +89,7 @@ public function testInvalidLanguages($language) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$language.'"') + ->setCode(Language::NO_SUCH_LANGUAGE_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index 24b63064d0084..75a3d6ee62845 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -241,6 +241,7 @@ public function testOneCharset($value, $charset, $isValid) ->setParameter('{{ value }}', '"'.$value.'"') ->setParameter('{{ charset }}', $charset) ->setInvalidValue($value) + ->setCode(Length::INVALID_CHARACTERS_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index e5e2f3009f9f9..ad27a74e2aa70 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -91,6 +91,7 @@ public function testInvalidLocales($locale) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$locale.'"') + ->setCode(Locale::NO_SUCH_LOCALE_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php index c248246e4383e..c7c081a63beb0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php @@ -58,6 +58,7 @@ public function testNullIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'null') + ->setCode(NotBlank::IS_BLANK_ERROR) ->assertRaised(); } @@ -71,6 +72,7 @@ public function testBlankIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', '""') + ->setCode(NotBlank::IS_BLANK_ERROR) ->assertRaised(); } @@ -84,6 +86,7 @@ public function testFalseIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'false') + ->setCode(NotBlank::IS_BLANK_ERROR) ->assertRaised(); } @@ -97,6 +100,7 @@ public function testEmptyArrayIsInvalid() $this->buildViolation('myMessage') ->setParameter('{{ value }}', 'array') + ->setCode(NotBlank::IS_BLANK_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php index d338f31f797b2..a244f6382ba60 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotNullValidatorTest.php @@ -55,6 +55,9 @@ public function testNullIsInvalid() $this->validator->validate(null, $constraint); - $this->buildViolation('myMessage')->assertRaised(); + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'null') + ->setCode(NotNull::IS_NULL_ERROR) + ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php index 9b7056b548735..39266f24097db 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RangeValidatorTest.php @@ -117,7 +117,7 @@ public function testInvalidValuesMin($value, $formattedValue) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $formattedValue) ->setParameter('{{ limit }}', 10) - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->assertRaised(); } @@ -136,7 +136,7 @@ public function testInvalidValuesMax($value, $formattedValue) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $formattedValue) ->setParameter('{{ limit }}', 20) - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->assertRaised(); } @@ -157,7 +157,7 @@ public function testInvalidValuesCombinedMax($value, $formattedValue) $this->buildViolation('myMaxMessage') ->setParameter('{{ value }}', $formattedValue) ->setParameter('{{ limit }}', 20) - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->assertRaised(); } @@ -178,7 +178,7 @@ public function testInvalidValuesCombinedMin($value, $formattedValue) $this->buildViolation('myMinMessage') ->setParameter('{{ value }}', $formattedValue) ->setParameter('{{ limit }}', 10) - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->assertRaised(); } @@ -299,7 +299,7 @@ public function testInvalidDatesMin($value, $dateTimeAsString) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $dateTimeAsString) ->setParameter('{{ limit }}', 'Mar 10, 2014, 12:00 AM') - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->assertRaised(); } @@ -322,7 +322,7 @@ public function testInvalidDatesMax($value, $dateTimeAsString) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $dateTimeAsString) ->setParameter('{{ limit }}', 'Mar 20, 2014, 12:00 AM') - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->assertRaised(); } @@ -347,7 +347,7 @@ public function testInvalidDatesCombinedMax($value, $dateTimeAsString) $this->buildViolation('myMaxMessage') ->setParameter('{{ value }}', $dateTimeAsString) ->setParameter('{{ limit }}', 'Mar 20, 2014, 12:00 AM') - ->setCode(Range::BEYOND_RANGE_ERROR) + ->setCode(Range::TOO_HIGH_ERROR) ->assertRaised(); } @@ -372,7 +372,7 @@ public function testInvalidDatesCombinedMin($value, $dateTimeAsString) $this->buildViolation('myMinMessage') ->setParameter('{{ value }}', $dateTimeAsString) ->setParameter('{{ limit }}', 'Mar 10, 2014, 12:00 AM') - ->setCode(Range::BELOW_RANGE_ERROR) + ->setCode(Range::TOO_LOW_ERROR) ->assertRaised(); } @@ -397,7 +397,7 @@ public function testNonNumeric() $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"abcd"') - ->setCode(Range::INVALID_VALUE_ERROR) + ->setCode(Range::INVALID_CHARACTERS_ERROR) ->assertRaised(); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 61917e355cdda..88e69966b59ec 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -84,6 +84,7 @@ public function testInvalidValues($value) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$value.'"') + ->setCode(Regex::REGEX_FAILED_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php index 4836928014edd..51bd992d8f81d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TypeValidatorTest.php @@ -59,6 +59,7 @@ public function testEmptyIsInvalidIfNoString() $this->buildViolation('myMessage') ->setParameter('{{ value }}', '""') ->setParameter('{{ type }}', 'integer') + ->setCode(Type::INVALID_TYPE_ERROR) ->assertRaised(); } @@ -126,6 +127,7 @@ public function testInvalidValues($value, $type, $valueAsString) $this->buildViolation('myMessage') ->setParameter('{{ value }}', $valueAsString) ->setParameter('{{ type }}', $type) + ->setCode(Type::INVALID_TYPE_ERROR) ->assertRaised(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 3358c7923a98d..edc4dc8aab07b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -126,6 +126,7 @@ public function testInvalidUrls($url) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$url.'"') + ->setCode(Url::INVALID_URL_ERROR) ->assertRaised(); }