1 | <?php |
||
9 | class WebLibrary implements WebLibraryInterface |
||
10 | { |
||
11 | |||
12 | |||
13 | /** |
||
14 | * List of JS files to add in header. |
||
15 | * If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL. |
||
16 | * |
||
17 | * @var array<string> |
||
18 | */ |
||
19 | private $jsFiles = array(); |
||
20 | |||
21 | /** |
||
22 | * List of CSS files to add in header. |
||
23 | * If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL. |
||
24 | * |
||
25 | * @var array<string> |
||
26 | */ |
||
27 | private $cssFiles = array(); |
||
28 | |||
29 | /** |
||
30 | * List of libraries this library depends on. |
||
31 | * |
||
32 | * @var array<WebLibraryInterface> |
||
33 | */ |
||
34 | private $dependencies = array(); |
||
35 | |||
36 | /** |
||
37 | * Boolean whether the dependencies are called asynchronously |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $async = false; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $rootUrl; |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Constructor |
||
51 | * |
||
52 | * @param string[] $jsFiles List of JS files to add in header. If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL. |
||
53 | * @param string[] $cssFiles List of CSS files to add in header. If you don't specify http:// or https:// and if your URL does not start with /, the file is considered to be relative to ROOT_URL. |
||
54 | * @param string $rootUrl The ROOT url of your application. It should not contain the complete domain name, only the path, starting and ending with a /. For instance: '/foo/bar/' or '/' |
||
55 | */ |
||
56 | |||
57 | public function __construct(array $jsFiles = [], array $cssFiles = [], string $rootUrl = '/') |
||
63 | |||
64 | /** |
||
65 | * Returns an array of Javascript files to be included for this library. |
||
66 | * |
||
67 | * @return array<string> |
||
68 | */ |
||
69 | public function getJsFiles(): array |
||
73 | |||
74 | /** |
||
75 | * List of JS files to put in the web library. |
||
76 | * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p> |
||
77 | * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div> |
||
78 | * |
||
79 | * @param array<string> $jsFiles |
||
80 | */ |
||
81 | public function setJsFiles(array $jsFiles): void |
||
85 | |||
86 | /** |
||
87 | * Adds a JS file to the web library. |
||
88 | * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p> |
||
89 | * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div> |
||
90 | * |
||
91 | * @param string $jsFile |
||
92 | */ |
||
93 | public function addJsFile(string $jsFile): void |
||
97 | |||
98 | /** |
||
99 | * Returns an array of CSS files to be included for this library. |
||
100 | * |
||
101 | * @return array<string> |
||
102 | */ |
||
103 | public function getCssFiles(): array |
||
107 | |||
108 | /** |
||
109 | * List of CSS files to add in web library. |
||
110 | * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p> |
||
111 | * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div> |
||
112 | * |
||
113 | * @Property |
||
114 | * @param array<string> $cssFiles |
||
115 | */ |
||
116 | public function setCssFiles(array $cssFiles): void |
||
120 | |||
121 | /** |
||
122 | * Adds a CSS file to the web library. |
||
123 | * <p>If you don't specify http:// or https:// and if the file does not start with /, the file is considered to be relative to ROOT_URL.</p> |
||
124 | * <div class="info">It is a good practice to make sure the file does not start with /, http:// or https:// (unless you are using a CDN).</div> |
||
125 | * |
||
126 | * @param string $cssFile |
||
127 | */ |
||
128 | public function addCssFile(string $cssFile): void |
||
132 | |||
133 | /** |
||
134 | * Returns a list of libraries that must be included before this library is included. |
||
135 | * |
||
136 | * @return array<WebLibraryInterface> |
||
137 | */ |
||
138 | public function getDependencies(): array |
||
142 | |||
143 | /** |
||
144 | * The list of all libraries that are needed for this library |
||
145 | * |
||
146 | * @Property |
||
147 | * @param array<WebLibraryInterface> $libraries |
||
148 | */ |
||
149 | public function setDependencies(array $libraries): void |
||
153 | |||
154 | /** |
||
155 | * Returns if the dependencies are loaded asynchronously |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isAsync(): bool |
||
163 | |||
164 | /** |
||
165 | * Set if the dependencies are loaded asynchronously |
||
166 | * |
||
167 | * @Property |
||
168 | * @param bool $async |
||
169 | */ |
||
170 | public function setIsAsync(bool $async): void |
||
174 | |||
175 | /** |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getRootUrl(): string |
||
182 | } |
||
183 |