1 | <?php |
||||||
2 | /** |
||||||
3 | * Twigpack plugin for Craft CMS 3.x |
||||||
4 | * |
||||||
5 | * Twigpack is the conduit between Twig and webpack, with manifest.json & |
||||||
6 | * webpack-dev-server HMR support |
||||||
7 | * |
||||||
8 | * @link https://nystudio107.com/ |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||||
9 | * @copyright Copyright (c) 2018 nystudio107 |
||||||
0 ignored issues
–
show
|
|||||||
10 | */ |
||||||
0 ignored issues
–
show
|
|||||||
11 | |||||||
12 | namespace nystudio107\twigpack\services; |
||||||
13 | |||||||
14 | use craft\base\Component; |
||||||
15 | use nystudio107\twigpack\helpers\Manifest as ManifestHelper; |
||||||
16 | use nystudio107\twigpack\Twigpack; |
||||||
17 | use Twig\Error\LoaderError; |
||||||
18 | use yii\web\NotFoundHttpException; |
||||||
19 | |||||||
20 | /** @noinspection MissingPropertyAnnotationsInspection */ |
||||||
0 ignored issues
–
show
|
|||||||
21 | |||||||
22 | /** |
||||||
0 ignored issues
–
show
|
|||||||
23 | * @author nystudio107 |
||||||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||||||
24 | * @package Twigpack |
||||||
0 ignored issues
–
show
|
|||||||
25 | * @since 1.0.0 |
||||||
0 ignored issues
–
show
|
|||||||
26 | */ |
||||||
0 ignored issues
–
show
|
|||||||
27 | class Manifest extends Component |
||||||
28 | { |
||||||
29 | // Public Methods |
||||||
30 | // ========================================================================= |
||||||
31 | |||||||
32 | /** |
||||||
33 | * Return the HTML tags to include the CSS |
||||||
34 | * |
||||||
35 | * @param string $moduleName |
||||||
0 ignored issues
–
show
|
|||||||
36 | * @param bool $async |
||||||
0 ignored issues
–
show
|
|||||||
37 | * @param null|array $config |
||||||
0 ignored issues
–
show
|
|||||||
38 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||||
0 ignored issues
–
show
|
|||||||
39 | * |
||||||
40 | * @return string |
||||||
41 | * @throws NotFoundHttpException |
||||||
42 | */ |
||||||
43 | public function getCssModuleTags(string $moduleName, bool $async = false, $config = null, array $attributes = []): string |
||||||
44 | { |
||||||
45 | $settings = Twigpack::$plugin->getSettings(); |
||||||
0 ignored issues
–
show
The method
getSettings() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
46 | $config = $config ?? $settings->getAttributes(); |
||||||
47 | |||||||
48 | return ManifestHelper::getCssModuleTags($config, $moduleName, $async, $attributes); |
||||||
49 | } |
||||||
50 | |||||||
51 | /** |
||||||
52 | * Returns the CSS file in $path wrapped in <style></style> tags |
||||||
53 | * |
||||||
54 | * @param string $path |
||||||
0 ignored issues
–
show
|
|||||||
55 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||||
0 ignored issues
–
show
|
|||||||
56 | * |
||||||
57 | * @return string |
||||||
58 | */ |
||||||
59 | public function getCssInlineTags(string $path, array $attributes = []): string |
||||||
60 | { |
||||||
61 | return ManifestHelper::getCssInlineTags($path, $attributes); |
||||||
62 | } |
||||||
63 | |||||||
64 | /** |
||||||
0 ignored issues
–
show
|
|||||||
65 | * @param array $config |
||||||
0 ignored issues
–
show
|
|||||||
66 | * @param null|string $name |
||||||
0 ignored issues
–
show
|
|||||||
67 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||||
0 ignored issues
–
show
|
|||||||
68 | * |
||||||
69 | * @return string |
||||||
70 | * @throws LoaderError |
||||||
71 | */ |
||||||
72 | public function getCriticalCssTags(?string $name = null, ?array $config = null, array $attributes = []): string |
||||||
73 | { |
||||||
74 | $settings = Twigpack::$plugin->getSettings(); |
||||||
75 | $config = $config ?? $settings->getAttributes(); |
||||||
76 | |||||||
77 | return ManifestHelper::getCriticalCssTags($config, $name, $attributes); |
||||||
78 | } |
||||||
79 | |||||||
80 | /** |
||||||
81 | * Returns the uglified loadCSS rel=preload Polyfill as per: |
||||||
82 | * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example |
||||||
83 | * |
||||||
84 | * @return string |
||||||
85 | */ |
||||||
86 | public function getCssRelPreloadPolyfill(): string |
||||||
87 | { |
||||||
88 | return ManifestHelper::getCssRelPreloadPolyfill(); |
||||||
0 ignored issues
–
show
The function
nystudio107\twigpack\hel...CssRelPreloadPolyfill() has been deprecated: in 1.2.0
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead. ![]() |
|||||||
89 | } |
||||||
90 | |||||||
91 | /** |
||||||
92 | * Return the HTML tags to include the JavaScript module |
||||||
93 | * |
||||||
94 | * @param string $moduleName |
||||||
0 ignored issues
–
show
|
|||||||
95 | * @param bool $async |
||||||
0 ignored issues
–
show
|
|||||||
96 | * @param null|array $config |
||||||
0 ignored issues
–
show
|
|||||||
97 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||||
0 ignored issues
–
show
|
|||||||
98 | * |
||||||
99 | * @return null|string |
||||||
100 | * @throws NotFoundHttpException |
||||||
101 | */ |
||||||
102 | public function getJsModuleTags(string $moduleName, bool $async = false, ?array $config = null, array $attributes = []) |
||||||
103 | { |
||||||
104 | $settings = Twigpack::$plugin->getSettings(); |
||||||
105 | $config = $config ?? $settings->getAttributes(); |
||||||
106 | |||||||
107 | return ManifestHelper::getJsModuleTags($config, $moduleName, $async, $attributes); |
||||||
108 | } |
||||||
109 | |||||||
110 | /** |
||||||
111 | * Return the Safari 10.1 nomodule JavaScript fix |
||||||
112 | * |
||||||
113 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||||
114 | * |
||||||
115 | * @return string |
||||||
116 | */ |
||||||
117 | public function getSafariNomoduleFix(array $attributes = []): string |
||||||
118 | { |
||||||
119 | return ManifestHelper::getSafariNomoduleFix($attributes); |
||||||
120 | } |
||||||
121 | |||||||
122 | /** |
||||||
123 | * Return the URI to a module |
||||||
124 | * |
||||||
125 | * @param string $moduleName |
||||||
0 ignored issues
–
show
|
|||||||
126 | * @param string $type |
||||||
0 ignored issues
–
show
|
|||||||
127 | * @param ?array $config |
||||||
0 ignored issues
–
show
|
|||||||
128 | * |
||||||
129 | * @return null|string |
||||||
130 | * @throws NotFoundHttpException |
||||||
131 | */ |
||||||
132 | public function getModule(string $moduleName, string $type = 'modern', $config = null): ?string |
||||||
133 | { |
||||||
134 | $settings = Twigpack::$plugin->getSettings(); |
||||||
135 | $config = $config ?? $settings->getAttributes(); |
||||||
136 | |||||||
137 | return ManifestHelper::getModule($config, $moduleName, $type); |
||||||
138 | } |
||||||
139 | |||||||
140 | /** |
||||||
141 | * Return the HASH value from a module |
||||||
142 | * |
||||||
143 | * @param string $moduleName |
||||||
0 ignored issues
–
show
|
|||||||
144 | * @param string $type |
||||||
0 ignored issues
–
show
|
|||||||
145 | * @param ?array $config |
||||||
0 ignored issues
–
show
|
|||||||
146 | * |
||||||
147 | * @return null|string |
||||||
148 | * @throws NotFoundHttpException |
||||||
149 | */ |
||||||
150 | public function getModuleHash(string $moduleName, string $type = 'modern', $config = null): ?string |
||||||
151 | { |
||||||
152 | $settings = Twigpack::$plugin->getSettings(); |
||||||
153 | $config = $config ?? $settings->getAttributes(); |
||||||
154 | |||||||
155 | return ManifestHelper::getModuleHash($config, $moduleName, $type); |
||||||
156 | } |
||||||
157 | |||||||
158 | /** |
||||||
159 | * Returns the contents of a file from a URI path |
||||||
160 | * |
||||||
161 | * @param string $path |
||||||
0 ignored issues
–
show
|
|||||||
162 | * |
||||||
163 | * @return string |
||||||
164 | */ |
||||||
165 | public function getFile(string $path): string |
||||||
166 | { |
||||||
167 | return ManifestHelper::getFile($path); |
||||||
168 | } |
||||||
169 | |||||||
170 | /** |
||||||
171 | * Returns the contents of a file from the $fileName in the manifest |
||||||
172 | * |
||||||
173 | * @param string $fileName |
||||||
0 ignored issues
–
show
|
|||||||
174 | * @param string $type |
||||||
0 ignored issues
–
show
|
|||||||
175 | * @param ?array $config |
||||||
0 ignored issues
–
show
|
|||||||
176 | * |
||||||
177 | * @return string |
||||||
178 | */ |
||||||
179 | public function getFileFromManifest(string $fileName, string $type = 'legacy', $config = null): string |
||||||
180 | { |
||||||
181 | $settings = Twigpack::$plugin->getSettings(); |
||||||
182 | $config = $config ?? $settings->getAttributes(); |
||||||
183 | |||||||
184 | return ManifestHelper::getFileFromManifest($config, $fileName, $type); |
||||||
185 | } |
||||||
186 | |||||||
187 | /** |
||||||
188 | * Invalidate the manifest cache |
||||||
189 | */ |
||||||
0 ignored issues
–
show
|
|||||||
190 | public function invalidateCaches() |
||||||
191 | { |
||||||
192 | ManifestHelper::invalidateCaches(); |
||||||
193 | } |
||||||
194 | } |
||||||
195 |