Add code to builder so pluginconfig.php is loaded if found in the root

This commit is contained in:
meadsteve 2014-03-02 20:00:43 +00:00
parent 6d4e49d07b
commit 20d5e5a6b2
3 changed files with 36 additions and 3 deletions

3
.gitignore vendored
View file

@ -9,4 +9,5 @@ config.php
.htaccess
PHPCI/config.yml
cache
/loggerconfig.php
/loggerconfig.php
/pluginconfig.php

View file

@ -14,6 +14,7 @@ use PHPCI\Helper\MailerFactory;
use PHPCI\Model\Build;
use b8\Store;
use b8\Config;
use PHPCI\Plugin\Util\Factory;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
@ -114,7 +115,10 @@ class Builder implements LoggerAwareInterface, BuildLogger
}
$this->build = $build;
$this->store = Store\Factory::getStore('Build');
$this->pluginExecutor = new Plugin\Util\Executor($this->buildPluginFactory($build), $this);
$pluginFactory = $this->buildPluginFactory($build);
$pluginFactory->addConfigFromFile(PHPCI_DIR . "/pluginconfig.php");
$this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this);
$this->commandExecutor = new CommandExecutor($this, PHPCI_DIR, $this->quiet, $this->verbose);
}
@ -394,9 +398,15 @@ class Builder implements LoggerAwareInterface, BuildLogger
return $this->logger;
}
/**
* Returns a configured instance of the plugin factory.
*
* @param Build $build
* @return Factory
*/
private function buildPluginFactory(Build $build)
{
$pluginFactory = new Plugin\Util\Factory();
$pluginFactory = new Factory();
$self = $this;
$pluginFactory->registerResource(

22
pluginconfig.php.example Normal file
View file

@ -0,0 +1,22 @@
<?php
return function (PHPCI\Plugin\Util\Factory $factory) {
$factory->registerResource(
// This function will be called when the resource is needed.
function() {
return array(
'Foo' => "Stuff",
'Bar' => "More Stuff"
);
},
// In addition to the function for building the resource the system
// also needs to be told when to load the resource. Either or both
// of the following arguments can be used (null to ignore)
// This resource will only be given when the argument name is:
"ResourceArray",
// The resource will only be given when the type hint is:
PHPCI\Plugin\Util\Factory::TYPE_ARRAY
);
};