1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is a part of the Phystrix Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2013-2015 oDesk Corporation. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
namespace Odesk\Bundle\PhystrixBundle\DependencyInjection; |
21
|
|
|
|
22
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
23
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class Configuration provides schema for the bundle configuration. |
27
|
|
|
*/ |
28
|
|
|
class Configuration implements ConfigurationInterface |
29
|
|
|
{ |
30
|
|
|
public function getConfigTreeBuilder() |
31
|
|
|
{ |
32
|
|
|
$treeBuilder = new TreeBuilder(); |
33
|
|
|
$rootNode = $treeBuilder->root('phystrix'); |
34
|
|
|
|
35
|
|
|
$rootNode |
36
|
|
|
->useAttributeAsKey('name') |
37
|
|
|
->prototype('array') |
38
|
|
|
->children() |
39
|
|
|
->arrayNode('fallback')->canBeEnabled()->end() |
40
|
|
|
->arrayNode('circuitBreaker') |
41
|
|
|
->addDefaultsIfNotSet() |
42
|
|
|
->canBeEnabled() |
43
|
|
|
->children() |
44
|
|
|
->integerNode('errorThresholdPercentage')->defaultValue(50)->end() |
45
|
|
|
->integerNode('requestVolumeThreshold')->defaultValue(20)->end() |
46
|
|
|
->integerNode('sleepWindowInMilliseconds')->defaultValue(5000)->end() |
47
|
|
|
->booleanNode('forceOpen')->defaultValue(false)->end() |
48
|
|
|
->booleanNode('forceClosed')->defaultValue(false)->end() |
49
|
|
|
->end() |
50
|
|
|
->end() |
51
|
|
|
->arrayNode('metrics') |
52
|
|
|
->addDefaultsIfNotSet() |
53
|
|
|
->children() |
54
|
|
|
->integerNode('healthSnapshotIntervalInMilliseconds')->defaultValue(1000)->end() |
55
|
|
|
->integerNode('rollingStatisticalWindowInMilliseconds')->defaultValue(1000)->end() |
56
|
|
|
->integerNode('rollingStatisticalWindowBuckets')->defaultValue(10)->end() |
57
|
|
|
->end() |
58
|
|
|
->end() |
59
|
|
|
->arrayNode('requestCache')->canBeDisabled()->end() |
60
|
|
|
->arrayNode('requestLog')->canBeEnabled()->end() |
61
|
|
|
->end() |
62
|
|
|
->end() |
63
|
|
|
->validate() |
64
|
|
|
->ifTrue(function ($data) { |
65
|
|
|
return !array_key_exists('default', $data); |
66
|
|
|
}) |
67
|
|
|
->thenInvalid("'default' configuration should be set") |
68
|
|
|
->end(); |
69
|
|
|
|
70
|
|
|
return $treeBuilder; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|