1 | <?php |
||
32 | class InstallationParams |
||
33 | { |
||
34 | /** |
||
35 | * @var ResourceInstaller |
||
36 | */ |
||
37 | private $installer; |
||
38 | |||
39 | /** |
||
40 | * @var InstallerDescriptor |
||
41 | */ |
||
42 | private $installerDescriptor; |
||
43 | |||
44 | /** |
||
45 | * @var ResourceCollection |
||
46 | */ |
||
47 | private $resources; |
||
48 | |||
49 | /** |
||
50 | * @var AssetMapping |
||
51 | */ |
||
52 | private $mapping; |
||
53 | |||
54 | /** |
||
55 | * @var Server |
||
56 | */ |
||
57 | private $server; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | private $rootDir; |
||
63 | |||
64 | /** |
||
65 | * @var array |
||
66 | */ |
||
67 | private $parameterValues; |
||
68 | |||
69 | /** |
||
70 | * Creates the installation request. |
||
71 | * |
||
72 | * @param ResourceInstaller $installer The used resource installer. |
||
73 | * @param InstallerDescriptor $installerDescriptor The descriptor of the |
||
74 | * resource installer. |
||
75 | * @param ResourceCollection $resources The resources to install. |
||
76 | * @param AssetMapping $mapping The asset mapping. |
||
77 | * @param Server $server The asset server. |
||
78 | * @param string $rootDir The project's root directory. |
||
79 | */ |
||
80 | 16 | public function __construct(ResourceInstaller $installer, InstallerDescriptor $installerDescriptor, ResourceCollection $resources, AssetMapping $mapping, Server $server, $rootDir) |
|
81 | { |
||
82 | 16 | $glob = $mapping->getGlob(); |
|
83 | 16 | $parameterValues = $server->getParameterValues(); |
|
84 | |||
85 | 16 | $this->validateParameterValues($parameterValues, $installerDescriptor); |
|
86 | |||
87 | 14 | $this->installer = $installer; |
|
88 | 14 | $this->installerDescriptor = $installerDescriptor; |
|
89 | 14 | $this->resources = $resources; |
|
90 | 14 | $this->mapping = $mapping; |
|
91 | 14 | $this->server = $server; |
|
92 | 14 | $this->rootDir = $rootDir; |
|
93 | 14 | $this->basePath = Glob::isDynamic($glob) ? Glob::getBasePath($glob) : $glob; |
|
|
|||
94 | 14 | $this->parameterValues = array_replace( |
|
95 | 14 | $installerDescriptor->getParameterValues(), |
|
96 | $parameterValues |
||
97 | ); |
||
98 | 14 | } |
|
99 | |||
100 | /** |
||
101 | * Returns the used resource installer. |
||
102 | * |
||
103 | * @return ResourceInstaller The installer used to install the resources in |
||
104 | * the server's document root. |
||
105 | */ |
||
106 | 2 | public function getInstaller() |
|
110 | |||
111 | /** |
||
112 | * Returns the descriptor of the installer. |
||
113 | * |
||
114 | * @return InstallerDescriptor The descriptor of the installer. |
||
115 | */ |
||
116 | 1 | public function getInstallerDescriptor() |
|
120 | |||
121 | /** |
||
122 | * Returns the installed resources. |
||
123 | * |
||
124 | * @return ResourceCollection The installed resources. |
||
125 | */ |
||
126 | 1 | public function getResources() |
|
130 | |||
131 | /** |
||
132 | * Returns the asset mapping. |
||
133 | * |
||
134 | * @return AssetMapping The asset mapping. |
||
135 | */ |
||
136 | public function getMapping() |
||
140 | |||
141 | /** |
||
142 | * Returns the root directory of the Puli project. |
||
143 | * |
||
144 | * @return string The project's root directory. |
||
145 | */ |
||
146 | 8 | public function getRootDirectory() |
|
150 | |||
151 | /** |
||
152 | * Returns the common base path of the installed resources. |
||
153 | * |
||
154 | * @return string The common base path of the installed resources. |
||
155 | */ |
||
156 | 2 | public function getBasePath() |
|
160 | |||
161 | /** |
||
162 | * Returns the target server. |
||
163 | * |
||
164 | * @return Server The target server. |
||
165 | */ |
||
166 | public function getServer() |
||
170 | |||
171 | /** |
||
172 | * Returns the document root of the server. |
||
173 | * |
||
174 | * This can be a directory name, a URL or any other string that can be |
||
175 | * interpreted by the installer. |
||
176 | * |
||
177 | * @return string The document root. |
||
178 | */ |
||
179 | 8 | public function getDocumentRoot() |
|
183 | |||
184 | /** |
||
185 | * Returns the path where the resources are going to be installed. |
||
186 | * |
||
187 | * This is a path relative to the document root of the target server. |
||
188 | * |
||
189 | * @return string The server path. |
||
190 | */ |
||
191 | 1 | public function getServerPath() |
|
195 | |||
196 | /** |
||
197 | * Returns the path where a resource is going to be installed. |
||
198 | * |
||
199 | * This is a path relative to the document root of the target server. |
||
200 | * |
||
201 | * @param PuliResource $resource The resource. |
||
202 | * |
||
203 | * @return string The server path. |
||
204 | */ |
||
205 | 10 | public function getServerPathForResource(PuliResource $resource) |
|
206 | { |
||
207 | 10 | $relPath = Path::makeRelative($resource->getRepositoryPath(), $this->basePath); |
|
208 | |||
209 | 10 | return '/'.trim($this->mapping->getServerPath().'/'.$relPath, '/'); |
|
210 | } |
||
211 | |||
212 | /** |
||
213 | * Returns the installer parameters. |
||
214 | * |
||
215 | * The result is a merge of the default parameter values of the installer |
||
216 | * and the parameter values set for the server. |
||
217 | * |
||
218 | * @return array The installer parameters. |
||
219 | */ |
||
220 | 8 | public function getParameterValues() |
|
224 | |||
225 | 16 | private function validateParameterValues(array $parameterValues, InstallerDescriptor $installerDescriptor) |
|
245 | } |
||
246 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: