Skip to content

Commit 662d8f4

Browse files
committed
added support for method, ips and attributes in the rules matcher
1 parent 1163caa commit 662d8f4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

DependencyInjection/Configuration.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ private function addRulesSection(ArrayNodeDefinition $rootNode)
5151
->children()
5252
->scalarNode('unless_role')->defaultNull()->end()
5353
->scalarNode('path')->defaultNull()->info('URL path info')->end()
54+
->arrayNode('method')
55+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
56+
->useAttributeAsKey('name')
57+
->prototype('scalar')->end()
58+
->info('HTTP method')
59+
->end()
60+
->arrayNode('ips')
61+
->beforeNormalization()->ifString()->then(function($v) { return preg_split('/\s*,\s*/', $v); })->end()
62+
->useAttributeAsKey('name')
63+
->prototype('scalar')->end()
64+
->info('List of ips')
65+
->end()
66+
->arrayNode('attributes')
67+
->addDefaultsIfNotSet()
68+
->cannotBeEmpty()
69+
->treatNullLike(array())
70+
->info('Request attributes')
71+
->end()
5472
->scalarNode('domain')->defaultNull()->info('depreciated, use host instead')->end()
5573
->scalarNode('host')->defaultNull()->info('URL host name')->end()
5674
->scalarNode('controller')->defaultNull()->info('controller action name')->end()

DependencyInjection/LiipCacheControlExtension.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ public function load(array $configs, ContainerBuilder $container)
3939
$container,
4040
$cache['path'],
4141
$host,
42+
$cache['method'],
43+
$cache['ips'],
44+
$cache['attributes'],
4245
$cache['controller']
4346
);
4447

4548
unset(
4649
$cache['path'],
50+
$cache['method'],
51+
$cache['ips'],
52+
$cache['attributes'],
4753
$cache['domain'],
4854
$cache['host'],
4955
$cache['controller']
@@ -82,11 +88,13 @@ public function load(array $configs, ContainerBuilder $container)
8288
}
8389
}
8490

85-
protected function createRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $controller = null)
91+
protected function createRequestMatcher(ContainerBuilder $container, $path = null, $host = null, $methods = null, $ips = null, array $attributes = array(), $controller = null)
8692
{
87-
$attributes = is_null($controller) ? array() : array('_controller' => $controller);
93+
if (null !== $controller) {
94+
$attributes['_controller'] = $controller;
95+
}
8896

89-
$arguments = array($path, $host, null, null, $attributes);
97+
$arguments = array($path, $host, $methods, $ips, $attributes);
9098
$serialized = serialize($arguments);
9199
$id = $this->getAlias().'.request_matcher.'.md5($serialized).sha1($serialized);
92100

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ liip_cache_control:
5858

5959
The matches are tried from top to bottom, the first match is taken and applied.
6060

61+
Run ``app/console config:dump-reference liip_cache_control`` to get the full list of configuration options.
6162

6263
About the path parameter
6364
------------------------

0 commit comments

Comments
 (0)