1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Faecie\Bundle\JsonApiErrorResponseBundle\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Faecie\Bundle\JsonApiErrorResponseBundle\ExceptionDescriber\PreconfiguredExceptionsDescriber; |
8
|
|
|
use Faecie\Bundle\JsonApiErrorResponseBundle\JsonApi\Error; |
9
|
|
|
use Symfony\Component\Config\FileLocator; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
12
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
13
|
|
|
|
14
|
|
|
class JsonApiErrorResponseExtension extends Extension |
15
|
|
|
{ |
16
|
3 |
|
public function load(array $configs, ContainerBuilder $container) |
17
|
|
|
{ |
18
|
3 |
|
$config = $this->processConfiguration(new Configuration(), $configs); |
19
|
3 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/')); |
20
|
3 |
|
$loader->load('config.xml'); |
21
|
|
|
|
22
|
3 |
|
$errorObjects = []; |
23
|
3 |
|
$exceptionsConfiguration = $config['exceptions']['response']; |
24
|
|
|
|
25
|
3 |
|
foreach ($exceptionsConfiguration as $exception => $config) { |
26
|
1 |
|
$errorObjects[$exception] = new Error( |
27
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_CODE], |
28
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_ID], |
29
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_ABOUT], |
30
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_STATUS], |
31
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_TITLE], |
32
|
1 |
|
$config[Configuration::EXCEPTION_ATTRIBUTE_DETAIL] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
3 |
|
$container->getDefinition(PreconfiguredExceptionsDescriber::class) |
37
|
3 |
|
->replaceArgument(0, $exceptionsConfiguration); |
38
|
3 |
|
} |
39
|
|
|
} |
40
|
|
|
|