TemplatingAssetHelperPass.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Bundle\FrameworkBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Definition;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. @trigger_error('The '.__NAMESPACE__.'\TemplatingAssetHelperPass class is deprecated since Symfony 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
  16. /**
  17. * @deprecated since 2.7, will be removed in 3.0
  18. */
  19. class TemplatingAssetHelperPass implements CompilerPassInterface
  20. {
  21. public function process(ContainerBuilder $container)
  22. {
  23. if (!$container->hasDefinition('templating.helper.assets')) {
  24. return;
  25. }
  26. $assetsHelperDefinition = $container->getDefinition('templating.helper.assets');
  27. $args = $assetsHelperDefinition->getArguments();
  28. if ('request' === $this->getPackageScope($container, $args[0])) {
  29. $assetsHelperDefinition->setScope('request');
  30. return;
  31. }
  32. if (!array_key_exists(1, $args)) {
  33. return;
  34. }
  35. if (!\is_array($args[1])) {
  36. return;
  37. }
  38. foreach ($args[1] as $arg) {
  39. if ('request' === $this->getPackageScope($container, $arg)) {
  40. $assetsHelperDefinition->setScope('request');
  41. break;
  42. }
  43. }
  44. }
  45. private function getPackageScope(ContainerBuilder $container, $package)
  46. {
  47. if ($package instanceof Reference) {
  48. return $container->findDefinition((string) $package)->getScope();
  49. }
  50. if ($package instanceof Definition) {
  51. return $package->getScope();
  52. }
  53. // Someone did some voodoo with a compiler pass. So we ignore this
  54. // 'package'. Can we be sure, it's a package anyway?
  55. }
  56. }