\QuickApps\CorePlugin

Plugin is used to load and locate plugins.

Wrapper for Cake\Core\Plugin, it adds some QuickAppsCMS specifics methods.

Summary

Methods
Properties
Constants
get()
scan()
exists()
validateJson()
checkReverseDependency()
cache()
dropCache()
No public properties found
No constants found
No protected methods found
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_cache

$_cache : array

Used internally.

Type

array

Methods

get()

get(string $plugin) : \QuickApps\Core\Package\PluginPackage|\Cake\Collection\Collection

Get the given plugin as an object, or a collection of objects if not specified.

Parameters

string $plugin

Plugin name to get, or null to get a collection of all plugin objects

Throws

\Cake\Error\FatalErrorException

When requested plugin was not found

Returns

\QuickApps\Core\Package\PluginPackage|\Cake\Collection\Collection

scan()

scan(boolean $ignoreThemes) : array

Scan plugin directories and returns plugin names and their paths within file system. We consider "plugin name" as the name of the container directory.

Example output:

[
    'Users' => '/full/path/plugins/Users/',
    'ThemeManager' => '/full/path/plugins/ThemeManager/',
    ...
    'MySuperPlugin' => '/full/path/plugins/MySuperPlugin/',
    'DarkGreenTheme' => '/full/path/plugins/DarkGreenTheme/',
]

If $ignoreThemes is set to true DarkGreenTheme will not be part of the result.

NOTE: All paths includes trailing slash.

Parameters

boolean $ignoreThemes

Whether include themes as well or not

Returns

array —

Associative array as PluginName => /full/path/to/PluginName

exists()

exists(string $plugin) : boolean

Checks whether a plugins is installed on the system regardless of its status.

Parameters

string $plugin

Plugin to check

Returns

boolean —

True if exists, false otherwise

validateJson()

validateJson(array|string $json, boolean $errorMessages) : array|boolean

Validates a composer.json file.

Below a list of validation rules that are applied:

  • must be a valid JSON file.
  • key name must be present and follow the pattern author/package
  • key type must be present.
  • key extra.regions must be present if it's a theme (its name ends with -theme, e.g. quickapps/blue-sky-theme)

Usage:

$json = json_decode(file_gets_content('/path/to/composer.json'), true);
Plugin::validateJson($json);

// OR:

Plugin::validateJson('/path/to/composer.json');

Parameters

array|string $json

JSON given as an array result of json_decode(..., true), or a string as path to where .json file can be found

boolean $errorMessages

If set to true an array of error messages will be returned, if set to false boolean result will be returned; true on success, false on validation failure. Defaults to false (boolean result)

Returns

array|boolean

checkReverseDependency()

checkReverseDependency(string $pluginName) : array

Checks if there is any active plugin that depends of $pluginName.

Parameters

string $pluginName

Plugin name to check

Returns

array —

A list of all plugin names that depends on $pluginName, an empty array means that no other plugins depends on $pluginName, so $pluginName can be safely deleted or turned off.

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.