PHP Class Vanilla\Addon

Exibir arquivo Open project: vanilla/vanilla Class Usage Examples

Public Methods

Method 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

Method 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 method

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

__set_state() public static method

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

check() public method

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.
return array Returns an array of issues with the addon.

checkVersion() public static method

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 method

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.
return integer Returns -1, 0, or 1.

getClassPath() public method

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.
return string Returns the path or an empty string of the class isn't found.

getClasses() public method

Get the classes.
public getClasses ( ) : array
return array Returns the classes.

getIcon() public method

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.
return string Returns the path of the icon relative to {@link $relative} or an empty string if there is no icon.

getInfo() public method

Get the info.
public getInfo ( ) : array
return array Returns the info.

getInfoValue() public method

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.
return mixed Returns the info value or {@link $default}.

getKey() public method

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

getName() public method

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

getPluginClass() public method

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

getPriority() public method

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
return integer Returns the priority.

getRawKey() public method

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

getRequirements() public method

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

getSpecial() public method

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.
return mixed Returns the special item or {@link $default}.

getSubdir() public method

Get the subdir.
public getSubdir ( ) : string
return string Returns the subdir.

getTranslationPaths() public method

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

getType() public method

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

getVersion() public method

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

makeFilterCallback() public static method

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.
return Closure Returns a new closure.

path() public method

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.
return string Returns a full path.

scan() public method

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

test() public method

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.
return boolean Returns **true** if the addon was successfully tested or **false** otherwise.