From 6c4a676d099558ebaa1d59b119a1246adea9228c Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Sun, 14 Jun 2015 23:41:59 -0300 Subject: [PATCH] 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 a58bb1834fe3..966f1f471113 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 bba5055d0085..076484567aae 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 1e0209760eb0..b37bf7b87575 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 5981a700c77a..57780d2e52fd 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 8231c874779d..8f5437146bb5 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 691683206077..024da4d3b94c 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 e62c71a2a018..c9e6f7eb731a 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 4e609a06e5d9..428ba0c8ee48 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 047f4e8c16a4..9be35dad0705 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 1c3b958bd92c..de404d24d0f5 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 b21190dc7983..59a1e85c6bb8 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 3397fd67acd6..c76d13ee4234 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 b3018b80b7f3..3a3de41c409e 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 7aecc4f629e7..5ceee2772a99 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 53bf114e81e0..40a3da00963a 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 56a2c390779a..c0d4f11e3326 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 d6ac0b750b16..51bb9c254f54 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 3837b95cb89e..6844d2d18076 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 6577037f9c00..551c9cb24b29 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 be9d2f015bd2..01f324860885 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 8de781dfc45a..92f1300b4bd5 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 68d3569732c6..6c18a6c2bbf8 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 af495497dd35..4c37faccf29a 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 92a9bbd70bd3..ec8a8cefa9e4 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 9d58434c17e1..22a094928a48 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 6b2f14651d30..866858799427 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 28a00d583b09..62fc7d2dc6c3 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 f128e522e599..ce9b1d05220c 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 6372d9e5b56d..b7a5dec87df7 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 d9832a1511ab..f527ab9ff874 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 3d9cbb2077c3..09340efcf5d8 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 75d082024457..6088d9a21b5a 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 278a5bfed413..bb0f5685f36a 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 f552debbf18b..43227638d88a 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 28a00d583b09..62fc7d2dc6c3 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 dd3e2e06d717..7a2154487d1e 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 d76d8fd629bb..04d41752c83e 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 e1e2b0e88393..2b97bd5a6638 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 94847e822be5..0bab4dbcbbec 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 132315fd23c8..00d17cee42ac 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 9f35827ecba3..7c4ff51e8cdd 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 219e66313d13..e54ee60abbca 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 3d4988d2e665..b4526edec84b 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 026700d2263d..c3c4ef5fd654 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 0efc6b500b5d..daaee8159d48 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 c90d76f48adf..3111d7f0916a 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 f0db5de6bc4e..2b9fc5f4877a 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 e697814bb10f..5ac89cde5731 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 19e800b3144d..39683a6d6675 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 71447fab12ae..e68e8b3cb813 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 5f35a1e5bb11..70e19af52f55 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 9c2b6dd54d3c..d3347a03c41c 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 40486c459554..1f9183f418de 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 832929cd049c..e1a5709dd32e 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 523c01cea493..93bb3a139d05 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 e10cfe2a4bce..c0239c2f90bf 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 ac2cba7a80ce..11f869c04ac2 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 88084880f80c..6bb117abb67c 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 161229e44bc5..c97c88758474 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 81ac67cc4d57..69d57685a248 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 4e8efdc8b4fa..e0639825f009 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 cd4448a96abf..45cf279e374a 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 590ca4cfae2f..038843416327 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 fb2bb5fca305..0060b35e9a59 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 72058868d44e..498baf82fc98 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 8155e0b7c6b8..7e5564c92b0e 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 dd8358e92996..603269ccc696 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 b501f1183901..4bac0e2a0baf 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 5da11359fa8b..1b75712b7952 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 e97a2dda69cc..d9b65a43fe26 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 9f4210c9d5b7..22dc44a4e431 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 4e8dfb977495..ce52c6dcd01c 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 708e10fd5dcd..c8e6e30bc9db 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 5692ba13ea20..dc55972a287e 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 9eb7b8915e62..a1a320bd826d 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 c4ddc416b463..f1e6e98efaf6 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 46ac679940e1..2e702bff2f89 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 64d17262aa30..6a5f03d9b87e 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 78abf4d15552..2186620045cc 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 fdab85fc7e05..ddb5d3a96abd 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 8bf524ae4f32..581dc675fb3f 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 28cf0ebf6252..058f5b66dffd 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 6f2fbcb9df9a..18a4b3f794af 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();