PHP Класс Vanilla\AddonManager

The {@link AddonManager} scans directories for addon folders and then maintains them in a catalogue. Addons can then be started which makes them available to the application. When an addon is started it can do the following: - Any classes the addon has declared are available via the {@link AddonManager::autoload()} method. - The addon can declare a class ending in "Plugin" and its events will be registered (TODO). - Any translations the addon has declared will be loaded for the currently enabled locale.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( array $scanDirs, string $cacheDir ) Initialize a new instance of the {@link AddonManager} class.
autoload ( string $class ) Attempt to load undefined class based on the addons that are enabled.
checkDependants ( Addon $addon, boolean $throw = false ) : boolean Check the enabled dependants of an addon.
checkRequirements ( Addon $addon, boolean $throw = false ) : boolean Check an addon's requirements.
clearCache ( ) : boolean Remove all of the cached files.
getCacheDir ( ) : string Get the cacheDir.
getEnabled ( ) : array[Addon] Get the enabled addons, sorted by priority with the highest priority first.
getEnabledTranslationPaths ( string $locale ) : array Get the paths to the current translation files.
getTheme ( ) : Addon | null Get the theme.
isEnabled ( string $key, string $type ) : boolean Check whether or not an addon is enabled.
lookupAddon ( string $key ) : Addon | null Lookup the addon with a given key.
lookupAllByType ( string $type ) : array Get all of the addons of a certain type.
lookupAsset ( string $subpath, Addon $addon = null, boolean $mustExist = true ) : string Lookup the path of an asset.
lookupByClassname ( string $class, boolean $searchAll = false ) : Addon | null Lookup an addon by class name.
lookupByType ( string $key, string $type ) : null | Addon Lookup an {@link Addon} by its type.
lookupDependants ( Addon $addon ) : array Get all of the enabled addons that depend on a given addon.
lookupLocale ( string $key ) : null | Addon Lookup a locale pack based on its key.
lookupRequirements ( Addon $addon, integer $filter = null ) : Returns Get all of the requirements for an addon.
lookupTheme ( string $key ) : null | Addon Lookup a theme based on its key.
scan ( string $type, boolean $saveCache = false ) : array Scan the directories of all of the addons of a given type.
setCacheDir ( string $cacheDir ) : AddonManager Set the cacheDir.
setTheme ( Addon $theme ) : AddonManager Set the theme.
startAddon ( Addon $addon ) Start an addon and make it available.
startAddonsByKey ( array $keys, string $type ) : integer Start one or more addons by specifying their keys.
stopAddon ( Addon $addon ) Stop an addon and make it unavailable.
stopAddonsByKey ( array $keys, string $type ) : integer Stop one or more addons by specifying their keys.

Приватные методы

Метод Описание
deleteSingleIndexKey ( string $type, string $key ) : boolean Delete an item from a single index and re-cache it.
ensureMultiCache ( ) Ensure that the addon cache has all of the addons.
filePutContents ( string $filename, mixed $data, integer $mode = 420 ) : boolean A version of file_put_contents() that is multi-thread safe.
getSingleIndex ( string $type ) : array Get the index for an addon type that is cached by single addon.
lookupRequirementsRecursive ( Addon $addon, array &$array ) The implementation of {@link lookupRequirements()}.
lookupSingleCachedAddon ( string $key, string $type ) : Addon | null Lookup an addon that is cached on a per-addon basis.
saveArrayCache ( string $path, string $array ) Cache an array.
scanAddonDirs ( string $type ) : array Get a list of addon directories for a given type.
themeSubdirs ( ) : array Get the current theme and themes it's based on as an array.
typeUsesMultiCaching ( string $type ) : boolean Test whether an addon type uses multi-caching.

Описание методов

__construct() публичный Метод

Initialize a new instance of the {@link AddonManager} class.
public __construct ( array $scanDirs, string $cacheDir )
$scanDirs array An array of root-relative directories to scan indexed by **Addon::TYPE_*** constant. Applications and plugins are treated as the same so pass their directories as an array with the **Addon::TYPE_ADDON** key.
$cacheDir string The path to the cache.

autoload() публичный Метод

Attempt to load undefined class based on the addons that are enabled.
public autoload ( string $class )
$class string The name of the class to load.

checkDependants() публичный Метод

Addons should always check their dependants before being disabled. This check does not consider dependants that are not enabled.
public checkDependants ( Addon $addon, boolean $throw = false ) : boolean
$addon Addon The addon to check.
$throw boolean Whether or not to throw an exception or just return **false** if the check fails.
Результат boolean Returns **true** if the addon a

checkRequirements() публичный Метод

An addon cannot be enabled if it has missing or invalid requirements. If an addon has requirements that are simply disabled it will pass this test as long as it's requirements also meet *their* requirements.
public checkRequirements ( Addon $addon, boolean $throw = false ) : boolean
$addon Addon The addon to check.
$throw boolean Whether or not to throw an exception if the requirements are not met.
Результат boolean Returns **true** if the requirements are met or **false** otherwise.

clearCache() публичный Метод

Remove all of the cached files.
public clearCache ( ) : boolean
Результат boolean Returns **true** if the files were removed or **false** otherwise.

getCacheDir() публичный Метод

Get the cacheDir.
public getCacheDir ( ) : string
Результат string Returns the cacheDir.

getEnabled() публичный Метод

Get the enabled addons, sorted by priority with the highest priority first.
public getEnabled ( ) : array[Addon]
Результат array[Addon]

getEnabledTranslationPaths() публичный Метод

Get the paths to the current translation files.
public getEnabledTranslationPaths ( string $locale ) : array
$locale string The locale to get the translation paths for.
Результат array Returns an array of paths.

getTheme() публичный Метод

Get the theme.
public getTheme ( ) : Addon | null
Результат Addon | null Returns the theme.

isEnabled() публичный Метод

Check whether or not an addon is enabled.
public isEnabled ( string $key, string $type ) : boolean
$key string The addon key.
$type string One of the **Addon::TYPE_*** constants.
Результат boolean Returns

lookupAddon() публичный Метод

Lookup the addon with a given key.
public lookupAddon ( string $key ) : Addon | null
$key string The key of the addon.
Результат Addon | null

lookupAllByType() публичный Метод

Get all of the addons of a certain type.
public lookupAllByType ( string $type ) : array
$type string One of the **Addon::TYPE_*** constants.
Результат array

lookupAsset() публичный Метод

Lookup the path of an asset.
public lookupAsset ( string $subpath, Addon $addon = null, boolean $mustExist = true ) : string
$subpath string The subpath of the asset, relative an addon root.
$addon Addon The addon that should contain the asset.
$mustExist boolean Whether or not the asset must exist in the addon.
Результат string

lookupByClassname() публичный Метод

This method should only be used with enabled addons as searching through all addons takes a performance hit.
public lookupByClassname ( string $class, boolean $searchAll = false ) : Addon | null
$class string The class name.
$searchAll boolean Whether or not to search all addons or just the enabled ones.
Результат Addon | null Returns an {@link Addon} object or **null** if one isn't found.

lookupByType() публичный Метод

Lookup an {@link Addon} by its type.
public lookupByType ( string $key, string $type ) : null | Addon
$key string The addon's key.
$type string One of the **Addon::TYPE_*** constants.
Результат null | Addon Returns the addon or **null** if one isn't found.

lookupDependants() публичный Метод

Get all of the enabled addons that depend on a given addon.
public lookupDependants ( Addon $addon ) : array
$addon Addon The addon to check the requirements.
Результат array Returns an array of {@link Addon} objects.

lookupLocale() публичный Метод

The local pack's key MUST be the same as the folder it's in.
public lookupLocale ( string $key ) : null | Addon
$key string The key of the locale pack.
Результат null | Addon Returns an {@link Addon} object for the locale pack or **null** if it can't be found.

lookupRequirements() публичный Метод

This method returns an array of all of the addon requirements for a given addon. The return is an array of requirements in the following form: 'addonKey' => ['req' => 'versionRequirement', 'status' => AddonManager::REQ_*]
public lookupRequirements ( Addon $addon, integer $filter = null ) : Returns
$addon Addon The addon to check.
$filter integer One or more of the **AddonManager::REQ_*** constants concatenated by `|`.
Результат Returns the requirements array. An empty array represents an addon with no requirements.

lookupTheme() публичный Метод

The theme's key MUST be the same as the folder it's in.
public lookupTheme ( string $key ) : null | Addon
$key string The key of the theme.
Результат null | Addon Returns an {@link Addon} object for the theme or **null** if it can't be found.

scan() публичный Метод

Scan the directories of all of the addons of a given type.
public scan ( string $type, boolean $saveCache = false ) : array
$type string One of the **Addon::TYPE_*** constants.
$saveCache boolean Whether or not to save the found addons to the cache.
Результат array Returns an array of {@link Addon} objects.

setCacheDir() публичный Метод

Set the cacheDir.
public setCacheDir ( string $cacheDir ) : AddonManager
$cacheDir string The cache directory to set. If this doesn't include **PATH_ROOT** then it will be prepended.
Результат AddonManager Returns `$this` for fluent calls.

setTheme() публичный Метод

Set the theme.
public setTheme ( Addon $theme ) : AddonManager
$theme Addon The new theme to set.
Результат AddonManager Returns `$this` for fluent calls.

startAddon() публичный Метод

Start an addon and make it available.
public startAddon ( Addon $addon )
$addon Addon The addon to start.

startAddonsByKey() публичный Метод

This method is useful for starting the addons that are stored in a configuration file.
public startAddonsByKey ( array $keys, string $type ) : integer
$keys array The keys of the addons. The addon keys can be the keys of the array or the values.
$type string One of the **Addon::TYPE_*** constants.
Результат integer Returns the number of addons that were enabled.

stopAddon() публичный Метод

Stop an addon and make it unavailable.
public stopAddon ( Addon $addon )
$addon Addon The addon to stop.

stopAddonsByKey() публичный Метод

Stop one or more addons by specifying their keys.
public stopAddonsByKey ( array $keys, string $type ) : integer
$keys array The keys of the addons. The addon keys can be the keys of the array or the values.
$type string One of the **Addon::TYPE_*** constants.
Результат integer Returns the number of addons that were stopped.