|
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
|
|
|
public function __construct(ResolverInterface $serviceResolver = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$serviceResolver = (null === $serviceResolver) ? new ServiceResolver() : $serviceResolver; |
|
33
|
|
|
$this->definitionParser = new DefinitionParser($serviceResolver); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
69 |
|
/** |
|
37
|
|
|
* Parses service definitions and register them to the container. |
|
38
|
69 |
|
* |
|
39
|
69 |
|
* @param ContainerBuilder $container |
|
40
|
|
|
* @param array $content YAML file content |
|
41
|
|
|
* @param string $fileName file name |
|
42
|
|
|
* |
|
43
|
|
|
* @throws InvalidArgumentException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function parse(ContainerBuilder $container, $content, $fileName) |
|
46
|
|
|
{ |
|
47
|
|
|
if (!isset($content['services'])) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
69 |
|
|
|
51
|
|
|
if (!is_array($content['services'])) { |
|
52
|
69 |
|
throw new InvalidArgumentException( |
|
53
|
12 |
|
sprintf( |
|
54
|
|
|
'The "services" key should contain an array in %s. Check your YAML syntax.', |
|
55
|
|
|
$fileName |
|
56
|
57 |
|
) |
|
57
|
6 |
|
); |
|
58
|
4 |
|
} |
|
59
|
6 |
|
|
|
60
|
|
|
foreach ($content['services'] as $id => $service) { |
|
61
|
4 |
|
$this->definitionParser->parse($container, strtolower($id), $service, $fileName); |
|
62
|
4 |
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|