Civi\Core\Container - Fix warning about Symfony 3=>4 and boot services
authorTim Otten <totten@civicrm.org>
Sat, 2 Nov 2019 02:30:17 +0000 (19:30 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 2 Nov 2019 02:30:17 +0000 (19:30 -0700)
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

index 1d1af901bf6898401bd877984f8905050de6a327..15deda8e29f91dfc67a56d235b63ffe7bee76ff7 100644 (file)
@@ -214,7 +214,7 @@ class Container {
       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.