Commit 8726216f authored by Bas de Nooijer's avatar Bas de Nooijer

- plugin support object instances

- unittest improvements
parent 995bcabb
...@@ -232,13 +232,15 @@ class Solarium_Client extends Solarium_Configurable ...@@ -232,13 +232,15 @@ class Solarium_Client extends Solarium_Configurable
public function registerPlugin($key, $plugin, $options = array()) public function registerPlugin($key, $plugin, $options = array())
{ {
if (is_string($plugin)) { if (is_string($plugin)) {
$plugin = new $plugin($this, $options); $plugin = new $plugin;
} }
if (!($plugin instanceof Solarium_Plugin_Abstract)) { if (!($plugin instanceof Solarium_Plugin_Abstract)) {
throw new Solarium_Exception('All plugins must extend Solarium_Plugin_Abstract'); throw new Solarium_Exception('All plugins must extend Solarium_Plugin_Abstract');
} }
$plugin->init($this, $options);
$this->_plugins[$key] = $plugin; $this->_plugins[$key] = $plugin;
return $this; return $this;
......
...@@ -51,15 +51,31 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable ...@@ -51,15 +51,31 @@ abstract class Solarium_Plugin_Abstract extends Solarium_Configurable
protected $_client; protected $_client;
/** /**
* Constructor * Initialize
*
* This method is called when the plugin is registered to a client instance
* *
* @param Solarium_Client $client * @param Solarium_Client $client
* @param array $options * @param array $options
*/ */
public function __construct($client, $options) public function init($client, $options)
{ {
$this->_client = $client; $this->_client = $client;
parent::__construct($options); parent::__construct($options);
$this->_init();
}
/**
* Secondary init function
*
* This is an extension point for plugin implemenations
*
* @return void
*/
public function _init()
{
} }
/** /**
......
...@@ -108,4 +108,9 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa ...@@ -108,4 +108,9 @@ class Solarium_Client_RequestBuilder_SelectTest extends PHPUnit_Framework_TestCa
); );
} }
public function testWithComponents()
{
//1 component met en 1 zonder builder registratie
}
} }
\ No newline at end of file
...@@ -37,7 +37,8 @@ class Solarium_Plugin_AbstractTest extends PHPUnit_Framework_TestCase ...@@ -37,7 +37,8 @@ class Solarium_Plugin_AbstractTest extends PHPUnit_Framework_TestCase
{ {
$this->_client = 'dummy'; $this->_client = 'dummy';
$this->_options = array('option1' => 1); $this->_options = array('option1' => 1);
$this->_plugin = new MyPlugin($this->_client, $this->_options); $this->_plugin = new MyPlugin();
$this->_plugin->init($this->_client, $this->_options);
} }
public function testConstructor() public function testConstructor()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment