1 | <?php |
||
29 | final class ServicesBuilder implements BuilderInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $parameters; |
||
35 | |||
36 | /** |
||
37 | * @var ReferenceResolverInterface |
||
38 | */ |
||
39 | private $referenceResolver; |
||
40 | |||
41 | /** |
||
42 | * @var ServiceInterface[] |
||
43 | */ |
||
44 | private $services; |
||
45 | |||
46 | /** |
||
47 | * @var ParameterResolverInterface|null |
||
48 | */ |
||
49 | private $parameterResolver; |
||
50 | |||
51 | /** |
||
52 | * @param ServiceInterface[] $services |
||
53 | * @param array $parameters |
||
54 | * @param ParameterResolverInterface|null $parameterResolver |
||
55 | * @param ReferenceResolverInterface|null $referenceResolver |
||
56 | */ |
||
57 | 16 | public function __construct( |
|
68 | |||
69 | 16 | public function build(Application $application) |
|
70 | { |
||
71 | try { |
||
72 | 16 | $parameterResolver = $this->getParameterResolver($application); |
|
73 | 16 | $instantiator = new ServiceInstantiator($parameterResolver, $this->referenceResolver, $application); |
|
74 | 16 | foreach ($this->services as $service) { |
|
75 | 14 | $this->buildService($service, $instantiator, $application); |
|
76 | 10 | } |
|
77 | |||
78 | 10 | return $this->parameters; |
|
79 | 6 | } catch (BindingResolutionException $exception) { |
|
80 | 2 | throw new Exception(sprintf('Could not load "%s" class', ConfigRepository::class), 0, $exception); |
|
81 | 4 | } catch (ResolverException $exception) { |
|
82 | throw new Exception('Could not resolve the parameters', 0, $exception); |
||
83 | 4 | } catch (\Exception $exception) { |
|
84 | 4 | throw new Exception('Could not build the parameters', 0, $exception); |
|
85 | } |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param Application $application |
||
90 | * |
||
91 | * @return ParameterResolverInterface |
||
92 | */ |
||
93 | 16 | private function getParameterResolver(Application $application) |
|
102 | |||
103 | 14 | private function buildService( |
|
118 | |||
119 | 8 | private function bindAutowiringTypes(ServiceInterface $service, Application $application) |
|
125 | |||
126 | 8 | private function tagService(ServiceInterface $service, Application $application) |
|
132 | } |
||
133 |