Skip to content

project API's

Bethuel edited this page Aug 29, 2023 · 1 revision

Info

the Info class handles plugin's info from plugin.json file.

file: https://github.com/bethropolis/plugin-system/blob/main/src/Info.php

Class-Namespace

use Bethropolis\PluginSystem\Info;

Class Methods

$this->loadConfig() private

Loads the configuration from the config file.

$this->refreshPlugins()

Refreshes the list of plugins and plugin info.

$this->scanPluginsDirectory() private

Scans the plugins directory and returns an array of plugin names.

$this->addPlugin($pluginName, $data)

Adds a plugin to the configuration.

$this->removePlugin($pluginName)

Removes a plugin from the configuration.

$this->modifyPluginData($pluginName, $data)

Modifies the plugin data for a specific plugin.

$this->getPlugins()

Retrieves the list of plugins as an array.

$this->saveConfig()

Saves the configuration data to a file.


Lifecycle

the lifecycle class handles a plugin's life cycle from installation to uninstallation.

file: https://github.com/bethropolis/plugin-system/blob/main/src/lifeCycle.php

Class-Namespace

use Bethropolis\PluginSystem\Lifecycle;

Class Methods

$this->onInstallation($pluginName)

executed when a plugin is installed

$this->onUninstallation($pluginName)

executed when a plugin is uninstalled

$this->processPluginFiles($pluginName, $action) private

Process plugin files. eg plugin.json
this allows it to perform plugin configurations e.t.c

$this->getPluginConfigPath($pluginName) private

return the path to the plugin's config file

$this->append($targetFile, $requireFile, $pluginName) private

Appends a require statement to a target file if it doesn't already exist.

$this->remove($targetFile, $requireFile, $pluginName) private

Undos the require statement from $this-append() .

$this->resolveAbsolutePath($path) private

Resolves the absolute path from a given path.

$this->resolveRelativePath($path, $basePath) private

Resolves the relative path from a given base path.


Manager

the manager class handles instalation, uninstallation and updating of plugins.

file: https://github.com/bethropolis/plugin-system/blob/main/src/Manager.php

Class Namespace

use Bethropolis\PluginSystem\Manager;

Class Methods

Manager::initialize()

initializes the manager

Manager::installPlugin($downloadUrl)

downloads a zip file and extracts it into the plugin directory

Manager::uninstallPlugin($pluginName)

removes a plugin from the plugins directory.

Manager::updatePlugin($pluginName, $pluginUrl)

updates a plugin.

Manager::loadConfig()

loads/creates the config file

Manager::activatePlugin($pluginName)

activates a plugin

Manager::deactivatePlugin($pluginName)

deactivates a plugin

Manager::togglePlugin($pluginName)

toggles between plugin activation and deactivation

Manager::pluginExists($pluginName)

checks if a plugin exists

Manager::isPluginActive($pluginName)

checks if a plugin is active

Manager::getPluginMetadata($pluginName)

returns the metadata of a plugin

Manager::saveConfig() private

saves the config file


Plugin

the plugin class is an abstract to all plugins to be made.

file: https://github.com/bethropolis/plugin-system/blob/main/src/Plugin.php

Class Namespace

use Bethropolis\PluginSystem\Plugin;

Class Methods

$this->name protected

plugin name

$this->version protected

plugin version

$this->description protected

plugin description

$this->author protected

plugin author

$this->getInfo

returns plugin info such as plugin name, version, description and author.

$this->initialize

initializes the plugin, should be defined on every plugin.

$this->linkHook($name, $callback)

links a plugin function to a hook.

$this->linkEvent($name, $callback)

links a plugin function to an event.

$this->error($errorMessage, $errorLevel)

logs an error.

$this->exception

logs an exception.


System

the system class handles registering and executing hooks and events.

file: https://github.com/bethropolis/plugin-system/blob/main/src/System.php

Class Namespace

use Bethropolis\PluginSystem\System;

Class Methods

System::loadPlugins($dir)

Loads plugins from a specific directory.

System::linkPluginToHook($name, $callback)

Links a plugin function to a hook.

System::executeHook($name, $pluginName, ...$args)

Executes a hook by calling all registered callbacks associated with it.

System::executeHooks($names, $pluginName, ...$args)

Executes a series of hooks.

System::registerEvent($name)

Registers an event

System::addAction($eventName, $callback)

Adds an action to the event specified by $eventName.

System::triggerEvent($name, ...$args)

Triggers an event and calls all registered callbacks for that event.

Clone this wiki locally