1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 Inneair |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
* |
18
|
|
|
* @license http://www.apache.org/licenses/LICENSE-2.0.html Apache-2.0 |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Inneair\TransactionBundle\DependencyInjection; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
24
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This class validates and merges configuration from the app/config files. |
28
|
|
|
*/ |
29
|
|
|
class Configuration implements ConfigurationInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Configuration key for the default policy. |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
const DEFAULT_POLICY = 'default_policy'; |
36
|
|
|
/** |
37
|
|
|
* Configuration value for default not-required transaction policy. |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
const POLICY_NOT_REQUIRED = 'not-required'; |
41
|
|
|
/** |
42
|
|
|
* Configuration value for default required transaction policy. |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
const POLICY_REQUIRED = 'required'; |
46
|
|
|
/** |
47
|
|
|
* Configuration value for default nested transaction policy. |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
const POLICY_NESTED = 'nested'; |
51
|
|
|
/** |
52
|
|
|
* Configuration key for the root node. |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
const ROOT_NODE_NAME = 'inneair_transaction'; |
56
|
|
|
/** |
57
|
|
|
* Configuration key for the strict mode. |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
const STRICT_MODE = 'strict_mode'; |
61
|
|
|
/** |
62
|
|
|
* Configuration key for exceptions ignored for rollback. |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
const NO_ROLLBACK_EXCEPTIONS = 'no_rollback_exceptions'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritDoc} |
69
|
|
|
*/ |
70
|
10 |
|
public function getConfigTreeBuilder() |
71
|
|
|
{ |
72
|
10 |
|
$treeBuilder = new TreeBuilder(); |
73
|
10 |
|
$rootNode = $treeBuilder->root(static::ROOT_NODE_NAME); |
74
|
10 |
|
$rootNode->fixXmlConfig('no_rollback_exception')->children() |
75
|
10 |
|
->booleanNode(static::STRICT_MODE) |
76
|
|
|
//->cannotBeEmpty() |
77
|
10 |
|
->defaultFalse() |
78
|
10 |
|
->info('Whether classes must implement the TransactionalAwareInterface interface, so as the Transactional annotation is read.') |
79
|
10 |
|
->end() |
80
|
10 |
|
->enumNode(static::DEFAULT_POLICY) |
81
|
10 |
|
->cannotBeEmpty() |
82
|
10 |
|
->values([static::POLICY_REQUIRED, static::POLICY_NOT_REQUIRED, static::POLICY_NESTED]) |
83
|
10 |
|
->defaultValue(static::POLICY_REQUIRED) |
84
|
10 |
|
->info('Default transactional policy when none policy is set in the annotation') |
85
|
10 |
|
->end() |
86
|
10 |
|
->arrayNode(static::NO_ROLLBACK_EXCEPTIONS) |
87
|
10 |
|
->prototype('scalar') |
88
|
10 |
|
->cannotBeEmpty() |
89
|
10 |
|
->info('Array of FQCN of exceptions for which rollback won\'t be triggered.') |
90
|
10 |
|
->end() |
91
|
10 |
|
->end(); |
92
|
|
|
|
93
|
10 |
|
return $treeBuilder; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|