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
Datei anzeigen Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Property Type Description
$Sender object

Public Methods

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

Protected Methods

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

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

autoToggle() public method

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

autoTogglePath() public method

public autoTogglePath ( null $Path = null ) : null | string
$Path null
return null | string

controller_index() public method

public controller_index ( $sender )
$sender

dispatch() public method

public dispatch ( $Sender, array $RequestArgs = [] ) : mixed
$Sender
$RequestArgs array
return mixed

getAddon() public method

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

getPluginFolder() public method

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

getPluginIndex() public method

Gets the case-sensitive plugin key.
public getPluginIndex ( ) : string
return string

getPluginKey() public method

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.
return mixed value of the provided key or {@link $default} if it isn't found.

getPluginName() public method

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

getResource() public method

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.
return string path to the file

getUserMeta() protected method

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.
return array Return the results or $Default.

getView() public method

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.
return string Returns the path to the view file, relative to the document root.

getWebResource() public method

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.
return string Returns the URL of the resource.

instance() public static method

Get an instance of the calling class.
public static instance ( ) : Gdn_Plugin
return Gdn_Plugin

isEnabled() public method

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
return boolean Status of plugin's 2nd level activation

makeMetaKey() protected method

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

render() public method

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 method

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

setUserMeta() protected method

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
return void

setup() public method

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

trimMetaKey() protected method

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

userMetaModel() public method

Instance of UserMetaModel.
public userMetaModel ( ) : UserMetaModel
return UserMetaModel

Property Details

$Sender protected_oe property

protected object $Sender
return object