Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add route options to routing loader #138

Merged
merged 3 commits into from
Feb 8, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 width keys 'requirements', 'defaults' or 'options'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Add array width should be Add array with


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
Original file line number Diff line number Diff line change
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'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code convention: Please add a space between if and (.

$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
Original file line number Diff line number Diff line change
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