Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Last active November 7, 2015 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezimuel/eb26ade8e0a2529cb6b6 to your computer and use it in GitHub Desktop.
Save ezimuel/eb26ade8e0a2529cb6b6 to your computer and use it in GitHub Desktop.
Experimental plugin manager compliant with ContainerInterface
<?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