DependencySerializationTraitPass.php 879 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Drupal\Core\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. /**
  6. * Sets the _serviceId property on all services.
  7. *
  8. * @see \Drupal\Core\DependencyInjection\DependencySerializationTrait
  9. */
  10. class DependencySerializationTraitPass implements CompilerPassInterface {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function process(ContainerBuilder $container) {
  15. foreach ($container->getDefinitions() as $service_id => $definition) {
  16. // Only add the property to services that are public (as private services
  17. // can not be reloaded through Container::get()) and are objects.
  18. if (!$definition->hasTag('parameter_service') && $definition->isPublic()) {
  19. $definition->setProperty('_serviceId', $service_id);
  20. }
  21. }
  22. }
  23. }