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