AssetsContextPass.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. class AssetsContextPass implements CompilerPassInterface
  16. {
  17. public function process(ContainerBuilder $container)
  18. {
  19. if (!$container->hasDefinition('assets.context')) {
  20. return;
  21. }
  22. if (!$container->hasDefinition('router.request_context')) {
  23. $container->setParameter('asset.request_context.base_path', $container->getParameter('asset.request_context.base_path') ?? '');
  24. $container->setParameter('asset.request_context.secure', $container->getParameter('asset.request_context.secure') ?? false);
  25. return;
  26. }
  27. $context = $container->getDefinition('assets.context');
  28. if (null === $container->getParameter('asset.request_context.base_path')) {
  29. $context->replaceArgument(1, (new Definition('string'))->setFactory([new Reference('router.request_context'), 'getBaseUrl']));
  30. }
  31. if (null === $container->getParameter('asset.request_context.secure')) {
  32. $context->replaceArgument(2, (new Definition('bool'))->setFactory([new Reference('router.request_context'), 'isSecure']));
  33. }
  34. }
  35. }