From 20d5e5a6b294e8b2709d0418b74d119c4b741a01 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 2 Mar 2014 20:00:43 +0000 Subject: [PATCH] Add code to builder so pluginconfig.php is loaded if found in the root --- .gitignore | 3 ++- PHPCI/Builder.php | 14 ++++++++++++-- pluginconfig.php.example | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 pluginconfig.php.example diff --git a/.gitignore b/.gitignore index 620cd6ce..d8c5ef7b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ config.php .htaccess PHPCI/config.yml cache -/loggerconfig.php \ No newline at end of file +/loggerconfig.php +/pluginconfig.php \ No newline at end of file diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 7b36d55b..4e02e1b3 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -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( diff --git a/pluginconfig.php.example b/pluginconfig.php.example new file mode 100644 index 00000000..4e4279b9 --- /dev/null +++ b/pluginconfig.php.example @@ -0,0 +1,22 @@ +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 + ); +}; \ No newline at end of file