Last active
November 7, 2015 16:54
-
-
Save ezimuel/eb26ade8e0a2529cb6b6 to your computer and use it in GitHub Desktop.
Experimental plugin manager compliant with ContainerInterface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Experimantal plugin manager complaint with ContainerInterface with options support | |
* using the optional Interface rule of PHP | |
*/ | |
use Interop\Container\ContainerInterface; | |
class PluginManager implements ContainerInterface | |
{ | |
/** | |
* Default set of symmetric adapters | |
* | |
* @var array | |
*/ | |
protected $plugins = [ | |
'key' => Class::class, // key => Plugin to use | |
]; | |
/** | |
* Do we have the plugin? | |
* | |
* @param string $id | |
* @return bool | |
*/ | |
public function has($id) | |
{ | |
return array_key_exists($id, $this->plugins); | |
} | |
/** | |
* Retrieve the symmetric plugin | |
* | |
* @param string $id | |
* @param mixed $options | |
* @return object | |
*/ | |
public function get($id, $options = null) | |
{ | |
$class = $this->plugins[$id]; | |
return new $class($options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment