1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
7
|
|
|
* |
8
|
|
|
* @license GPL-3.0 |
9
|
|
|
* |
10
|
|
|
* @author Gerrit Addiks <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Addiks\SymfonyGenerics\DependencyInjection\Compiler; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
18
|
|
|
use Webmozart\Assert\Assert; |
19
|
|
|
|
20
|
|
|
final class ControllerErrorHandlingPass implements CompilerPassInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
2 |
|
public function process(ContainerBuilder $container): void |
24
|
|
|
{ |
25
|
|
|
/** @var array<string, array> $taggedErrorHandlers */ |
26
|
2 |
|
$taggedErrorHandlers = $container->findTaggedServiceIds("symfony_generics.error_handler"); |
27
|
|
|
|
28
|
2 |
|
foreach ($taggedErrorHandlers as $errorHandlerServiceId => $errorHandlerTags) { |
29
|
2 |
|
foreach ($errorHandlerTags as $errorHandlerTag) { |
30
|
2 |
|
Assert::keyExists($errorHandlerTag, 'key'); |
31
|
|
|
|
32
|
|
|
/** @var string $errorHandlerKey */ |
33
|
1 |
|
$errorHandlerKey = $errorHandlerTag['key']; |
34
|
|
|
|
35
|
1 |
|
unset($errorHandlerTag['key']); |
36
|
|
|
|
37
|
|
|
/** @var array<string, array> $taggedControllers */ |
38
|
1 |
|
$taggedControllers = $container->findTaggedServiceIds(sprintf( |
39
|
1 |
|
"symfony_generics.error_handler.%s", |
40
|
1 |
|
$errorHandlerKey |
41
|
|
|
)); |
42
|
|
|
|
43
|
|
|
/** @var Definition $errorHandlerDefinition */ |
44
|
1 |
|
$errorHandlerDefinition = $container->getDefinition($errorHandlerServiceId); |
45
|
|
|
|
46
|
1 |
|
foreach ($taggedControllers as $controllerServiceId => $tags) { |
47
|
|
|
/** @var array $tags */ |
48
|
|
|
|
49
|
1 |
|
foreach ($tags as $tagData) { |
50
|
|
|
/** @var array $tagData */ |
51
|
1 |
|
$tagData = array_merge([ |
52
|
1 |
|
'decorates' => $controllerServiceId |
53
|
1 |
|
], $errorHandlerTag, $tagData); |
54
|
|
|
|
55
|
1 |
|
$errorHandlerDefinition->addTag("symfony_generics.decorates", $tagData); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|