diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php new file mode 100644 index 000000000000..81862ba17e37 --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php @@ -0,0 +1,37 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Factory\Worker; + +use Assetic\Asset\AssetInterface; +use Assetic\Factory\Worker\WorkerInterface; + +/** + * Prepends a fake front controller to every asset's target URL. + * + * This worker should only be added when the use_controller configuration + * option is true. It changes the target URL to include the front controller. + * + * @author Kris Wallsmith + */ +class PrependControllerWorker implements WorkerInterface +{ + const CONTROLLER = 'front_controller/'; + + public function process(AssetInterface $asset) + { + $targetUrl = $asset->getTargetUrl(); + + if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, self::CONTROLLER)) { + $asset->setTargetUrl(self::CONTROLLER.$targetUrl); + } + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml index 65a65732c2c6..4b56f8fcb60f 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml @@ -8,6 +8,7 @@ Symfony\Bundle\AsseticBundle\Controller\AsseticController Symfony\Bundle\AsseticBundle\Routing\AsseticLoader Assetic\Cache\FilesystemCache + Symfony\Bundle\AsseticBundle\Factory\Worker\PrependControllerWorker @@ -23,5 +24,8 @@ %assetic.cache_dir%/assets + + +