|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; |
| 13 | + |
| 14 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 15 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 16 | +use Symfony\Component\DependencyInjection\Definition; |
| 17 | +use Symfony\Component\DependencyInjection\Reference; |
| 18 | + |
| 19 | +class AssetsContextPass implements CompilerPassInterface |
| 20 | +{ |
| 21 | + public function process(ContainerBuilder $container) |
| 22 | + { |
| 23 | + if (!$container->hasDefinition('assets.context')) { |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + if (!$container->hasDefinition('router.request_context')) { |
| 28 | + $container->setParameter('asset.request_context.base_path', $container->getParameter('asset.request_context.base_path') ?? ''); |
| 29 | + $container->setParameter('asset.request_context.secure', $container->getParameter('asset.request_context.secure') ?? false); |
| 30 | + |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + $context = $container->getDefinition('assets.context'); |
| 35 | + |
| 36 | + if (null === $container->getParameter('asset.request_context.base_path')) { |
| 37 | + $context->replaceArgument(1, (new Definition('string'))->setFactory([new Reference('router.request_context'), 'getBaseUrl'])); |
| 38 | + } |
| 39 | + |
| 40 | + if (null === $container->getParameter('asset.request_context.secure')) { |
| 41 | + $context->replaceArgument(2, (new Definition('bool'))->setFactory([new Reference('router.request_context'), 'isSecure'])); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments