PHP Class Gdn_Plugin, vanilla

A simple framework that all plugins should extend. Aside from the implementation of Gdn_IPlugin, this class provides some convenience methods to make plugin development easier and faster.
Since: 2.0
Author: Tim Gunter ([email protected])
Inheritance: extends Gdn_Pluggable, implements Gdn_IPlugin
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Свойство Type Description
$Sender object

Méthodes publiques

Méthode Description
__construct ( ) Initialize a new instance of the {@link Gdn_Plugin} class.
autoToggle ( object $Sender, mixed $Redirect = null ) Automatically handle the toggle effect.
autoTogglePath ( null $Path = null ) : null | string
controller_index ( $sender )
dispatch ( $Sender, array $RequestArgs = [] ) : mixed
getAddon ( ) : Addon Get the addon that this plugin belongs to.
getPluginFolder ( boolean $absolute = true ) : string Get the plugin's folder.
getPluginIndex ( ) : string Gets the case-sensitive plugin key.
getPluginKey ( string $key, mixed $default = null ) : mixed Get a specific value from the plugin info array.
getPluginName ( ) : string Get the human-readable name of the plugin.
getResource ( string $filePath, boolean $include = false, boolean $absolute = true ) : string Gets the path to a file within the plugin's folder (and optionally include it).
getView ( string $ViewName ) : string Converts view files to Render() paths.
getWebResource ( string $filePath, boolean $withDomain = false ) : string Get a static resource for this addon suitable to be served from the browser.
instance ( ) : Gdn_Plugin Get an instance of the calling class.
isEnabled ( ) : boolean Convenience method for determining 2nd level activation.
render ( string $view ) Passthru render request to sender.
setAddon ( Addon $addon ) : Gdn_Plugin Set the addon that this plugin belongs to.
setup ( ) Implementation of {@link Gdn_IPlugin::Setup()}.
userMetaModel ( ) : UserMetaModel Instance of UserMetaModel.

Méthodes protégées

Méthode Description
getUserMeta ( integer | array $userID, string $key, mixed $default = null, boolean $autoUnfold = false ) : array Retries UserMeta information for a UserID/Key pair.
makeMetaKey ( string $relativeUserKey ) : string This method takes a UserKey (short relative form) and prepends the plugin prefix.
setUserMeta ( $UserID, $Key, $Value = null ) : void Sets UserMeta data to the UserMeta table
trimMetaKey ( $FullyQualifiedUserKey ) : string This method trims the plugin prefix from a fully qualified MetaKey.

Method Details

__construct() public méthode

Initialize a new instance of the {@link Gdn_Plugin} class.
public __construct ( )

autoToggle() public méthode

Automatically handle the toggle effect.
Deprecation:
public autoToggle ( object $Sender, mixed $Redirect = null )
$Sender object Reference to the invoking controller
$Redirect mixed

autoTogglePath() public méthode

public autoTogglePath ( null $Path = null ) : null | string
$Path null
Résultat null | string

controller_index() public méthode

public controller_index ( $sender )
$sender

dispatch() public méthode

public dispatch ( $Sender, array $RequestArgs = [] ) : mixed
$Sender
$RequestArgs array
Résultat mixed

getAddon() public méthode

Get the addon that this plugin belongs to.
public getAddon ( ) : Addon
Résultat Vanilla\Addon Returns the addon.

getPluginFolder() public méthode

Get the plugin's folder.
public getPluginFolder ( boolean $absolute = true ) : string
$absolute boolean Whether or not the folder should be absolute.
Résultat string Returns the folder or an empty string if there is no addon associated with this object.

getPluginIndex() public méthode

Gets the case-sensitive plugin key.
public getPluginIndex ( ) : string
Résultat string

getPluginKey() public méthode

Get a specific value from the plugin info array.
public getPluginKey ( string $key, mixed $default = null ) : mixed
$key string Name of the key whose value you wish to retrieve.
$default mixed Optional value to return if the key cannot be found.
Résultat mixed value of the provided key or {@link $default} if it isn't found.

getPluginName() public méthode

Get the human-readable name of the plugin.
public getPluginName ( ) : string
Résultat string Returns the name of the plugin.

getResource() public méthode

Gets the path to a file within the plugin's folder (and optionally include it).
public getResource ( string $filePath, boolean $include = false, boolean $absolute = true ) : string
$filePath string A relative path to a file within the plugin's folder.
$include boolean Whether or not to immediately include() the file if it exists.
$absolute boolean Whether or not to prepend the full document root to the path.
Résultat string path to the file

getUserMeta() protected méthode

This method takes a $UserID or array of $UserIDs, and a $Key. It converts the $Key to fully qualified format and then queries for the associated value(s). $Key can contain SQL wildcards, in which case multiple results can be returned. If $UserID is an array, the return value will be a multi dimensional array with the first axis containing UserIDs and the second containing fully qualified UserMetaKeys, associated with their values. If $UserID is a scalar, the return value will be a single dimensional array of $UserMetaKey => $Value pairs.
protected getUserMeta ( integer | array $userID, string $key, mixed $default = null, boolean $autoUnfold = false ) : array
$userID integer | array The UserID or array of UserIDs.
$key string The relative user meta key.
$default mixed An optional default return value if key is not found.
$autoUnfold boolean Automatically return key item for single key queries.
Résultat array Return the results or $Default.

getView() public méthode

This method takes a simple filename and, assuming it is located inside /views/, converts it into a path that is suitable for $Sender->Render().
Deprecation: This method is not themeable and thus not advisable.
public getView ( string $ViewName ) : string
$ViewName string The name of the view file, including extension.
Résultat string Returns the path to the view file, relative to the document root.

getWebResource() public méthode

Get a static resource for this addon suitable to be served from the browser.
public getWebResource ( string $filePath, boolean $withDomain = false ) : string
$filePath string The plugin-relative path of the resource.
$withDomain boolean Whether or not to include the domain.
Résultat string Returns the URL of the resource.

instance() public static méthode

Get an instance of the calling class.
public static instance ( ) : Gdn_Plugin
Résultat Gdn_Plugin

isEnabled() public méthode

This method checks the secondary "Plugin.PLUGINNAME.Enabled" setting that has becoming the de-facto standard for keeping plugins enabled but de-activated.
public isEnabled ( ) : boolean
Résultat boolean Status of plugin's 2nd level activation

makeMetaKey() protected méthode

For example, 'Sig' becomes 'Plugin.Signatures.Sig'
protected makeMetaKey ( string $relativeUserKey ) : string
$relativeUserKey string The relative user meta key.
Résultat string Returns a fully qualified meta key.

render() public méthode

This render method automatically adds the correct ApplicationFolder parameter so that $Sender->Render() will first check the plugin's views/ folder.
public render ( string $view )
$view string The name of the view to render.

setAddon() public méthode

Set the addon that this plugin belongs to.
public setAddon ( Addon $addon ) : Gdn_Plugin
$addon Vanilla\Addon The new addon.
Résultat Gdn_Plugin Returns `$this` for fluent calls.

setUserMeta() protected méthode

This method takes a UserID, Key, and Value, and attempts to set $Key = $Value for $UserID. $Key can be an SQL wildcard, thereby allowing multiple variations of a $Key to be set. $UserID can be an array, thereby allowing multiple users' $Keys to be set to the same $Value. ++ Before any queries are run, $Key is converted to its fully qualified format (Plugin. prepended) ++ to prevent collisions in the meta table when multiple plugins have similar key names. If $Value == NULL, the matching row(s) are deleted instead of updated.
protected setUserMeta ( $UserID, $Key, $Value = null ) : void
$UserID int UserID or array of UserIDs
$Key string relative user key
$Value mixed optional value to set, null to delete
Résultat void

setup() public méthode

Implementation of {@link Gdn_IPlugin::Setup()}.
public setup ( )

trimMetaKey() protected méthode

For example, Plugin.Signatures.Sig would become 'Sig'.
protected trimMetaKey ( $FullyQualifiedUserKey ) : string
Résultat string relative meta key

userMetaModel() public méthode

Instance of UserMetaModel.
public userMetaModel ( ) : UserMetaModel
Résultat UserMetaModel

Property Details

$Sender protected_oe property

protected object $Sender
Résultat object