PHP Class 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.
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Méthode Description
__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.

Private Methods

Méthode Description
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.

Method Details

__construct() public méthode

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() public méthode

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() public méthode

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.
Résultat boolean Returns **true** if the addon a

checkRequirements() public méthode

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.
Résultat boolean Returns **true** if the requirements are met or **false** otherwise.

clearCache() public méthode

Remove all of the cached files.
public clearCache ( ) : boolean
Résultat boolean Returns **true** if the files were removed or **false** otherwise.

getCacheDir() public méthode

Get the cacheDir.
public getCacheDir ( ) : string
Résultat string Returns the cacheDir.

getEnabled() public méthode

Get the enabled addons, sorted by priority with the highest priority first.
public getEnabled ( ) : array[Addon]
Résultat array[Addon]

getEnabledTranslationPaths() public méthode

Get the paths to the current translation files.
public getEnabledTranslationPaths ( string $locale ) : array
$locale string The locale to get the translation paths for.
Résultat array Returns an array of paths.

getTheme() public méthode

Get the theme.
public getTheme ( ) : Addon | null
Résultat Addon | null Returns the theme.

isEnabled() public méthode

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.
Résultat boolean Returns

lookupAddon() public méthode

Lookup the addon with a given key.
public lookupAddon ( string $key ) : Addon | null
$key string The key of the addon.
Résultat Addon | null

lookupAllByType() public méthode

Get all of the addons of a certain type.
public lookupAllByType ( string $type ) : array
$type string One of the **Addon::TYPE_*** constants.
Résultat array

lookupAsset() public méthode

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.
Résultat string

lookupByClassname() public méthode

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.
Résultat Addon | null Returns an {@link Addon} object or **null** if one isn't found.

lookupByType() public méthode

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.
Résultat null | Addon Returns the addon or **null** if one isn't found.

lookupDependants() public méthode

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.
Résultat array Returns an array of {@link Addon} objects.

lookupLocale() public méthode

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.
Résultat null | Addon Returns an {@link Addon} object for the locale pack or **null** if it can't be found.

lookupRequirements() public méthode

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 `|`.
Résultat Returns the requirements array. An empty array represents an addon with no requirements.

lookupTheme() public méthode

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.
Résultat null | Addon Returns an {@link Addon} object for the theme or **null** if it can't be found.

scan() public méthode

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.
Résultat array Returns an array of {@link Addon} objects.

setCacheDir() public méthode

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.
Résultat AddonManager Returns `$this` for fluent calls.

setTheme() public méthode

Set the theme.
public setTheme ( Addon $theme ) : AddonManager
$theme Addon The new theme to set.
Résultat AddonManager Returns `$this` for fluent calls.

startAddon() public méthode

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

startAddonsByKey() public méthode

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.
Résultat integer Returns the number of addons that were enabled.

stopAddon() public méthode

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

stopAddonsByKey() public méthode

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.
Résultat integer Returns the number of addons that were stopped.