1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LaravelYaml package. |
5
|
|
|
* |
6
|
|
|
* (c) Théo FIDRY <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Fidry\LaravelYaml\FileLoader\Parser\Yaml; |
13
|
|
|
|
14
|
|
|
use Fidry\LaravelYaml\DependencyInjection\Builder\ContainerBuilder; |
15
|
|
|
use Fidry\LaravelYaml\Exception\FileLoader\InvalidArgumentException; |
16
|
|
|
use Fidry\LaravelYaml\FileLoader\Parser\Resolver\ResolverInterface; |
17
|
|
|
use Fidry\LaravelYaml\FileLoader\Parser\Resolver\ServiceResolver; |
18
|
|
|
use Fidry\LaravelYaml\FileLoader\Parser\Yaml\Util\DefinitionParser; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Théo FIDRY <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class DefinitionsParser |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var DefinitionParser |
27
|
|
|
*/ |
28
|
|
|
private $definitionParser; |
29
|
|
|
|
30
|
44 |
|
public function __construct(ResolverInterface $serviceResolver = null) |
31
|
1 |
|
{ |
32
|
44 |
|
$serviceResolver = (null === $serviceResolver) ? new ServiceResolver() : $serviceResolver; |
33
|
44 |
|
$this->definitionParser = new DefinitionParser($serviceResolver); |
34
|
44 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Parses service definitions and register them to the container. |
38
|
|
|
* |
39
|
|
|
* @param ContainerBuilder $container |
40
|
|
|
* @param array $content YAML file content |
41
|
|
|
* @param string $fileName file name |
42
|
|
|
* |
43
|
|
|
* @throws InvalidArgumentException |
44
|
|
|
*/ |
45
|
44 |
|
public function parse(ContainerBuilder $container, $content, $fileName) |
46
|
|
|
{ |
47
|
44 |
|
if (!isset($content['services'])) { |
48
|
8 |
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
36 |
|
if (!is_array($content['services'])) { |
52
|
4 |
|
throw new InvalidArgumentException( |
53
|
2 |
|
sprintf( |
54
|
4 |
|
'The "services" key should contain an array in %s. Check your YAML syntax.', |
55
|
|
|
$fileName |
56
|
2 |
|
) |
57
|
2 |
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
32 |
|
foreach ($content['services'] as $id => $service) { |
61
|
32 |
|
$this->definitionParser->parse($container, strtolower($id), $service, $fileName); |
62
|
7 |
|
} |
63
|
14 |
|
} |
64
|
|
|
} |
65
|
|
|
|