|
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
|
|
|
public function process(ContainerBuilder $container): void |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var array<string, array> $taggedErrorHandlers */ |
|
26
|
|
|
$taggedErrorHandlers = $container->findTaggedServiceIds("symfony_generics.error_handler"); |
|
27
|
|
|
|
|
28
|
|
|
foreach ($taggedErrorHandlers as $errorHandlerServiceId => $errorHandlerTags) { |
|
29
|
|
|
foreach ($errorHandlerTags as $errorHandlerTag) { |
|
30
|
|
|
Assert::keyExists($errorHandlerTag, 'key'); |
|
31
|
|
|
|
|
32
|
|
|
/** @var string $errorHandlerKey */ |
|
33
|
|
|
$errorHandlerKey = $errorHandlerTag['key']; |
|
34
|
|
|
|
|
35
|
|
|
unset($errorHandlerTag['key']); |
|
36
|
|
|
|
|
37
|
|
|
/** @var array<string, array> $taggedControllers */ |
|
38
|
|
|
$taggedControllers = $container->findTaggedServiceIds(sprintf( |
|
39
|
|
|
"symfony_generics.error_handler.%s", |
|
40
|
|
|
$errorHandlerKey |
|
41
|
|
|
)); |
|
42
|
|
|
|
|
43
|
|
|
/** @var Definition $errorHandlerDefinition */ |
|
44
|
|
|
$errorHandlerDefinition = $container->getDefinition($errorHandlerServiceId); |
|
45
|
|
|
|
|
46
|
|
|
foreach ($taggedControllers as $controllerServiceId => $tags) { |
|
47
|
|
|
/** @var array $tagData */ |
|
48
|
|
|
|
|
49
|
|
|
foreach ($tags as $tagData) { |
|
50
|
|
|
$tagData = array_merge([ |
|
51
|
|
|
'decorates' => $controllerServiceId |
|
52
|
|
|
], $errorHandlerTag, $tagData); |
|
53
|
|
|
|
|
54
|
|
|
$errorHandlerDefinition->addTag("symfony_generics.decorates", $tagData); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|