AddClassesToCachePass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\DependencyInjection;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\HttpKernel\Kernel;
  14. /**
  15. * Sets the classes to compile in the cache for the container.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class AddClassesToCachePass implements CompilerPassInterface
  20. {
  21. private $kernel;
  22. public function __construct(Kernel $kernel)
  23. {
  24. $this->kernel = $kernel;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function process(ContainerBuilder $container)
  30. {
  31. $classes = array();
  32. foreach ($container->getExtensions() as $extension) {
  33. if ($extension instanceof Extension) {
  34. $classes = array_merge($classes, $extension->getClassesToCompile());
  35. }
  36. }
  37. $this->kernel->setClassCache(array_unique($container->getParameterBag()->resolveValue($classes)));
  38. }
  39. }