Skip to content

Commit

Permalink
Merge pull request #138 from sveriger/add_route_options
Browse files Browse the repository at this point in the history
Add route options to routing loader
  • Loading branch information
havvg committed Feb 8, 2013
2 parents 42c20c6 + 19962ce commit c00512c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration.php
Expand Up @@ -51,6 +51,14 @@ public function getConfigTreeBuilder()
->scalarNode('cache')->defaultNull()->end()
->scalarNode('data_loader')->defaultNull()->end()
->scalarNode('controller_action')->defaultNull()->end()
->arrayNode('route')
->defaultValue(array())
->useAttributeAsKey('name')
->prototype('array')
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->end()
->arrayNode('filters')
->useAttributeAsKey('name')
->prototype('array')
Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -184,6 +184,7 @@ liip_imagine:
cache: ~
data_loader: ~
controller_action: ~
route: []
filters:

# Prototype
Expand Down Expand Up @@ -250,6 +251,10 @@ Each filter set that you specify has the following options:
- `cache` - override the default cache setting
- `data_loader` - override the default data loader
- `controller_action` - override the default controller action
- `route` - optional list of route requirements, defaults and options using in the route loader. Add array with keys 'requirements', 'defaults' or 'options'.

default: empty array

- `format` - hardcodes the output format (aka the requested format is ignored)

## Built-in Filters
Expand Down
19 changes: 17 additions & 2 deletions Routing/ImagineLoader.php
Expand Up @@ -46,10 +46,25 @@ public function load($resource, $type = null)
'filter' => $filter,
);

$routeRequirements = $requirements;
$routeDefaults = $defaults;
$routeOptions = array();

if (isset($config['route']['requirements'])) {
$routeRequirements = array_merge($routeRequirements, $config['route']['requirements']);
}
if (isset($config['route']['defaults'])) {
$routeDefaults = array_merge($routeDefaults, $config['route']['defaults']);
}
if (isset($config['route']['options'])) {
$routeOptions = array_merge($routeOptions, $config['route']['options']);
}

$routes->add('_imagine_'.$filter, new Route(
$pattern.'/{path}',
$defaults,
$requirements
$routeDefaults,
$routeRequirements,
$routeOptions
));
}
}
Expand Down
17 changes: 15 additions & 2 deletions Tests/DependencyInjection/LiipImagineExtensionTest.php
Expand Up @@ -69,7 +69,18 @@ public function testCacheClearerIsNotRegistered()

$this->assertFalse($this->containerBuilder->hasDefinition('liip_imagine.cache.clearer'));
}


public function testCustomRouteRequirements()
{
$this->createFullConfiguration();
$param = $this->containerBuilder->getParameter('liip_imagine.filter_sets');

$this->assertTrue(isset($param['small']['filters']['route']['requirements']));

$variable1 = $param['small']['filters']['route']['requirements']['variable1'];
$this->assertEquals('value1', $variable1, sprintf('%s parameter is correct', $variable1));
}

/**
* @return ContainerBuilder
*/
Expand All @@ -80,7 +91,7 @@ protected function createEmptyConfiguration()
$loader->load(array(array()), $this->containerBuilder);
$this->assertTrue($this->containerBuilder instanceof ContainerBuilder);
}

/**
* @return ContainerBuilder
*/
Expand All @@ -105,6 +116,8 @@ protected function getFullConfig()
small:
filters:
thumbnail: { size: [100, ~], mode: inset }
route:
requirements: { variable1: 'value1' }
quality: 80
medium_small_cropped:
filters:
Expand Down

0 comments on commit c00512c

Please sign in to comment.