AddClassesToCachePass.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  14. use Symfony\Component\HttpKernel\Kernel;
  15. /**
  16. * Sets the classes to compile in the cache for the container.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class AddClassesToCachePass implements CompilerPassInterface
  21. {
  22. private $kernel;
  23. public function __construct(Kernel $kernel)
  24. {
  25. $this->kernel = $kernel;
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function process(ContainerBuilder $container)
  31. {
  32. $classes = array();
  33. foreach ($container->getExtensions() as $extension) {
  34. if ($extension instanceof Extension) {
  35. $classes = array_merge($classes, $extension->getClassesToCompile());
  36. }
  37. }
  38. $this->kernel->setClassCache(array_unique($container->getParameterBag()->resolveValue($classes)));
  39. }
  40. }