Permalink
Browse files

make it possible to extend the ImagineController

  • Loading branch information...
1 parent 043b777 commit 806c07b97bd92d204878342565e4864b1ee1347c @lsmith77 lsmith77 committed Nov 18, 2011
@@ -13,17 +13,17 @@ class ImagineController
/**
* @var DataManager
*/
- private $dataManager;
+ protected $dataManager;
/**
* @var FilterManager
*/
- private $filterManager;
+ protected $filterManager;
/**
* @var CacheManager
*/
- private $cacheManager;
+ protected $cacheManager;
/**
* Constructor
@@ -31,6 +31,7 @@ public function getConfigTreeBuilder()
->scalarNode('cache_prefix')->defaultValue('/media/cache')->end()
->scalarNode('cache')->defaultValue('web_path')->end()
->scalarNode('data_loader')->defaultValue('filesystem')->end()
+ ->scalarNode('controller_action')->defaultValue('liip_imagine.controller:filterAction')->end()
->arrayNode('formats')
->defaultValue(array())
->prototype('scalar')->end()
@@ -37,5 +37,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('liip_imagine.filter_sets', $config['filter_sets']);
$container->setParameter('liip_imagine.data.loader.default', $config['data_loader']);
+
+ $container->setParameter('liip_imagine.controller_action', $config['controller_action']);
}
}
View
@@ -167,7 +167,8 @@ liip_imagine:
web_root: %kernel.root_dir%/../web
cache_prefix: /media/cache
cache: true
- loader: ~
+ data_loader: ~
+ controller_action: ~
driver: gd
formats: []
filter_sets: []
@@ -196,6 +197,10 @@ There are several configuration options available:
default: filesystem (which means the standard filesystem loader is used)
+ - `controller_action` - name of the controller action to use in the route loader
+
+ default: liip_imagine.controller:filterAction
+
- `driver` - one of the three drivers: `gd`, `imagick`, `gmagick`
default: `gd`
@@ -83,6 +83,7 @@
<service id="liip_imagine.routing.loader" class="%liip_imagine.routing.loader.class%">
<tag name="routing.loader" />
+ <argument>%liip_imagine.controller_action%</argument>
<argument>%liip_imagine.cache_prefix%</argument>
<argument>%liip_imagine.filter_sets%</argument>
</service>
@@ -9,13 +9,15 @@
class ImagineLoader extends Loader
{
+ private $controllerAction;
private $cachePrefix;
private $filters;
- public function __construct($cachePrefix, array $filters = array())
+ public function __construct($controllerAction, $cachePrefix, array $filters = array())
{
+ $this->controllerAction = $controllerAction;
$this->cachePrefix = $cachePrefix;
- $this->filters = $filters;
+ $this->filters = $filters;
}
public function supports($resource, $type = null)
@@ -26,7 +28,7 @@ public function supports($resource, $type = null)
public function load($resource, $type = null)
{
$requirements = array('_method' => 'GET', 'filter' => '[A-z0-9_\-]*', 'path' => '.+');
- $defaults = array('_controller' => 'liip_imagine.controller:filterAction');
+ $defaults = array('_controller' => $this->controllerAction);
$routes = new RouteCollection();
if (count($this->filters) > 0) {

3 comments on commit 806c07b

Owner

lsmith77 replied Nov 27, 2011

this allows you to also customize the method name. but actually i forgot to also add this as a per filter set option. this would allow you to handle different filters with different methods.

Owner

lsmith77 replied Nov 27, 2011

just added this in 03e49d6

Owner

lsmith77 replied Nov 27, 2011

btw .. overriding a service requires that either the bundle that does the overriding is registered after the original one or a compiler pass is used. this way its cleaner.

Please sign in to comment.