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.
파일 보기 프로젝트 열기: vanilla/vanilla 1 사용 예제들

공개 메소드들

메소드 설명
__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.