Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,32 @@ System::addAction('my_event', function ($arg) {
System::triggerEvent('my_event', ...$args);
```

## Examples
## plugin

here is an example plugin:
```php

// eg. FILE: /plugins-folder/examplepugin.php

class ExamplePlugin extends \Bethropolis\PluginSystem\Plugin
{

public function initialize()
{
$this->linkHook('my_hook', array($this, 'myCallback'));
}



public function myCallback($name = [])
{
$name = array_shift($name);
return "hello {$name}";
}
}
```

## more Examples

The examples directory contains sample plugins that demonstrate the usage of the Plugin System.

Expand Down
4 changes: 2 additions & 2 deletions examples/SingleFilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SingleFilePlugin extends \Bethropolis\PluginSystem\Plugin

public function initialize()
{
$this->linkHook('js_hook', array($this, 'myCallback'));
$this->linkHook('my_hook', array($this, 'myCallback'));
}


Expand All @@ -16,4 +16,4 @@ public function myCallback($name = [])
$name = array_shift($name);
return "hello {$name}";
}
}
}
12 changes: 6 additions & 6 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function initialize()
{
$pluginsDir = System::getPluginsDir();
self::setPluginsDir($pluginsDir);
self::$config = self::loadConfig();
self::$config = self::loadConfig();
self::$lifeCycle = new LifeCycle();
}
public static function setPluginsDir($dir)
Expand Down Expand Up @@ -78,16 +78,16 @@ public static function installPlugin($pluginUrl)
public static function uninstallPlugin($pluginName)
{
$pluginNamespace = __NAMESPACE__ . '\\' . $pluginName . "Plugin\\Load";
$pluginNamespace = stripslashes(strtolower($pluginNamespace));
$pluginNamespace = stripslashes(strtolower($pluginNamespace));



if (!self::pluginExists($pluginNamespace)) {
return Error::handleException(new \Exception("Plugin does not exist."));
return Error::handleException(new \Exception("Plugin does not exist."));
}

if (self::isPluginActive($pluginNamespace)) {
return Error::handleException(new \Exception("Cannot uninstall an active plugin. Deactivate it first."));
return Error::handleException(new \Exception("Cannot uninstall an active plugin. Deactivate it first."));
}

$pluginDir = self::$pluginsDir . '/' . $pluginName;
Expand Down Expand Up @@ -141,7 +141,7 @@ public static function unregisterPlugin($pluginName)
{
// remove plugin from config file
$pluginName = __NAMESPACE__ . '\\' . $pluginName . "Plugin\\Load";
$pluginName = stripslashes(strtolower($pluginName));
$pluginName = stripslashes(strtolower($pluginName));
unset(self::$config['plugins'][$pluginName]);
unset(self::$config['activated_plugins'][$pluginName]);
self::saveConfig();
Expand Down Expand Up @@ -228,4 +228,4 @@ private static function saveConfig($config = null)
$config = $config ?? self::$config;
file_put_contents(self::$configFile, json_encode($config, JSON_PRETTY_PRINT));
}
}
}