1 | <?php |
||
30 | class Plugin extends CakePlugin |
||
31 | { |
||
32 | |||
33 | use StaticCacheTrait; |
||
34 | |||
35 | /** |
||
36 | * Get the given plugin as an object, or a collection of objects if not |
||
37 | * specified. |
||
38 | * |
||
39 | * @param string $plugin Plugin name to get, or null to get a collection of |
||
40 | * all plugin objects |
||
41 | * @return \CMS\Core\Package\PluginPackage|\Cake\Collection\Collection |
||
42 | * @throws \Cake\Error\FatalErrorException When requested plugin was not found |
||
43 | */ |
||
44 | public static function get($plugin = null) |
||
71 | |||
72 | /** |
||
73 | * Scan plugin directories and returns plugin names and their paths within file |
||
74 | * system. We consider "plugin name" as the name of the container directory. |
||
75 | * |
||
76 | * Example output: |
||
77 | * |
||
78 | * ```php |
||
79 | * [ |
||
80 | * 'Users' => '/full/path/plugins/Users/', |
||
81 | * 'ThemeManager' => '/full/path/plugins/ThemeManager/', |
||
82 | * ... |
||
83 | * 'MySuperPlugin' => '/full/path/plugins/MySuperPlugin/', |
||
84 | * 'DarkGreenTheme' => '/full/path/plugins/DarkGreenTheme/', |
||
85 | * ] |
||
86 | * ``` |
||
87 | * |
||
88 | * If $ignoreThemes is set to true `DarkGreenTheme` will not be part of the |
||
89 | * result. |
||
90 | * |
||
91 | * NOTE: All paths includes trailing slash. |
||
92 | * |
||
93 | * @param bool $ignoreThemes Whether include themes as well or not |
||
94 | * @return array Associative array as `PluginName` => `/full/path/to/PluginName` |
||
95 | */ |
||
96 | public static function scan($ignoreThemes = false) |
||
139 | |||
140 | /** |
||
141 | * Checks whether a plugins is installed on the system regardless of its status. |
||
142 | * |
||
143 | * @param string $plugin Plugin to check |
||
144 | * @return bool True if exists, false otherwise |
||
145 | */ |
||
146 | public static function exists($plugin) |
||
151 | |||
152 | /** |
||
153 | * Validates a composer.json file. |
||
154 | * |
||
155 | * Below a list of validation rules that are applied: |
||
156 | * |
||
157 | * - must be a valid JSON file. |
||
158 | * - key `name` must be present and follow the pattern `author/package` |
||
159 | * - key `type` must be present. |
||
160 | * - key `extra.regions` must be present if it's a theme (its name ends with |
||
161 | * `-theme`, e.g. `quickapps/blue-sky-theme`) |
||
162 | * |
||
163 | * ### Usage: |
||
164 | * |
||
165 | * ```php |
||
166 | * $json = json_decode(file_gets_content('/path/to/composer.json'), true); |
||
167 | * Plugin::validateJson($json); |
||
168 | * |
||
169 | * // OR: |
||
170 | * |
||
171 | * Plugin::validateJson('/path/to/composer.json'); |
||
172 | * ``` |
||
173 | * |
||
174 | * @param array|string $json JSON given as an array result of |
||
175 | * `json_decode(..., true)`, or a string as path to where .json file can be found |
||
176 | * @param bool $errorMessages If set to true an array of error messages |
||
177 | * will be returned, if set to false boolean result will be returned; true on |
||
178 | * success, false on validation failure. Defaults to false (boolean result) |
||
179 | * @return array|bool |
||
180 | */ |
||
181 | public static function validateJson($json, $errorMessages = false) |
||
212 | |||
213 | /** |
||
214 | * Checks if there is any active plugin that depends of $plugin. |
||
215 | * |
||
216 | * @param string|CMS\Package\PluginPackage $plugin Plugin name, package |
||
217 | * name (as `vendor/package`) or plugin package object result of |
||
218 | * `static::get()` |
||
219 | * @return array A list of all plugin names that depends on $plugin, an empty |
||
220 | * array means that no other plugins depends on $pluginName, so $plugin can be |
||
221 | * safely deleted or turned off. |
||
222 | * @throws \Cake\Error\FatalErrorException When requested plugin was not found |
||
223 | * @see \CMS\Core\Plugin::get() |
||
224 | */ |
||
225 | public static function checkReverseDependency($plugin) |
||
234 | } |
||
235 |