1 | <?php |
||
21 | class WebLibraryManager implements HtmlElementInterface { |
||
22 | |||
23 | /** |
||
24 | * The array of all included libraries. |
||
25 | * |
||
26 | * @var WebLibraryInterface[] |
||
27 | */ |
||
28 | private $webLibraries = array(); |
||
29 | |||
30 | /** |
||
31 | * false if the toHtml method has not yet been called, true if it has been called. |
||
32 | * @var boolean |
||
33 | */ |
||
34 | private $rendered = false; |
||
35 | |||
36 | /** |
||
37 | * The renderer used by the application. Usually, this points to the 'defaultRenderer' instance. |
||
38 | * |
||
39 | * @var RendererInterface |
||
40 | */ |
||
41 | private $renderer; |
||
42 | |||
43 | /** |
||
44 | * |
||
45 | * @param RendererInterface $renderer The renderer used by the application. Usually, this points to the 'defaultRenderer' instance. |
||
46 | */ |
||
47 | public function __construct(RendererInterface $renderer) { |
||
50 | |||
51 | /** |
||
52 | * Adds a library to the list of libraries that should be loaded in the web page. |
||
53 | * <p>The function will also load the dependencies (if any) and will have no effect if the library has already been loaded.</p> |
||
54 | * |
||
55 | * @param WebLibraryInterface $library |
||
56 | */ |
||
57 | public function addLibrary(WebLibraryInterface $library) { |
||
74 | |||
75 | /** |
||
76 | * The list of all libraries that should be loaded in the web page. |
||
77 | * <p>If you do not pass all dependencies of a library, the dependencies will be loaded automatically.</p> |
||
78 | * |
||
79 | * @param array<WebLibraryInterface> $libraries |
||
80 | */ |
||
81 | public function setWebLibraries($libraries) { |
||
86 | |||
87 | /** |
||
88 | * Renders the HTML in charge of loading CSS and JS files. |
||
89 | * The Html is echoed directly into the output. |
||
90 | * This function should be called within the head tag. |
||
91 | * |
||
92 | */ |
||
93 | public function toHtml() { |
||
104 | |||
105 | /** |
||
106 | * Adds a single JS file to the list of files to be included in the <head> tag. |
||
107 | * <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> |
||
108 | * <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> |
||
109 | * |
||
110 | * @param string $jsFile |
||
111 | */ |
||
112 | public function addJsFile($jsFile) { |
||
115 | |||
116 | /** |
||
117 | * Adds a single CSS file to the list of files to be included in the <head> tag. |
||
118 | * <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> |
||
119 | * <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> |
||
120 | * |
||
121 | * @param string $cssFile |
||
122 | */ |
||
123 | public function addCssFile($cssFile) { |
||
126 | |||
127 | /** |
||
128 | * Adds an additional script at the end of the <head> tag. |
||
129 | * The provided script can either be a string or an object implementing HtmlElementInterface. |
||
130 | * |
||
131 | * @param string|HtmlElementInterface $additionalScript |
||
132 | */ |
||
133 | public function addAdditionalScript($additionalScript) { |
||
139 | |||
140 | /** |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getCssHtml() { |
||
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getJsHtml() { |
||
161 | |||
162 | /** |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getAdditionalHtml() { |
||
172 | } |
||
173 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.