Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/http-foundation' of github.com:ralphschindler/z…
Browse files Browse the repository at this point in the history
…f2 into feature/http-foundation
  • Loading branch information
Ralph Schindler committed Aug 16, 2011
11 parents 6186985 + 26666c9 + c993e85 + 4e037a4 + 965637a + 64de913 + b400e6b + 526722c + f7defb5 + 1f1e802 + 954d53b commit aba79e7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/PluginBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class PluginBroker implements Broker
* @var ShortNameLocator Plugin class loader used by this instance
*/
protected $classLoader;

/**
* @var boolean Whether plugins should be registered on load
*/
protected $registerPluginsOnLoad = true;

/**
* @var array Cache of loaded plugin instances
Expand Down Expand Up @@ -139,6 +144,9 @@ public function setOptions($options)
// been registered
$plugins = $value;
break;
case 'register_plugins_on_load':
$this->setRegisterPluginsOnLoad($value);
break;
case 'validator':
$this->setValidator($value);
break;
Expand Down Expand Up @@ -191,7 +199,10 @@ public function load($plugin, array $options = null)
$instance = $r->newInstanceArgs($options);
}

$this->register($pluginName, $instance);
if ($this->getRegisterPluginsOnLoad()) {
$this->register($pluginName, $instance);
}

return $instance;
}

Expand Down Expand Up @@ -280,6 +291,28 @@ public function getClassLoader()
}
return $this->classLoader;
}

/**
* Set if plugins should be registered on load.
*
* @param boolean $flag
* @return PluginBroker
*/
public function setRegisterPluginsOnLoad($flag)
{
$this->registerPluginsOnLoad = (bool) $flag;
return $this;
}

/**
* Retrieve if plugins are registered on load.
*
* @return boolean
*/
public function getRegisterPluginsOnLoad()
{
return $this->registerPluginsOnLoad;
}

/**
* Set plugin validator callback
Expand Down
13 changes: 13 additions & 0 deletions test/PluginBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ public function testIsLoadedReturnsTrueForRegisteredPlugin()
$this->broker->register('sample', new TestAsset\SamplePlugin());
$this->assertTrue($this->broker->isLoaded('sample'));
}

public function testRegisterPluginsOnLoadDisabled()
{
$this->broker->setRegisterPluginsOnLoad(false);

$loader = $this->broker->getClassLoader();
$loader->registerPlugin('sample', 'ZendTest\Loader\TestAsset\SamplePlugin');

$plugin1 = $this->broker->load('sample');
$plugin2 = $this->broker->load('sample');

$this->assertNotSame($plugin1, $plugin2);
}

/**
* Unsure if this is functionality we want to support; requires some form
Expand Down

0 comments on commit aba79e7

Please sign in to comment.