Git Product home page Git Product logo

phpplugin's Introduction

alt text alt text alt-text

PHPPlugin system

A simple > PHP5.3 plugin system supporting plugin descriptor files and extension points. It is inspired by the eclipse and jira plugin architectures. In combination with a dependency manager (Composer), a module system (for example Symfony bundles) and a dependency injection framework (for example the Symfony service container) this provides a very powerfull way of building a pluggable architecture in a PHP application. It can be easily extended to filter loaded plugins based on your own criteria which allows for different levels op application functionalities (maybe based on subscription level).

Terminology

  • Registry :: Container of shared objects (for example plugins and extension points)
  • Locators :: Objects that locate installed plugins
  • Activators :: Objects athat provide different ways to activate plugins
  • Loader :: Loads and parses plugin declaration and register it on the plugin registry

Example usage

composer require gheevel/phpplugin

Create a directory for plugins with a new plugin directory containing a plugin.xml file and a plugin class. (Directories may be nested)

<?xml version="1.0" encoding="UTF-8" ?>
<plugin>
    <name>company/plugin</name>
    <pluginClass>Company\Plugin\Plugin</pluginClass> <!-- Just extend AbstractPlugin or implement PluginInterface //-->
    <extension type="some.extension.type.identifier" className="Some\ClassOne" customPropertyOne="one" />
    <extension type="some.extension.type.identifier" className="Some\ClassTwo" customPropertyTwo="two" />
</plugin>
<?php
namespace Company\Plugin;

use PHPPlugin\PluginSystem\AbstractPlugin;

class Plugin extends AbstractPlugin
{
    
}
<?php
use PHPPlugin\PluginSystem\ComponentAccessor;

// Or preferably inject with a dependency injection container
$pluginRegistry = ComponentAccessor::getInstance()->getPluginRegistry(); 

$pluginRegistry
    ->getPluginLocator('PHPPlugin\PluginSystem\Locator\RecursiveDirectoryPluginLocator')
    ->addPath('vendor');

// Now all extensions are available through proxy instances.
$pluginRegistry->activate();

// Or preferably inject with a dependency injection container
$extensionRegistry = ComponentAccessor::getInstance()->getExtensionRegistry();

$extensionRegistry->getExtensionsByType('some.extension.type.identifier');
$extensionRegistry->getExtensionByClassName('Some\Class');

phpplugin's People

Stargazers

 avatar

Watchers

James Cloos avatar Greg Kennedy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.