PHP Класс 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.
С версии: 2.0
Автор: Tim Gunter ([email protected])
Наследование: extends Gdn_Pluggable, implements Gdn_IPlugin
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$Sender object

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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

autoToggle() публичный Метод

Automatically handle the toggle effect.
Устаревший:
public autoToggle ( object $Sender, mixed $Redirect = null )
$Sender object Reference to the invoking controller
$Redirect mixed

autoTogglePath() публичный Метод

public autoTogglePath ( null $Path = null ) : null | string
$Path null
Результат null | string

controller_index() публичный Метод

public controller_index ( $sender )
$sender

dispatch() публичный Метод

public dispatch ( $Sender, array $RequestArgs = [] ) : mixed
$Sender
$RequestArgs array
Результат mixed

getAddon() публичный Метод

Get the addon that this plugin belongs to.
public getAddon ( ) : Addon
Результат Vanilla\Addon Returns the addon.

getPluginFolder() публичный Метод

Get the plugin's folder.
public getPluginFolder ( boolean $absolute = true ) : string
$absolute boolean Whether or not the folder should be absolute.
Результат string Returns the folder or an empty string if there is no addon associated with this object.

getPluginIndex() публичный Метод

Gets the case-sensitive plugin key.
public getPluginIndex ( ) : string
Результат string

getPluginKey() публичный Метод

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.
Результат mixed value of the provided key or {@link $default} if it isn't found.

getPluginName() публичный Метод

Get the human-readable name of the plugin.
public getPluginName ( ) : string
Результат string Returns the name of the plugin.

getResource() публичный Метод

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.
Результат string path to the file

getUserMeta() защищенный Метод

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.
Результат array Return the results or $Default.

getView() публичный Метод

This method takes a simple filename and, assuming it is located inside /views/, converts it into a path that is suitable for $Sender->Render().
Устаревший: This method is not themeable and thus not advisable.
public getView ( string $ViewName ) : string
$ViewName string The name of the view file, including extension.
Результат string Returns the path to the view file, relative to the document root.

getWebResource() публичный Метод

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.
Результат string Returns the URL of the resource.

instance() публичный статический Метод

Get an instance of the calling class.
public static instance ( ) : Gdn_Plugin
Результат Gdn_Plugin

isEnabled() публичный Метод

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
Результат boolean Status of plugin's 2nd level activation

makeMetaKey() защищенный Метод

For example, 'Sig' becomes 'Plugin.Signatures.Sig'
protected makeMetaKey ( string $relativeUserKey ) : string
$relativeUserKey string The relative user meta key.
Результат string Returns a fully qualified meta key.

render() публичный Метод

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() публичный Метод

Set the addon that this plugin belongs to.
public setAddon ( Addon $addon ) : Gdn_Plugin
$addon Vanilla\Addon The new addon.
Результат Gdn_Plugin Returns `$this` for fluent calls.

setUserMeta() защищенный Метод

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
Результат void

setup() публичный Метод

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

trimMetaKey() защищенный Метод

For example, Plugin.Signatures.Sig would become 'Sig'.
protected trimMetaKey ( $FullyQualifiedUserKey ) : string
Результат string relative meta key

userMetaModel() публичный Метод

Instance of UserMetaModel.
public userMetaModel ( ) : UserMetaModel
Результат UserMetaModel

Описание свойств

$Sender защищенное свойство

protected object $Sender
Результат object