1 | <?php |
||||
2 | namespace Mezon\HtmlTemplate; |
||||
3 | |||||
4 | /** |
||||
5 | * Class TemplateResources |
||||
6 | * |
||||
7 | * @package Mezon |
||||
8 | * @subpackage TemplateResources |
||||
9 | * @author Dodonov A.A. |
||||
10 | * @version v.1.0 (2019/08/17) |
||||
11 | * @copyright Copyright (c) 2019, aeon.org |
||||
12 | */ |
||||
13 | |||||
14 | /** |
||||
15 | * Class collects resources for page. |
||||
16 | * |
||||
17 | * Any including components can add to the page their own resources without having access to the application or template. |
||||
18 | */ |
||||
19 | class TemplateResources |
||||
20 | { |
||||
21 | |||||
22 | /** |
||||
23 | * Custom CSS files to be included. |
||||
24 | */ |
||||
25 | private static $cSSFiles = false; |
||||
26 | |||||
27 | /** |
||||
28 | * Custom JS files to be included. |
||||
29 | */ |
||||
30 | private static $jSFiles = false; |
||||
31 | |||||
32 | /** |
||||
33 | * Constructor. |
||||
34 | */ |
||||
35 | function __construct() |
||||
36 | { |
||||
37 | if (self::$cSSFiles === false) { |
||||
38 | self::$cSSFiles = []; |
||||
39 | } |
||||
40 | if (self::$jSFiles === false) { |
||||
41 | self::$jSFiles = []; |
||||
42 | } |
||||
43 | } |
||||
44 | |||||
45 | /** |
||||
46 | * Additing single CSS file |
||||
47 | * |
||||
48 | * @param string $cSSFile |
||||
49 | * CSS file |
||||
50 | */ |
||||
51 | function addCssFile(string $cSSFile) |
||||
0 ignored issues
–
show
|
|||||
52 | { |
||||
53 | // additing only unique paths |
||||
54 | if (array_search($cSSFile, self::$cSSFiles) === false) { |
||||
0 ignored issues
–
show
self::cSSFiles of type boolean is incompatible with the type array expected by parameter $haystack of array_search() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
55 | self::$cSSFiles[] = \Mezon\Conf\Conf::expandString($cSSFile); |
||||
56 | } |
||||
57 | } |
||||
58 | |||||
59 | /** |
||||
60 | * Additing multyple CSS files |
||||
61 | * |
||||
62 | * @param array $cSSFiles |
||||
63 | * CSS files |
||||
64 | */ |
||||
65 | function addCssFiles(array $cSSFiles) |
||||
0 ignored issues
–
show
|
|||||
66 | { |
||||
67 | foreach ($cSSFiles as $cSSFile) { |
||||
68 | $this->addCssFile($cSSFile); |
||||
69 | } |
||||
70 | } |
||||
71 | |||||
72 | /** |
||||
73 | * Method returning added CSS files |
||||
74 | */ |
||||
75 | function getCssFiles() |
||||
0 ignored issues
–
show
|
|||||
76 | { |
||||
77 | return self::$cSSFiles; |
||||
78 | } |
||||
79 | |||||
80 | /** |
||||
81 | * Additing single CSS file |
||||
82 | * |
||||
83 | * @param string $jSFile |
||||
84 | * JS file |
||||
85 | */ |
||||
86 | function addJsFile($jSFile) |
||||
0 ignored issues
–
show
|
|||||
87 | { |
||||
88 | // additing only unique paths |
||||
89 | if (array_search($jSFile, self::$jSFiles) === false) { |
||||
0 ignored issues
–
show
self::jSFiles of type boolean is incompatible with the type array expected by parameter $haystack of array_search() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
90 | self::$jSFiles[] = \Mezon\Conf\Conf::expandString($jSFile); |
||||
91 | } |
||||
92 | } |
||||
93 | |||||
94 | /** |
||||
95 | * Additing multyple CSS files |
||||
96 | * |
||||
97 | * @param array $jSFiles |
||||
98 | * JS files |
||||
99 | */ |
||||
100 | function addJsFiles(array $jSFiles) |
||||
0 ignored issues
–
show
|
|||||
101 | { |
||||
102 | foreach ($jSFiles as $jSFile) { |
||||
103 | $this->addJsFile($jSFile); |
||||
104 | } |
||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * Method returning added JS files. |
||||
109 | */ |
||||
110 | function getJsFiles() |
||||
0 ignored issues
–
show
|
|||||
111 | { |
||||
112 | return self::$jSFiles; |
||||
113 | } |
||||
114 | |||||
115 | /** |
||||
116 | * Method clears loaded resources. |
||||
117 | */ |
||||
118 | function clear() |
||||
0 ignored issues
–
show
|
|||||
119 | { |
||||
120 | self::$cSSFiles = []; |
||||
121 | |||||
122 | self::$jSFiles = []; |
||||
123 | } |
||||
124 | } |
||||
125 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.