diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index bc76ce28f0cd1..1499d050370aa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -30,13 +30,15 @@ class Client extends BaseClient private $hasPerformedRequest = false; private $profiler = false; private $reboot = true; + private $container; /** * {@inheritdoc} */ - public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null) + public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, ContainerInterface $container = null) { parent::__construct($kernel, $server, $history, $cookieJar); + $this->container = $container; } /** @@ -46,7 +48,7 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi */ public function getContainer() { - return $this->kernel->getContainer(); + return $this->container ?? $this->kernel->getContainer(); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php new file mode 100644 index 0000000000000..9e36a80d00ce6 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * @author Nicolas Grekas
+ */ +class TestServiceContainerRealRefPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('test.service_container')) { + return; + } + + $testContainer = $container->getDefinition('test.service_container'); + $privateContainer = $container->getDefinition((string) $testContainer->getArgument(2)); + $definitions = $container->getDefinitions(); + + foreach ($privateContainer->getArgument(0) as $id => $argument) { + if (isset($definitions[$target = (string) $argument->getValues()[0]])) { + $argument->setValues(array(new Reference($target))); + } + } + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerWeakRefPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerWeakRefPass.php new file mode 100644 index 0000000000000..b704bf54e48a5 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerWeakRefPass.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +/** + * @author Nicolas Grekas
+ */
+class TestServiceContainerWeakRefPass implements CompilerPassInterface
+{
+ public function process(ContainerBuilder $container)
+ {
+ if (!$container->hasDefinition('test.service_container')) {
+ return;
+ }
+
+ $privateServices = array();
+ $definitions = $container->getDefinitions();
+
+ foreach ($definitions as $id => $definition) {
+ if (!$definition->isPublic() && !$definition->getErrors() && !$definition->isAbstract()) {
+ $privateServices[$id] = new ServiceClosureArgument(new Reference($id, ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE));
+ }
+ }
+
+ $aliases = $container->getAliases();
+
+ foreach ($aliases as $id => $alias) {
+ if (!$alias->isPublic()) {
+ while (isset($aliases[$target = (string) $alias])) {
+ $alias = $aliases[$target];
+ }
+ if (isset($definitions[$target]) && !$definitions[$target]->getErrors() && !$definitions[$target]->isAbstract()) {
+ $privateServices[$id] = new ServiceClosureArgument(new Reference($target, ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE));
+ }
+ }
+ }
+
+ if ($privateServices) {
+ $definitions[(string) $definitions['test.service_container']->getArgument(2)]->replaceArgument(0, $privateServices);
+ }
+ }
+}
diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
index f25bb71240b9b..9511c4bc61ce0 100644
--- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
@@ -23,6 +23,8 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
use Symfony\Component\Console\Application;
@@ -114,6 +116,8 @@ public function build(ContainerBuilder $container)
$this->addCompilerPassIfExists($container, FormPass::class);
$container->addCompilerPass(new WorkflowGuardListenerPass());
$container->addCompilerPass(new ResettableServicePass());
+ $container->addCompilerPass(new TestServiceContainerWeakRefPass(), PassConfig::TYPE_BEFORE_REMOVING, -32);
+ $container->addCompilerPass(new TestServiceContainerRealRefPass(), PassConfig::TYPE_AFTER_REMOVING);
if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
index ff109c4cd2420..d7aab2e068a58 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml
@@ -16,6 +16,7 @@
+ */ +class TestContainer extends Container +{ + private $publicContainer; + private $privateContainer; + + public function __construct(?ParameterBagInterface $parameterBag, SymfonyContainerInterface $publicContainer, PsrContainerInterface $privateContainer) + { + $this->parameterBag = $parameterBag ?? $publicContainer->getParameterBag(); + $this->publicContainer = $publicContainer; + $this->privateContainer = $privateContainer; + } + + /** + * {@inheritdoc} + */ + public function compile() + { + $this->publicContainer->compile(); + } + + /** + * {@inheritdoc} + */ + public function isCompiled() + { + return $this->publicContainer->isCompiled(); + } + + /** + * {@inheritdoc} + */ + public function set($id, $service) + { + $this->publicContainer->set($id, $service); + } + + /** + * {@inheritdoc} + */ + public function has($id) + { + return $this->publicContainer->has($id) || $this->privateContainer->has($id); + } + + /** + * {@inheritdoc} + */ + public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1) + { + return $this->privateContainer->has($id) ? $this->privateContainer->get($id) : $this->publicContainer->get($id, $invalidBehavior); + } + + /** + * {@inheritdoc} + */ + public function initialized($id) + { + return $this->publicContainer->initialized($id); + } + + /** + * {@inheritdoc} + */ + public function reset() + { + $this->publicContainer->reset(); + } + + /** + * {@inheritdoc} + */ + public function getServiceIds() + { + return $this->publicContainer->getServiceIds(); + } + + /** + * {@inheritdoc} + */ + public function getRemovedIds() + { + return $this->publicContainer->getRemovedIds(); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/PropertyInfoTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/PropertyInfoTest.php index f98072ce7b39c..6adde224275b4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/PropertyInfoTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/PropertyInfoTest.php @@ -18,9 +18,8 @@ class PropertyInfoTest extends WebTestCase public function testPhpDocPriority() { static::bootKernel(array('test_case' => 'Serializer')); - $container = static::$kernel->getContainer(); - $this->assertEquals(array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT))), $container->get('test.property_info')->getTypes('Symfony\Bundle\FrameworkBundle\Tests\Functional\Dummy', 'codes')); + $this->assertEquals(array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT))), static::$container->get('property_info')->getTypes('Symfony\Bundle\FrameworkBundle\Tests\Functional\Dummy', 'codes')); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml index e4090041bb196..cac135c315d00 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml @@ -1,10 +1,6 @@ imports: - { resource: ../config/default.yml } -services: - _defaults: { public: true } - test.property_info: '@property_info' - framework: serializer: { enabled: true } property_info: { enabled: true } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml index a313b3339a089..84c6e64e2a918 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml @@ -4,7 +4,7 @@ framework: validation: { enabled: true, enable_annotations: true } csrf_protection: true form: true - test: ~ + test: true default_locale: en session: storage_id: session.storage.mock_file
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: