PHP Class Vanilla\Addon

Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Méthode Description
__construct ( string $subdir = '' ) Addon constructor.
__set_state ( array $array ) : Addon Support {@link var_export()} for caching.
check ( boolean $trigger = false ) : array Check the addon for data issues.
checkVersion ( string $version, string $requirement ) Check a version against a version requirement.
comparePriority ( Addon $a, Addon $b ) : integer Compare two addon's by priority so that they can be sorted.
getClassPath ( string $classname, string $relative = self::PATH_FULL ) : string Get the path of a class within this addon.
getClasses ( ) : array Get the classes.
getIcon ( string $relative = self::PATH_ADDON ) : string Get the path to the icon for this addon.
getInfo ( ) : array Get the info.
getInfoValue ( string $key, mixed $default = null ) : mixed Get a single value from the info array.
getKey ( ) : string Get this addon's key.
getName ( ) : string Get this addon's human-readable name.
getPluginClass ( ) : string Get the name of the plugin class for this addon, if any.
getPriority ( ) : integer Get the priority of this addon.
getRawKey ( ) : string Get this addon's raw case-sensitive key.
getRequirements ( ) : array Get the required addons for this addon.
getSpecial ( string $key, mixed $default = null ) : mixed Get an item from the special array.
getSubdir ( ) : string Get the subdir.
getTranslationPaths ( string $locale = '' ) : array Get translation paths.
getType ( ) : string Get the type of addon.
getVersion ( ) : string Get the version number of the addon.
makeFilterCallback ( array $where ) : Closure Return a function that can be used as a callback to filter arrays of {@link Addon} objects.
path ( string $subpath = '', string $relative = self::PATH_FULL ) : string Make a full path from an addon-relative path.
scan ( string $subdir ) Scan a subdirectory and setup this addon.
test ( boolean $throw = true ) : boolean Do a very basic test of this addon.

Private Methods

Méthode Description
canonicalizeLocale ( string $locale ) : string Canonicalize a locale string so different representations of the same locale can be used together.
convertRequire ( array $info, array $keys ) Convert the info array style requirements to the composer-like require format.
glob ( string $pattern ) : array Perform a glob from this addon's subdirectory.
scanClassPaths ( )
scanClasses ( ) : array Scan for all of the classes in this addon.
scanFile ( string $path ) : array Looks what classes and namespaces are defined in a file and returns them.
scanInfo ( ) : array | null Get an addon's meta info.
scanInfoArray ( string $subpath ) : array | null Scan an addon's info array.
scanTranslations ( ) Scan the addon for translation files.
setClasses ( array $classes ) : Addon Set the classes.
setInfo ( array $info ) : Addon Set the info.
setSpecialArray ( array $special ) : Addon Set the special array.
setSubdir ( string $subdir ) : Addon Set the root-relative subdirectory of the addon.
setTranslationPaths ( array $translations ) : Addon Set the translation paths.
splitAuthors ( array $author ) : array[array[string]] Split an author array that may contain multiple authors separated by commas.
splitRequirement ( string $requirement ) : array Split a requirements string into comparisons.
testRequirement ( string $version, array $req ) : boolean Test an individual requirement.

Method Details

__construct() public méthode

Addon constructor.
public __construct ( string $subdir = '' )
$subdir string The root-relative subdirectory of the addon.

__set_state() public static méthode

Support {@link var_export()} for caching.
public static __set_state ( array $array ) : Addon
$array array The array to load.
Résultat Addon Returns a new addon with the properties from {@link $array}.

check() public méthode

Check the addon for data issues.
public check ( boolean $trigger = false ) : array
$trigger boolean Whether or not to trigger a notice if there are issues.
Résultat array Returns an array of issues with the addon.

checkVersion() public static méthode

Check a version against a version requirement.
public static checkVersion ( string $version, string $requirement )
$version string The version to check.
$requirement string The version requirement.

comparePriority() public static méthode

Compare two addon's by priority so that they can be sorted.
public static comparePriority ( Addon $a, Addon $b ) : integer
$a Addon The first addon to compare.
$b Addon The second addon to compare.
Résultat integer Returns -1, 0, or 1.

getClassPath() public méthode

This is a case insensitive lookup.
public getClassPath ( string $classname, string $relative = self::PATH_FULL ) : string
$classname string The name of the class.
$relative string One of the **Addon::PATH*** constants.
Résultat string Returns the path or an empty string of the class isn't found.

getClasses() public méthode

Get the classes.
public getClasses ( ) : array
Résultat array Returns the classes.

getIcon() public méthode

Get the path to the icon for this addon.
public getIcon ( string $relative = self::PATH_ADDON ) : string
$relative string One of the **Addon::PATH_*** constants.
Résultat string Returns the path of the icon relative to {@link $relative} or an empty string if there is no icon.

getInfo() public méthode

Get the info.
public getInfo ( ) : array
Résultat array Returns the info.

getInfoValue() public méthode

Get a single value from the info array.
public getInfoValue ( string $key, mixed $default = null ) : mixed
$key string The key in the info array.
$default mixed The default value to return if there is no item.
Résultat mixed Returns the info value or {@link $default}.

getKey() public méthode

Get this addon's key.
public getKey ( ) : string
Résultat string Returns the key as a string.

getName() public méthode

Get this addon's human-readable name.
public getName ( ) : string
Résultat string Returns the name of the addon or its key if it has no name.

getPluginClass() public méthode

Get the name of the plugin class for this addon, if any.
public getPluginClass ( ) : string
Résultat string Returns the name of the class or an empty string if it doesn't have one.

getPriority() public méthode

An addon's priority determines the order of things like translations, autoloading, and event firing. Addons with higher priorities will generally override addons with lower priority.
public getPriority ( ) : integer
Résultat integer Returns the priority.

getRawKey() public méthode

Addon's have a lowercase key, but some places still require the uppercase one.
public getRawKey ( ) : string
Résultat string Returns the key as a string.

getRequirements() public méthode

Get the required addons for this addon.
public getRequirements ( ) : array
Résultat array Returns an array in the form addonKey => version.

getSpecial() public méthode

Get an item from the special array.
public getSpecial ( string $key, mixed $default = null ) : mixed
$key string The key in the special array.
$default mixed The default if the key isn't set.
Résultat mixed Returns the special item or {@link $default}.

getSubdir() public méthode

Get the subdir.
public getSubdir ( ) : string
Résultat string Returns the subdir.

getTranslationPaths() public méthode

Get translation paths.
public getTranslationPaths ( string $locale = '' ) : array
$locale string If passed then only the translation paths for this locale will be returned.
Résultat array Returns an array of translation paths or an array of locale codes pointing to translation paths.

getType() public méthode

Get the type of addon.
public getType ( ) : string
Résultat string Returns one of the **Addon::TYPE_*** constants.

getVersion() public méthode

This is just a convenience method for grabbing the version number from the info array.
public getVersion ( ) : string
Résultat string Returns a version number or an empty string if there isn't one.

makeFilterCallback() public static méthode

Return a function that can be used as a callback to filter arrays of {@link Addon} objects.
public static makeFilterCallback ( array $where ) : Closure
$where array A where array that filters the info array.
Résultat Closure Returns a new closure.

path() public méthode

Make a full path from an addon-relative path.
public path ( string $subpath = '', string $relative = self::PATH_FULL ) : string
$subpath string The subpath to base the path on, starting with a "/".
$relative string One of the **Addon::PATH_*** constants.
Résultat string Returns a full path.

scan() public méthode

Scan a subdirectory and setup this addon.
public scan ( string $subdir )
$subdir string The root-relative subdirectory to scan.

test() public méthode

The test includes some of the files on this addon which will throw an exception if there are any major issues.
public test ( boolean $throw = true ) : boolean
$throw boolean Whether or not to throw an exception.
Résultat boolean Returns **true** if the addon was successfully tested or **false** otherwise.