maslosoft/gazebo

Plugin container

2.0.2 2022-10-06 16:45 UTC

This package is auto-updated.

Last update: 2024-04-06 20:09:28 UTC


README

Plugin container

Latest Stable Version License Scrutinizer Code Quality Code Coverage

Quick Install

composer require maslosoft/gazebo

Documentation

Full Gazebo Documentation

Plugin container

When developing plugins for Your application, these might come in very different kids. This library helps to manage plugins by providing sets of instantiated plugins required for various scenarios. All plugins for component using gazebo are configured as a one simple list - thus allowing for easy adding and removing them - without bothering which plugin type should go where.

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"
//	}
//}