1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2019 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Jose\Bundle\JoseFramework\DependencyInjection\Source; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
19
|
|
|
|
20
|
|
|
abstract class AbstractSource |
21
|
|
|
{ |
22
|
|
|
public function create(ContainerBuilder $container, string $type, string $name, array $config): void |
23
|
|
|
{ |
24
|
|
|
$service_id = sprintf('jose.%s.%s', $type, $name); |
25
|
|
|
$definition = $this->createDefinition($container, $config); |
26
|
|
|
$definition->setPublic($config['is_public']); |
27
|
|
|
foreach ($config['tags'] as $id => $attributes) { |
28
|
|
|
$definition->addTag($id, $attributes); |
29
|
|
|
} |
30
|
|
|
$container->setDefinition($service_id, $definition); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function addConfiguration(NodeDefinition $node): void |
34
|
|
|
{ |
35
|
|
|
$node |
36
|
|
|
->children() |
37
|
|
|
->booleanNode('is_public') |
38
|
|
|
->info('If true, the service will be public, else private.') |
39
|
|
|
->defaultTrue() |
40
|
|
|
->end() |
41
|
|
|
->arrayNode('tags') |
42
|
|
|
->info('A list of tags to be associated to the service.') |
43
|
|
|
->useAttributeAsKey('name') |
44
|
|
|
->treatNullLike([]) |
45
|
|
|
->treatFalseLike([]) |
46
|
|
|
->variablePrototype()->end() |
47
|
|
|
->end() |
48
|
|
|
->end() |
49
|
|
|
; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
abstract protected function createDefinition(ContainerBuilder $container, array $config): Definition; |
53
|
|
|
} |
54
|
|
|
|