From 765daeac4eba0e3ab1732d8cc424af026b4482d7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 1 Nov 2019 19:30:17 -0700 Subject: [PATCH] Civi\Core\Container - Fix warning about Symfony 3=>4 and boot services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Boot services are initialized before the container starts -- and then passed in via `$container->set()`. Symfony 3.4 changes the default handling of `set()` - it now emits warnings unless the services were previously flagged as public. https://symfony.com/blog/new-in-symfony-3-4-services-are-private-by-default Before ------ ``` [bknix-min:~/bknix/build/d8re] drush php Psy Shell v0.9.9 (PHP 7.0.32 — cli) by Justin Hileman >>> \Drupal::service('civicrm')->initialize(); PHP Deprecated: The "runtime" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "paths" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "userSystem" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "userPermissionClass" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "cache.settings" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "settings_manager" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 PHP Deprecated: The "lockManager" service is private, replacing it is deprecated since Symfony 3.2 and will fail in 4.0. in /Users/totten/bknix/build/d8re/vendor/symfony/dependency-injection/Container.php on line 190 ``` After ----- The warnings don't appear. Comments -------- The `Definition` class includes two methods, `setPublic()` and `setPrivate()`, which appear to do the same thing (but as opposites). `setPublic()` exists Symfony 2.8+, but `setPrivate()` was added in Symfony 3.x, so we use `setPublic()` for broader compatibility. --- Civi/Core/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 1d1af901bf6..15deda8e29f 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -214,7 +214,7 @@ public function createContainer() { throw new \RuntimeException("Cannot initialize container. Boot services are undefined."); } foreach (\Civi::$statics[__CLASS__]['boot'] as $bootService => $def) { - $container->setDefinition($bootService, new Definition())->setSynthetic(TRUE); + $container->setDefinition($bootService, new Definition())->setSynthetic(TRUE)->setPublic(TRUE); } // Expose legacy singletons as services in the container.