maslosoft/gazebo

Plugin container

1.1.10 2017-04-06 21:08 UTC

README

Plugin container

Latest Stable Version License [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Maslosoft/Gazebo/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Gazebo/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Maslosoft/Gazebo/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Gazebo/?branch=master)

68747470733a2f2f7472617669732d63692e6f72672f4d61736c6f736f66742f47617a65626f2e7376673f6272616e63683d6d6173746572

687474703a2f2f6868766d2e683463632e64652f62616467652f6d61736c6f736f66742f67617a65626f2e7376673f7374796c653d666c6174

Quick Install

composer require maslosoft/gazebo

Usage

//Plugins
class WaterPlugin implements WetInterface
{
	public $name = 'foo';
}
class MetalPlugin implements HardInterface
{
	public $options = false;
}
class GenericPlugin
{

}
// Config:
$config = [
			TestModel::class => [
				WaterPlugin::class,
				[
					'class' => MetalPlugin::class,
					'options' => true
				],
				GenericPlugin::class,
			],
		];

// Create plugins but only for selected interfaces
$plugins = (new PluginFactory())->instance($this->config, $model, [
			HardInterface::class,
			WetInterface::class
		]);


var_dump($plugins);

// Created flyweight instances of two plugins
//array(2) {
//	[0] => class Maslosoft\GazeboTest\Model\WaterPlugin#181 (1) {
//		public $name => string(3) "foo"
//	}
//	[1] => class Maslosoft\GazeboTest\Model\MetalPlugin#182 (2) {
//		public $options => bool(true)
//		public $class => string(38) "Maslosoft\GazeboTest\Model\MetalPlugin"
//	}
//}