1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AnimeDb package |
4
|
|
|
* |
5
|
|
|
* @package AnimeDb |
6
|
|
|
* @author Peter Gribanov <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2014, Peter Gribanov |
8
|
|
|
* @license http://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\DependencyInjection; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
14
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* DI Configuration |
18
|
|
|
* |
19
|
|
|
* @package AnimeDb\Bundle\CacheTimeKeeperBundle\DependencyInjection |
20
|
|
|
* @author Peter Gribanov <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $shmop_salt = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $file_path = ''; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $shmop_salt |
36
|
|
|
* @param string $file_path |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct($shmop_salt, $file_path) |
39
|
|
|
{ |
40
|
1 |
|
$this->shmop_salt = $shmop_salt; |
41
|
1 |
|
$this->file_path = $file_path; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return TreeBuilder |
46
|
|
|
*/ |
47
|
1 |
|
public function getConfigTreeBuilder() |
48
|
|
|
{ |
49
|
1 |
|
$treeBuilder = new TreeBuilder(); |
50
|
1 |
|
$rootNode = $treeBuilder->root('anime_db_cache_time_keeper'); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Example config: |
54
|
|
|
* |
55
|
|
|
* anime_db_cache_time_keeper: |
56
|
|
|
* use_driver: file |
57
|
|
|
* drivers: |
58
|
|
|
* multi: |
59
|
|
|
* fast: shmop |
60
|
|
|
* slow: file |
61
|
|
|
* shmop: |
62
|
|
|
* salt: '%secret%' |
63
|
|
|
* file: |
64
|
|
|
* path: '%kernel.root_dir%/cache/cache-time-keeper/' |
65
|
|
|
* memcached: |
66
|
|
|
* prefix: 'cache_time_keeper_' |
67
|
|
|
* persistent_id: 'cache_time_keeper' |
68
|
|
|
* hosts: |
69
|
|
|
* - {host: 'localhost', port: 11211, weight: 100} |
70
|
|
|
*/ |
71
|
|
|
$rootNode |
72
|
1 |
|
->children() |
73
|
1 |
|
->scalarNode('use_driver') |
74
|
1 |
|
->cannotBeEmpty() |
75
|
1 |
|
->defaultValue('file') |
76
|
1 |
|
->end() |
77
|
1 |
|
->arrayNode('drivers') |
78
|
1 |
|
->children() |
79
|
1 |
|
->arrayNode('multi') |
80
|
1 |
|
->children() |
81
|
1 |
|
->scalarNode('fast') |
82
|
1 |
|
->cannotBeEmpty() |
83
|
1 |
|
->defaultValue('shmop') |
84
|
1 |
|
->end() |
85
|
1 |
|
->scalarNode('slow') |
86
|
1 |
|
->cannotBeEmpty() |
87
|
1 |
|
->defaultValue('file') |
88
|
1 |
|
->end() |
89
|
1 |
|
->end() |
90
|
1 |
|
->end() // multi |
91
|
1 |
|
->arrayNode('shmop') |
92
|
1 |
|
->children() |
93
|
1 |
|
->scalarNode('salt') |
94
|
1 |
|
->cannotBeEmpty() |
95
|
1 |
|
->defaultValue($this->shmop_salt) |
96
|
1 |
|
->end() |
97
|
1 |
|
->end() |
98
|
1 |
|
->end() // shmop |
99
|
1 |
|
->arrayNode('file') |
100
|
1 |
|
->children() |
101
|
1 |
|
->scalarNode('path') |
102
|
1 |
|
->cannotBeEmpty() |
103
|
1 |
|
->defaultValue($this->file_path) |
104
|
1 |
|
->end() |
105
|
1 |
|
->end() |
106
|
1 |
|
->end() // file |
107
|
1 |
|
->arrayNode('memcached') |
108
|
1 |
|
->children() |
109
|
1 |
|
->scalarNode('prefix') |
110
|
1 |
|
->defaultValue('cache_time_keeper_') |
111
|
1 |
|
->end() |
112
|
1 |
|
->scalarNode('persistent_id') |
113
|
1 |
|
->defaultValue('cache_time_keeper') |
114
|
1 |
|
->info( |
115
|
|
|
'Specify to enable persistent connections. '. |
116
|
|
|
'All clients with the same ID share connections.' |
117
|
1 |
|
) |
118
|
1 |
|
->end() |
119
|
1 |
|
->arrayNode('hosts') |
120
|
1 |
|
->requiresAtLeastOneElement() |
121
|
1 |
|
->prototype('array') |
122
|
1 |
|
->children() |
123
|
1 |
|
->scalarNode('host') |
124
|
1 |
|
->cannotBeEmpty() |
125
|
1 |
|
->defaultValue('localhost') |
126
|
1 |
|
->end() |
127
|
1 |
|
->scalarNode('port') |
128
|
1 |
|
->cannotBeEmpty() |
129
|
1 |
|
->defaultValue(11211) |
130
|
1 |
|
->validate() |
131
|
|
|
->ifTrue(function($v) { |
132
|
|
|
return !is_numeric($v); |
133
|
1 |
|
}) |
134
|
1 |
|
->thenInvalid('Host port must be numeric') |
135
|
1 |
|
->end() |
136
|
1 |
|
->end() |
137
|
1 |
|
->scalarNode('weight') |
138
|
1 |
|
->defaultValue(0) |
139
|
1 |
|
->validate() |
140
|
1 |
|
->ifTrue(function ($v) { |
141
|
|
|
return !is_numeric($v); |
142
|
1 |
|
}) |
143
|
1 |
|
->thenInvalid('Host weight must be numeric') |
144
|
1 |
|
->end() |
145
|
1 |
|
->end() |
146
|
1 |
|
->end() |
147
|
1 |
|
->end() |
148
|
1 |
|
->end() |
149
|
1 |
|
->end() |
150
|
1 |
|
->end() // memcached |
151
|
1 |
|
->end() |
152
|
1 |
|
->end() // drivers |
153
|
1 |
|
->end() |
154
|
|
|
; |
155
|
|
|
|
156
|
1 |
|
return $treeBuilder; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|