[AsseticBundle] removed fake front controller from URL before creating route
This commit is contained in:
parent
8ad93095d4
commit
6a227f858a
@ -15,23 +15,19 @@ 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.
|
||||
* Prepends a fake front controller so the asset knows where it is-ish.
|
||||
*
|
||||
* @author Kris Wallsmith <kris@symfony.com>
|
||||
*/
|
||||
class PrependControllerWorker implements WorkerInterface
|
||||
class UseControllerWorker 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);
|
||||
if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, '_controller/')) {
|
||||
$asset->setTargetUrl('_controller/'.$targetUrl);
|
||||
}
|
||||
|
||||
return $asset;
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<parameter key="assetic.controller.class">Symfony\Bundle\AsseticBundle\Controller\AsseticController</parameter>
|
||||
<parameter key="assetic.routing_loader.class">Symfony\Bundle\AsseticBundle\Routing\AsseticLoader</parameter>
|
||||
<parameter key="assetic.cache.class">Assetic\Cache\FilesystemCache</parameter>
|
||||
<parameter key="assetic.prepend_controller_worker.class">Symfony\Bundle\AsseticBundle\Factory\Worker\PrependControllerWorker</parameter>
|
||||
<parameter key="assetic.use_controller_worker.class">Symfony\Bundle\AsseticBundle\Factory\Worker\UseControllerWorker</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -24,7 +24,7 @@
|
||||
<service id="assetic.cache" class="%assetic.cache.class%" public="false">
|
||||
<argument>%assetic.cache_dir%/assets</argument>
|
||||
</service>
|
||||
<service id="assetic.prepend_controller_worker" class="%assetic.prepend_controller_worker.class%" public="false">
|
||||
<service id="assetic.use_controller_worker" class="%assetic.use_controller_worker.class%" public="false">
|
||||
<tag name="assetic.factory_worker" />
|
||||
</service>
|
||||
</services>
|
||||
|
@ -80,6 +80,17 @@ class AsseticLoader extends Loader
|
||||
return $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a route to serve an supplied asset.
|
||||
*
|
||||
* The fake front controller that {@link UseControllerWorker} adds to the
|
||||
* target URL will be removed before set as a route pattern.
|
||||
*
|
||||
* @param RouteCollection $routes The route collection
|
||||
* @param AssetInterface $asset The asset
|
||||
* @param string $name The name to use
|
||||
* @param integer $pos The leaf index
|
||||
*/
|
||||
private function loadRouteForAsset(RouteCollection $routes, AssetInterface $asset, $name, $pos = null)
|
||||
{
|
||||
$defaults = array(
|
||||
@ -88,7 +99,8 @@ class AsseticLoader extends Loader
|
||||
'pos' => $pos,
|
||||
);
|
||||
|
||||
$pattern = $asset->getTargetUrl();
|
||||
// remove the fake front controller
|
||||
$pattern = str_replace('_controller/', '', $asset->getTargetUrl());
|
||||
|
||||
if ($format = pathinfo($pattern, PATHINFO_EXTENSION)) {
|
||||
$defaults['_format'] = $format;
|
||||
|
Reference in New Issue
Block a user