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 Exception; |
24
|
|
|
use InvalidArgumentException; |
25
|
|
|
use ReflectionClass; |
26
|
|
|
use ReflectionException; |
27
|
|
|
use Inneair\TransactionBundle\Annotation\Transactional; |
28
|
|
|
use Symfony\Component\Config\FileLocator; |
29
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
30
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
31
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* This class loads and manages the bundle configuration. |
35
|
|
|
*/ |
36
|
|
|
class InneairTransactionExtension extends Extension |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
* |
41
|
|
|
* @throws InvalidArgumentException If the class name of a no rollback exception cannot be found, or it is not a |
42
|
|
|
* valid exception class, or if the configuration options contain an unsupported default policy. |
43
|
|
|
*/ |
44
|
11 |
|
public function load(array $configs, ContainerBuilder $container) |
45
|
|
|
{ |
46
|
11 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
47
|
11 |
|
$loader->load('services.yml'); |
48
|
|
|
|
49
|
11 |
|
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
|
|
|
|
50
|
|
|
|
51
|
11 |
|
$container->setParameter( |
52
|
11 |
|
Configuration::ROOT_NODE_NAME . '.' . Configuration::STRICT_MODE, |
53
|
11 |
|
$config[Configuration::STRICT_MODE] |
54
|
11 |
|
); |
55
|
|
|
|
56
|
11 |
|
switch ($config[Configuration::DEFAULT_POLICY]) { |
57
|
11 |
|
case Configuration::POLICY_NOT_REQUIRED: |
58
|
1 |
|
$policy = Transactional::NOT_REQUIRED; |
59
|
1 |
|
break; |
60
|
10 |
|
case Configuration::POLICY_REQUIRED: |
61
|
6 |
|
$policy = Transactional::REQUIRED; |
62
|
6 |
|
break; |
63
|
4 |
|
case Configuration::POLICY_NESTED: |
64
|
3 |
|
$policy = Transactional::NESTED; |
65
|
3 |
|
break; |
66
|
1 |
|
default: |
67
|
1 |
|
throw new InvalidArgumentException( |
68
|
1 |
|
'Unsupported default policy "' . $config[Configuration::DEFAULT_POLICY] . '"' |
69
|
1 |
|
); |
70
|
11 |
|
} |
71
|
10 |
|
$container->setParameter(Configuration::ROOT_NODE_NAME . '.' . Configuration::DEFAULT_POLICY, $policy); |
72
|
|
|
|
73
|
10 |
|
$noRollbackExceptions = array_unique($config[Configuration::NO_ROLLBACK_EXCEPTIONS]); |
74
|
10 |
View Code Duplication |
foreach ($noRollbackExceptions as $exceptionClassName) { |
|
|
|
|
75
|
|
|
try { |
76
|
4 |
|
$exceptionClass = new ReflectionClass($exceptionClassName); |
77
|
4 |
|
} catch (ReflectionException $e) { |
78
|
1 |
|
throw new InvalidArgumentException('Class not found: \'' . $exceptionClassName . '\'', null, $e); |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
if (($exceptionClassName !== Exception::class) && !$exceptionClass->isSubclassOf(Exception::class)) { |
82
|
1 |
|
throw new InvalidArgumentException('Not an exception: \'' . $exceptionClassName . '\''); |
83
|
|
|
} |
84
|
8 |
|
} |
85
|
8 |
|
$container->setParameter( |
86
|
8 |
|
Configuration::ROOT_NODE_NAME . '.' . Configuration::NO_ROLLBACK_EXCEPTIONS, |
87
|
|
|
$noRollbackExceptions |
88
|
8 |
|
); |
89
|
8 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
3 |
|
public function getXsdValidationBasePath() |
95
|
|
|
{ |
96
|
3 |
|
return __DIR__ . '/../Resources/config/schema'; |
|
|
|
|
97
|
1 |
|
} |
98
|
|
|
} |
99
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: