Skip to content

Commit

Permalink
allow per filter set configuration of the controller action
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Nov 27, 2011
1 parent 736052d commit 03e49d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Routing/ImagineLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
));
}
Expand Down

0 comments on commit 03e49d6

Please sign in to comment.