-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathConfiguration.php
53 lines (47 loc) · 2 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace SmartCore\Bundle\AcceleratorCacheBundle\DependencyInjection;
use SmartCore\Bundle\AcceleratorCacheBundle\CacheClearerService;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('accelerator_cache');
$rootNode
->children()
->scalarNode('host')
->beforeNormalization()
->always(function ($v) { return $v && strncmp($v, 'http', 4) !== 0 ? 'http://'.$v : $v; })
->end()
->defaultNull()
->end()
->scalarNode('web_dir')->defaultValue('%kernel.project_dir%/web')->end()
->enumNode('mode')
->values(array(CacheClearerService::MODE_FOPEN, CacheClearerService::MODE_CURL))
->defaultValue(CacheClearerService::MODE_FOPEN)
->end()
->arrayNode('curl_opts')
->validate()
->always(function ($opts) {
foreach (array_keys($opts) as $const) {
if (!defined($const) || substr($const, 0, 8) !== 'CURLOPT_') {
throw new \InvalidArgumentException(sprintf('%s is not a valid CURLOPT option. (http://php.net/manual/en/function.curl-setopt.php)', json_encode($const)));
}
}
return $opts;
})
->end()
->defaultValue(array())
->useAttributeAsKey('name', false)
->prototype('scalar')->end()
->end()
->end()
->end();
return $treeBuilder;
}
}