PHP Класс Piwik\Plugin

Any plugin that wants to add event observers to one of Piwik's {@hook # hooks}, or has special installation/uninstallation logic must implement this class. Plugins that can specify everything they need to in the _plugin.json_ files, such as themes, don't need to implement this class. Class implementations should be named after the plugin they are a part of (eg, class UserCountry extends Plugin). ### Plugin Metadata In addition to providing a place for plugins to install/uninstall themselves and add event observers, this class is also responsible for loading metadata found in the plugin.json file. The plugin.json file must exist in the root directory of a plugin. It can contain the following information: - **description**: An internationalized string description of what the plugin does. - **homepage**: The URL to the plugin's website. - **authors**: A list of author arrays with keys for 'name', 'email' and 'homepage' - **license**: The license the code uses (eg, GPL, MIT, etc.). - **license_homepage**: URL to website describing the license used. - **version**: The plugin version (eg, 1.0.1). - **theme**: true or false. If true, the plugin will be treated as a theme. ### Examples **How to extend** use Piwik\Common; use Piwik\Plugin; use Piwik\Db; class MyPlugin extends Plugin { public function getListHooksRegistered() { return array( 'API.getReportMetadata' => 'getReportMetadata', 'Another.event' => array( 'function' => 'myOtherPluginFunction', 'after' => true // executes this callback after others ) ); } public function install() { Db::exec("CREATE TABLE " . Common::prefixTable('mytable') . "..."); } public function uninstall() { Db::exec("DROP TABLE IF EXISTS " . Common::prefixTable('mytable')); } public function getReportMetadata(&$metadata) { ... } public function myOtherPluginFunction() { ... } }
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$pluginName string Name of this plugin.

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

Метод Описание
__construct ( string | boolean $pluginName = false ) Constructor.
activate ( ) Executed every time the plugin is enabled.
deactivate ( ) Executed every time the plugin is disabled.
findComponent ( string $componentName, string $expectedSubclass ) : string | null Tries to find a component such as a Menu or Tasks within this plugin.
findMultipleComponents ( $directoryWithinPlugin, $expectedSubclass )
getInformation ( ) : array Returns plugin information, including:
getListHooksRegistered ( ) : array
getMissingDependencies ( $piwikVersion = null )
getMissingDependenciesAsString ( string $piwikVersion = null ) : string Returns a string (translated) describing the missing requirements for this plugin and the given Piwik version
getPluginName ( ) : string Returns the plugin's base class name without the namespace, e.g., "UserCountry" when the plugin class is "Piwik\Plugins\UserCountry\UserCountry".
getPluginNameFromBacktrace ( array $backtrace ) : string | false Extracts the plugin name from a backtrace array. Returns false if we can't find one.
getPluginNameFromNamespace ( string $namespaceOrClassName ) : string | false Extracts the plugin name from a namespace name or a fully qualified class name. Returns false if we can't find one.
getVersion ( ) : string Returns the plugin version number.
hasMissingDependencies ( null $piwikVersion = null ) : boolean Detect whether there are any missing dependencies.
install ( ) Installs the plugin. Derived classes should implement this class if the plugin needs to:
isTheme ( ) : boolean Returns true if this plugin is a theme, false if otherwise.
isTrackerPlugin ( ) : boolean Override this method in your plugin class if you want your plugin to be loaded during tracking.
postLoad ( ) This method is executed after a plugin is loaded and translations are registered.
registerEvents ( ) : array Returns a list of events with associated event observers.
reloadPluginInformation ( )
uninstall ( ) Uninstalls the plugins. Derived classes should implement this method if the changes made in {@link install()} need to be undone during uninstallation.

Приватные методы

Метод Описание
createCacheIfNeeded ( )
doFindMultipleComponents ( $directoryWithinPlugin, $expectedSubclass ) : array
hasDefinedPluginInformationInPluginClass ( )
includeComponents ( $components ) : boolean
makeDependency ( $piwikVersion ) : Dependency

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

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

Constructor.
public __construct ( string | boolean $pluginName = false )
$pluginName string | boolean A plugin name to force. If not supplied, it is set to the last part of the class name.

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

Executed every time the plugin is enabled.
public activate ( )

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

Executed every time the plugin is disabled.
public deactivate ( )

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

Tries to find a component such as a Menu or Tasks within this plugin.
public findComponent ( string $componentName, string $expectedSubclass ) : string | null
$componentName string The name of the component you want to look for. In case you request a component named 'Menu' it'll look for a file named 'Menu.php' within the root of the plugin folder that implements a class named Piwik\Plugin\$PluginName\Menu . If such a file exists but does not implement this class it'll silently ignored.
$expectedSubclass string If not empty, a check will be performed whether a found file extends the given subclass. If the requested file exists but does not extend this class a warning will be shown to advice a developer to extend this certain class.
Результат string | null Null if the requested component does not exist or an instance of the found component.

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

public findMultipleComponents ( $directoryWithinPlugin, $expectedSubclass )

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

- 'description' => string // 1-2 sentence description of the plugin - 'author' => string // plugin author - 'author_homepage' => string // author homepage URL (or email "mailto:[email protected]") - 'homepage' => string // plugin homepage URL - 'license' => string // plugin license - 'version' => string // plugin version number; examples and 3rd party plugins must not use Version::VERSION; 3rd party plugins must increment the version number with each plugin release - 'theme' => bool // Whether this plugin is a theme (a theme is a plugin, but a plugin is not necessarily a theme)
Устаревший:
public getInformation ( ) : array
Результат array

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

Устаревший: since 2.15.0 use {@link registerEvents()} instead.
public getListHooksRegistered ( ) : array
Результат array

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

public getMissingDependencies ( $piwikVersion = null )

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

Returns a string (translated) describing the missing requirements for this plugin and the given Piwik version
public getMissingDependenciesAsString ( string $piwikVersion = null ) : string
$piwikVersion string
Результат string "AnonymousPiwikUsageMeasurement requires PIWIK >=3.0.0"

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

Returns the plugin's base class name without the namespace, e.g., "UserCountry" when the plugin class is "Piwik\Plugins\UserCountry\UserCountry".
final public getPluginName ( ) : string
Результат string

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

Extracts the plugin name from a backtrace array. Returns false if we can't find one.
public static getPluginNameFromBacktrace ( array $backtrace ) : string | false
$backtrace array The result of {@link debug_backtrace()} or [Exception::getTrace()](http://www.php.net/manual/en/exception.gettrace.php).
Результат string | false

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

Extracts the plugin name from a namespace name or a fully qualified class name. Returns false if we can't find one.
public static getPluginNameFromNamespace ( string $namespaceOrClassName ) : string | false
$namespaceOrClassName string The namespace or class string.
Результат string | false

getVersion() закрытый публичный Метод

Returns the plugin version number.
final public getVersion ( ) : string
Результат string

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

Detect whether there are any missing dependencies.
public hasMissingDependencies ( null $piwikVersion = null ) : boolean
$piwikVersion null Defaults to the current Piwik version
Результат boolean

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

- create tables - update existing tables - etc.
public install ( )

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

Returns true if this plugin is a theme, false if otherwise.
public isTheme ( ) : boolean
Результат boolean

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

Note: If you define your own dimension or handle a tracker event, your plugin will automatically be detected as a tracker plugin.
public isTrackerPlugin ( ) : boolean
Результат boolean

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

Useful for initialization code that uses translated strings.
public postLoad ( )

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

Derived classes should use this method to associate callbacks with events.
С версии: 2.15.0
public registerEvents ( ) : array
Результат array eg, array( 'API.getReportMetadata' => 'myPluginFunction', 'Another.event' => array( 'function' => 'myOtherPluginFunction', 'after' => true // execute after callbacks w/o ordering ) 'Yet.Another.event' => array( 'function' => 'myOtherPluginFunction', 'before' => true // execute before callbacks w/o ordering ) )

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

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

In most cases, if you have an {@link install()} method, you should provide an {@link uninstall()} method.
public uninstall ( )

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

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

Name of this plugin.
protected string $pluginName
Результат string