@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | 'rev-manifest.json', |
24 | 24 | ], |
25 | 25 | 'missingAsset' => 'notice', // exception, notice, or ignore |
26 | - 'missingManifest' => 'notice', // exception, notice, or ignore |
|
26 | + 'missingManifest' => 'notice', // exception, notice, or ignore |
|
27 | 27 | 'missingVersion' => 'ignore', // exception, notice, or ignore |
28 | 28 | ]; |
29 | 29 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | $choices = ['exception', 'notice', 'ignore']; |
36 | 36 | $this->validateChoices('missingAsset', $choices); |
37 | - $this->validateChoices('missingManifest', $choices); |
|
37 | + $this->validateChoices('missingManifest', $choices); |
|
38 | 38 | $this->validateChoices('missingVersion', $choices); |
39 | 39 | |
40 | 40 | $builder = $this->getContainerBuilder(); |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | 'versions.json', |
23 | 23 | 'rev-manifest.json', |
24 | 24 | ], |
25 | - 'missingAsset' => 'notice', // exception, notice, or ignore |
|
25 | + 'missingAsset' => 'notice', // exception, notice, or ignore |
|
26 | 26 | 'missingManifest' => 'notice', // exception, notice, or ignore |
27 | - 'missingVersion' => 'ignore', // exception, notice, or ignore |
|
27 | + 'missingVersion' => 'ignore', // exception, notice, or ignore |
|
28 | 28 | ]; |
29 | 29 | |
30 | 30 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | private function validateChoices($key, array $choices) |
55 | 55 | { |
56 | - if ( ! in_array($this->config[$key], $choices)) { |
|
56 | + if (!in_array($this->config[$key], $choices)) { |
|
57 | 57 | throw new UnexpectedValueException(sprintf( |
58 | 58 | "Unexpected value '%s' of '%s' configuration key. Allowed values: %s.", |
59 | 59 | $this->config[$key], |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | // Get asset version |
76 | - try { |
|
77 | - $versions = $config['revManifest'] ?: |
|
78 | - self::autodetectVersions($absolutePath, $wwwDir, $config['autodetect']); |
|
79 | - $version = self::getAssetVersion($versions, $absolutePath, $needed, $config); |
|
80 | - } catch(ManifestNotFoundException $e) { |
|
81 | - self::throwError($e, $config['missingManifest'], $needed); |
|
82 | - $version = 'unknown'; |
|
83 | - } |
|
76 | + try { |
|
77 | + $versions = $config['revManifest'] ?: |
|
78 | + self::autodetectVersions($absolutePath, $wwwDir, $config['autodetect']); |
|
79 | + $version = self::getAssetVersion($versions, $absolutePath, $needed, $config); |
|
80 | + } catch(ManifestNotFoundException $e) { |
|
81 | + self::throwError($e, $config['missingManifest'], $needed); |
|
82 | + $version = 'unknown'; |
|
83 | + } |
|
84 | 84 | |
85 | 85 | return self::formatOutput($format, $basePath, $relativePath, $version); |
86 | 86 | } |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | switch ($matches[1]) { |
103 | 103 | case 'url': |
104 | 104 | return sprintf("%s/%s?v=%s", $basePath, $relativePath, $version); |
105 | - case 'path': |
|
106 | - return sprintf("%s/%s", $basePath, $relativePath); |
|
105 | + case 'path': |
|
106 | + return sprintf("%s/%s", $basePath, $relativePath); |
|
107 | 107 | case 'version': |
108 | 108 | return $version; |
109 | 109 | case 'basePath': |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | if (($absolutePath = realpath($wwwDir . DIRECTORY_SEPARATOR . $relativePath)) === FALSE) { |
160 | - $msg = sprintf("Asset '%s' not found.", $relativePath); |
|
161 | - self::throwError(new AssetNotFoundException($msg), $config['missingAsset'], $needed); |
|
160 | + $msg = sprintf("Asset '%s' not found.", $relativePath); |
|
161 | + self::throwError(new AssetNotFoundException($msg), $config['missingAsset'], $needed); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return [$relativePath, $absolutePath, $wwwDir]; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * @param mixed $assetsVersions |
170 | 170 | * @param string $absolutePath |
171 | - * @param bool $needed |
|
171 | + * @param bool $needed |
|
172 | 172 | * @param array $config |
173 | 173 | * @return mixed|string |
174 | 174 | */ |
@@ -190,18 +190,18 @@ discard block |
||
190 | 190 | } |
191 | 191 | |
192 | 192 | $msg = sprintf("Asset macro: version of asset '%s' not found.", $absolutePath); |
193 | - self::throwError(new AssetVersionNotFound($msg), $config['missingVersion'], $needed); |
|
193 | + self::throwError(new AssetVersionNotFound($msg), $config['missingVersion'], $needed); |
|
194 | 194 | |
195 | - return 'unknown'; |
|
195 | + return 'unknown'; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * @param $absolutePath |
|
201 | - * @param $wwwDir |
|
202 | - * @param array $paths |
|
203 | - * @return mixed|string |
|
204 | - */ |
|
199 | + /** |
|
200 | + * @param $absolutePath |
|
201 | + * @param $wwwDir |
|
202 | + * @param array $paths |
|
203 | + * @return mixed|string |
|
204 | + */ |
|
205 | 205 | private static function autodetectVersions($absolutePath, $wwwDir, array $paths) |
206 | 206 | { |
207 | 207 | // Iterate over parent directories (stop in www dir) |
@@ -226,20 +226,20 @@ discard block |
||
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - /** |
|
230 | - * @param \Exception $e |
|
231 | - * @param string $action |
|
232 | - * @param bool $needed |
|
233 | - * @throws \Exception |
|
234 | - */ |
|
229 | + /** |
|
230 | + * @param \Exception $e |
|
231 | + * @param string $action |
|
232 | + * @param bool $needed |
|
233 | + * @throws \Exception |
|
234 | + */ |
|
235 | 235 | private static function throwError(\Exception $e, $action = 'exception', $needed = TRUE) { |
236 | - if ($needed) { |
|
237 | - if ($action === 'exception') { |
|
238 | - throw $e; |
|
239 | - } elseif ($action === 'notice') { |
|
240 | - trigger_error($e->getMessage(), E_USER_NOTICE); |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
236 | + if ($needed) { |
|
237 | + if ($action === 'exception') { |
|
238 | + throw $e; |
|
239 | + } elseif ($action === 'notice') { |
|
240 | + trigger_error($e->getMessage(), E_USER_NOTICE); |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | } |
@@ -74,10 +74,9 @@ discard block |
||
74 | 74 | |
75 | 75 | // Get asset version |
76 | 76 | try { |
77 | - $versions = $config['revManifest'] ?: |
|
78 | - self::autodetectVersions($absolutePath, $wwwDir, $config['autodetect']); |
|
77 | + $versions = $config['revManifest'] ?: self::autodetectVersions($absolutePath, $wwwDir, $config['autodetect']); |
|
79 | 78 | $version = self::getAssetVersion($versions, $absolutePath, $needed, $config); |
80 | - } catch(ManifestNotFoundException $e) { |
|
79 | + } catch (ManifestNotFoundException $e) { |
|
81 | 80 | self::throwError($e, $config['missingManifest'], $needed); |
82 | 81 | $version = 'unknown'; |
83 | 82 | } |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | { |
99 | 98 | return Strings::replace($format, |
100 | 99 | '/%([^%]+)%/', |
101 | - function ($matches) use ($basePath, $format, $relativePath, $version) { |
|
100 | + function($matches) use ($basePath, $format, $relativePath, $version) { |
|
102 | 101 | switch ($matches[1]) { |
103 | 102 | case 'url': |
104 | 103 | return sprintf("%s/%s?v=%s", $basePath, $relativePath, $version); |
@@ -175,8 +174,8 @@ discard block |
||
175 | 174 | private static function getAssetVersion($assetsVersions, $absolutePath, $needed, array $config) |
176 | 175 | { |
177 | 176 | // Versions can be array or path to JSON file |
178 | - if ( ! is_array($assetsVersions)) { |
|
179 | - if ( ! file_exists($assetsVersions)) { |
|
177 | + if (!is_array($assetsVersions)) { |
|
178 | + if (!file_exists($assetsVersions)) { |
|
180 | 179 | throw new ManifestNotFoundException(sprintf("Revision manifest file not found: '%s'.", $assetsVersions)); |
181 | 180 | } |
182 | 181 | $assetsVersions = Json::decode(file_get_contents($assetsVersions), Json::FORCE_ARRAY); |