CachedCiviContainer generated with Symfony 4 removes private services
Overview
When using Symfony 4.4, private services & aliases are removed from the generated CachedCiviContainer.*.php
file making them missing/unavailable.
Reproduction steps
- Set up a Drupal 9 site using composer (requires
symfony/dependency-injection
and other Symfony packages with version ^4.4). (I know Drupal 9 isn't officially supported yet, but civicrm-core does claim it can use Symfony ~3.0 || ~4.4 and I think Symfony is the problem here) - Follow instructions from "Install CiviCRM on Drupal 8" documentation to add/install CiviCRM.
- If you look at the
CachedCiviContainer.*.php
file generated in thetemplates_c
folder, you can see$this->privates
and$this->aliases
are empty arrays, whereas with Symfony 3 there was a 'cache.short' alias and a number of private services that are now missing. - Visit
.../civicrm/admin/extensions?reset=1
page and it will break.
Current behaviour
When visiting .../civicrm/admin/extensions?reset=1
page:
The "cache.short" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.
There are probably other pages/actions that try & fail to use one of the services/alias that were removed, but this is the one I found.
Expected behaviour
Page should load without error!
Environment information
- CiviCRM: 5.29.0
- PHP: 7.3
- CMS: Drupal 9.0.5
- Database: MariaDB 10.4
- Web Server: Nginx
Comments
I believe Symfony 4 may remove these private services/alias with RemoveUnusedDefinitionsPass
because they look "unused"? The error message offers a solution, make these services/alias public or "stop using the container directly and use dependency injection instead". I'm not sure what the implications of making them public are, or how much work would be involved in using dependency injection.