This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractServiceCompilerHook.php
142 lines (128 loc) · 2.89 KB
/
AbstractServiceCompilerHook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Services\Common\Hook;
use Ulrack\Services\Common\ServiceRegistryInterface;
abstract class AbstractServiceCompilerHook implements ServiceCompilerHookInterface
{
/**
* Contains the service registry.
*
* @var ServiceRegistryInterface
*/
private $registry;
/**
* Contains the key of the service extension.
*
* @var string
*/
private $key;
/**
* Contains the parameters for the extension.
*
* @var array
*/
private $parameters;
/**
* Constructor.
*
* @param ServiceRegistryInterface $registry
* @param string $key
* @param array $parameters
*/
public function __construct(
ServiceRegistryInterface $registry,
string $key,
array $parameters
) {
$this->registry = $registry;
$this->key = $key;
$this->parameters = $parameters;
}
/**
* Hooks in before compiling all services in the compiler.
*
* @param array $services
* @param array $parameters
*
* @return array
*/
public function preCompile(array $services, array $parameters = []): array
{
return ['services' => $services, 'parameters' => $parameters];
}
/**
* Hooks in after compiling all services in the compiler.
*
* @param array $services
* @param array $return
* @param array $parameters
*
* @return array
*/
public function postCompile(
array $services,
array $return,
array $parameters = []
): array {
return [
'services' => $services,
'return' => $return,
'parameters' => $parameters
];
}
/**
* Hooks in after fetching all services in the compiler.
*
* @param array $return
* @param array $parameters
*
* @return array
*/
public function postFetch(
array $return,
array $parameters = []
): array {
return ['return' => $return, 'parameters' => $parameters];
}
/**
* Retrieves the registry.
*
* @return ServiceRegistryInterface
*/
public function getRegistry(): ServiceRegistryInterface
{
return $this->registry;
}
/**
* Retrieves the key of the service.
*
* @return string
*/
public function getKey(): string
{
return $this->key;
}
/**
* Retrieves the requested extension parameter.
*
* @param string $key
*
* @return mixed
*/
public function getParameter(string $key)
{
return $this->parameters[$key];
}
/**
* Retrieves the parameters for the extension.
*
* @return array
*/
public function getParameters(): array
{
return $this->parameters;
}
}