From 03e49d67731c68ab7f9d4cb2a4e1b87d3a1ef332 Mon Sep 17 00:00:00 2001 From: lsmith77 Date: Sun, 27 Nov 2011 12:51:50 +0100 Subject: [PATCH] allow per filter set configuration of the controller action --- DependencyInjection/Configuration.php | 3 ++- README.md | 2 ++ Routing/ImagineLoader.php | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 787c63635..179d4cb8d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -45,8 +45,9 @@ public function getConfigTreeBuilder() ->scalarNode('path')->end() ->scalarNode('quality')->defaultValue(100)->end() ->scalarNode('format')->defaultNull()->end() - ->scalarNode('data_loader')->defaultNull()->end() ->scalarNode('cache')->defaultNull()->end() + ->scalarNode('data_loader')->defaultNull()->end() + ->scalarNode('controller_action')->defaultNull()->end() ->arrayNode('filters') ->useAttributeAsKey('name') ->prototype('array') diff --git a/README.md b/README.md index 9bb8db644..fe44a0498 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,9 @@ Each filter set that you specify has the following options: and options that should be passed to the specific filter type - `path` - used in place of the filter name to determine the path in combination with the global `cache_prefix` - `quality` - override the default quality of 100 for the generated images + - `cache` - override the default cache setting - `data_loader` - override the default data loader + - `controller_action` - override the default controller action - `format` - hardcodes the output format (aka the requested format is ignored) ## Built-in Filters diff --git a/Routing/ImagineLoader.php b/Routing/ImagineLoader.php index 46aefb6f9..bd6bbfdcd 100644 --- a/Routing/ImagineLoader.php +++ b/Routing/ImagineLoader.php @@ -28,7 +28,6 @@ public function supports($resource, $type = null) public function load($resource, $type = null) { $requirements = array('_method' => 'GET', 'filter' => '[A-z0-9_\-]*', 'path' => '.+'); - $defaults = array('_controller' => $this->controllerAction); $routes = new RouteCollection(); if (count($this->filters) > 0) { @@ -42,9 +41,14 @@ public function load($resource, $type = null) $pattern .= '/'.$filter; } + $defaults = array( + '_controller' => empty($config['controller_action']) ? $this->controllerAction : $config['controller_action'], + 'filter' => $filter, + ); + $routes->add('_imagine_'.$filter, new Route( $pattern.'/{path}', - array_merge( $defaults, array('filter' => $filter)), + $defaults, $requirements )); }