1 | <?php |
||
9 | class Module implements Serializable |
||
10 | { |
||
11 | /** |
||
12 | * Directory |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $path = null; |
||
17 | |||
18 | /** |
||
19 | * Base folder of application |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $basePath = null; |
||
24 | |||
25 | /** |
||
26 | * Cache of composer data |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $composerData = null; |
||
31 | |||
32 | public function __construct($path, $base) |
||
38 | |||
39 | /** |
||
40 | * Gets name of this module. Used as unique key and identifier for this module. |
||
41 | * |
||
42 | * If installed by composer, this will be the full composer name (vendor/name). |
||
43 | * If not insalled by composer this will default to the basedir() |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getName() |
||
51 | |||
52 | /** |
||
53 | * Get full composer name. Will be null if no composer.json is available |
||
54 | * |
||
55 | * @return string|null |
||
56 | */ |
||
57 | public function getComposerName() |
||
64 | |||
65 | /** |
||
66 | * Gets "short" name of this module. This is the base directory this module |
||
67 | * is installed in. |
||
68 | * |
||
69 | * If installed in root, this will be generated from the composer name instead |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getShortName() |
||
93 | |||
94 | /** |
||
95 | * Get base path for this module |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getPath() |
||
103 | |||
104 | /** |
||
105 | * Get path relative to base dir. |
||
106 | * If module path is base this will be empty string |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getRelativePath() |
||
114 | |||
115 | public function serialize() |
||
119 | |||
120 | public function unserialize($serialized) |
||
124 | |||
125 | /** |
||
126 | * Activate _config.php for this module, if one exists |
||
127 | */ |
||
128 | public function activate() |
||
135 | |||
136 | /** |
||
137 | * @throws Exception |
||
138 | */ |
||
139 | protected function loadComposer() |
||
153 | |||
154 | /** |
||
155 | * Gets path to physical file resource relative to base directory. |
||
156 | * Directories included |
||
157 | * |
||
158 | * This method makes no distinction between public / local resources, |
||
159 | * which may change in the near future. |
||
160 | * |
||
161 | * @internal Experimental API and may change |
||
162 | * @param string $path File or directory path relative to module directory |
||
163 | * @return string Path relative to base directory |
||
164 | */ |
||
165 | public function getRelativeResourcePath($path) |
||
171 | |||
172 | /** |
||
173 | * Gets path to physical file resource relative to base directory. |
||
174 | * Directories included |
||
175 | * |
||
176 | * This method makes no distinction between public / local resources, |
||
177 | * which may change in the near future. |
||
178 | * |
||
179 | * @internal Experimental API and may change |
||
180 | * @param string $path File or directory path relative to module directory |
||
181 | * @return string Path relative to base directory |
||
182 | */ |
||
183 | public function getResourcePath($path) |
||
187 | |||
188 | /** |
||
189 | * Gets the URL for a given resource. |
||
190 | * Relies on the ModuleURLGenerator Injector service to do the heavy lifting |
||
191 | * |
||
192 | * @internal Experimental API and may change |
||
193 | * @param string $path File or directory path relative to module directory |
||
194 | * @return string URL, either domain-relative (starting with /) or absolute |
||
195 | */ |
||
196 | public function getResourceURL($path) |
||
202 | |||
203 | /** |
||
204 | * Check if this module has a given resource |
||
205 | * |
||
206 | * @internal Experimental API and may change |
||
207 | * @param string $path |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function hasResource($path) |
||
214 | } |
||
215 |
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.