From bb76952e6aac3d8099e3947b1a7ce077e46a40e8 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Wed, 26 Feb 2014 11:16:09 +0000 Subject: [PATCH 01/22] Update phpci.yml --- phpci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpci.yml b/phpci.yml index 8d962dca..ec5b056a 100644 --- a/phpci.yml +++ b/phpci.yml @@ -8,9 +8,7 @@ build_settings: test: php_mess_detector: - allow_failures: true # Temporarily allowing failures, remove this! php_code_sniffer: - allow_failures: true # Temporarily allowing failures, remove this! standard: "PSR2" php_loc: From b421b2093592ed0abee7bf271d800b4c6dfd7102 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Wed, 26 Feb 2014 14:35:14 +0000 Subject: [PATCH 02/22] fix code sniff violations. --- PHPCI/Application.php | 3 +-- PHPCI/Builder.php | 14 ++++++-------- PHPCI/Model.php | 2 +- PHPCI/Store.php | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 3f20c3ed..03e878d7 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -27,8 +27,7 @@ class Application extends b8\Application $opts = ['controller' => 'Home', 'action' => 'index']; $this->router->clearRoutes(); - $this->router->register($route, $opts, function (&$route, Response &$response) use (&$request) - { + $this->router->register($route, $opts, function (&$route, Response &$response) use (&$request) { $skipValidation = in_array($route['controller'], array('session', 'webhook', 'build-status')); if (!$skipValidation && !$this->validateSession()) { diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index eb3e08e9..e7ea97e3 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -197,8 +197,7 @@ class Builder implements LoggerAwareInterface // stages. if ($this->success) { $this->build->setStatus(Build::STATUS_SUCCESS); - } - else { + } else { $this->build->setStatus(Build::STATUS_FAILED); } @@ -208,8 +207,7 @@ class Builder implements LoggerAwareInterface if ($this->success) { $this->pluginExecutor->executePlugins($this->config, 'success'); $this->buildLogger->logSuccess('BUILD SUCCESSFUL!'); - } - else { + } else { $this->pluginExecutor->executePlugins($this->config, 'failure'); $this->buildLogger->logFailure("BUILD FAILURE"); } @@ -266,8 +264,8 @@ class Builder implements LoggerAwareInterface */ protected function setupBuild() { - $buildId = 'project' . $this->build->getProject()->getId( - ) . '-build' . $this->build->getId(); + $buildId = 'project' . $this->build->getProject()->getId() + . '-build' . $this->build->getId(); $this->ciDir = dirname(dirname(__FILE__) . '/../') . '/'; $this->buildPath = $this->ciDir . 'build/' . $buildId . '/'; $this->build->currentBuildPath = $this->buildPath; @@ -338,7 +336,7 @@ class Builder implements LoggerAwareInterface $self = $this; $pluginFactory->registerResource( - function () use($self) { + function () use ($self) { return $self; }, null, @@ -346,7 +344,7 @@ class Builder implements LoggerAwareInterface ); $pluginFactory->registerResource( - function () use($build) { + function () use ($build) { return $build; }, null, diff --git a/PHPCI/Model.php b/PHPCI/Model.php index 392df656..7e314693 100644 --- a/PHPCI/Model.php +++ b/PHPCI/Model.php @@ -4,4 +4,4 @@ namespace PHPCI; abstract class Model extends \b8\Model { -} \ No newline at end of file +} diff --git a/PHPCI/Store.php b/PHPCI/Store.php index f0352680..6806a097 100644 --- a/PHPCI/Store.php +++ b/PHPCI/Store.php @@ -4,4 +4,4 @@ namespace PHPCI; abstract class Store extends \b8\Store { -} \ No newline at end of file +} From 112adba3325b824855249a853a88d21efbadf9d0 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Thu, 27 Feb 2014 14:02:21 +0000 Subject: [PATCH 03/22] fix psr2 violations in Plugin/Util --- .../Plugin/Util/ComposerPluginInformation.php | 32 +++++++++---------- PHPCI/Plugin/Util/Executor.php | 7 ++-- PHPCI/Plugin/Util/Factory.php | 23 ++++++------- PHPCI/Plugin/Util/FilesPluginInformation.php | 15 ++++----- .../Util/InstalledPluginInformation.php | 2 +- .../Util/PluginInformationCollection.php | 6 ++-- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/PHPCI/Plugin/Util/ComposerPluginInformation.php b/PHPCI/Plugin/Util/ComposerPluginInformation.php index 0ce76e6f..c870514e 100644 --- a/PHPCI/Plugin/Util/ComposerPluginInformation.php +++ b/PHPCI/Plugin/Util/ComposerPluginInformation.php @@ -23,8 +23,7 @@ class ComposerPluginInformation implements InstalledPluginInformation { if (file_exists($filePath)) { $installed = json_decode(file_get_contents($filePath)); - } - else { + } else { $installed = array(); } return new self($installed); @@ -60,12 +59,12 @@ class ComposerPluginInformation implements InstalledPluginInformation */ public function getPluginClasses() { - return array_map( - function($plugin) { - return $plugin->class; - }, - $this->getInstalledPlugins() - ); + return array_map( + function ($plugin) { + return $plugin->class; + }, + $this->getInstalledPlugins() + ); } protected function loadPluginInfo() @@ -74,7 +73,7 @@ class ComposerPluginInformation implements InstalledPluginInformation return; } $this->pluginInfo = array(); - foreach($this->composerPackages as $package) { + foreach ($this->composerPackages as $package) { $this->addPluginsFromPackage($package); } } @@ -89,8 +88,7 @@ class ComposerPluginInformation implements InstalledPluginInformation if (isset($phpciData->pluginNamespace)) { $rootNamespace = $phpciData->pluginNamespace; - } - else { + } else { $rootNamespace = ""; } @@ -112,9 +110,9 @@ class ComposerPluginInformation implements InstalledPluginInformation protected function addPlugins( array $plugins, $sourcePackageName, - $rootNamespace = "") - { - foreach($plugins as $plugin) { + $rootNamespace = "" + ) { + foreach ($plugins as $plugin) { if (!isset($plugin->class)) { continue; } @@ -130,8 +128,8 @@ class ComposerPluginInformation implements InstalledPluginInformation protected function addPlugin( $plugin, $sourcePackageName, - $rootNamespace = "") - { + $rootNamespace = "" + ) { $newPlugin = clone $plugin; $newPlugin->class = $rootNamespace . $newPlugin->class; @@ -144,4 +142,4 @@ class ComposerPluginInformation implements InstalledPluginInformation $this->pluginInfo[] = $newPlugin; } -} \ No newline at end of file +} diff --git a/PHPCI/Plugin/Util/Executor.php b/PHPCI/Plugin/Util/Executor.php index ceb1de55..39a5d35e 100644 --- a/PHPCI/Plugin/Util/Executor.php +++ b/PHPCI/Plugin/Util/Executor.php @@ -17,7 +17,7 @@ class Executor */ protected $pluginFactory; - function __construct(Factory $pluginFactory,BuildLogger $logger) + public function __construct(Factory $pluginFactory, BuildLogger $logger) { $this->pluginFactory = $pluginFactory; $this->logger = $logger; @@ -78,8 +78,7 @@ class Executor $class = str_replace('_', ' ', $plugin); $class = ucwords($class); $class = 'PHPCI\\Plugin\\' . str_replace(' ', '', $class); - } - else { + } else { $class = $plugin; } @@ -105,4 +104,4 @@ class Executor return $rtn; } -} \ No newline at end of file +} diff --git a/PHPCI/Plugin/Util/Factory.php b/PHPCI/Plugin/Util/Factory.php index 0e526023..781b6d5a 100644 --- a/PHPCI/Plugin/Util/Factory.php +++ b/PHPCI/Plugin/Util/Factory.php @@ -29,7 +29,7 @@ class Factory { $self = $this; $this->registerResource( - function() use ($self) { + function () use ($self) { return $self->getLastOptions(); }, 'options', @@ -37,7 +37,8 @@ class Factory { ); } - public function getLastOptions() { + public function getLastOptions() + { return $this->currentPluginOptions; } @@ -66,7 +67,7 @@ class Factory { if ($constructor) { $argsToUse = array(); - foreach($constructor->getParameters() as $param) { + foreach ($constructor->getParameters() as $param) { $argsToUse = $this->addArgFromParam($argsToUse, $param); } $plugin = $reflectedPlugin->newInstanceArgs($argsToUse); @@ -84,11 +85,11 @@ class Factory { * @throws \InvalidArgumentException * @internal param mixed $resource */ - public function registerResource($loader, - $name = null, - $type = null - ) - { + public function registerResource( + $loader, + $name = null, + $type = null + ) { if ($name === null && $type === null) { throw new \InvalidArgumentException( "Type or Name must be specified" @@ -138,9 +139,9 @@ class Factory { $class = $param->getClass(); if ($class) { return $class->getName(); - } elseif($param->isArray()) { + } elseif ($param->isArray()) { return self::TYPE_ARRAY; - } elseif($param->isCallable()) { + } elseif ($param->isCallable()) { return self::TYPE_CALLABLE; } else { return null; @@ -165,4 +166,4 @@ class Factory { return $existingArgs; } -} \ No newline at end of file +} diff --git a/PHPCI/Plugin/Util/FilesPluginInformation.php b/PHPCI/Plugin/Util/FilesPluginInformation.php index 3d8b6f47..8366c4cb 100644 --- a/PHPCI/Plugin/Util/FilesPluginInformation.php +++ b/PHPCI/Plugin/Util/FilesPluginInformation.php @@ -26,7 +26,7 @@ class FilesPluginInformation implements InstalledPluginInformation return new self(new \DirectoryIterator($dirPath)); } - function __construct(\Iterator $files) + public function __construct(\Iterator $files) { $this->files = $files; } @@ -55,17 +55,17 @@ class FilesPluginInformation implements InstalledPluginInformation public function getPluginClasses() { return array_map( - function($plugin) { + function ($plugin) { return $plugin->class; - }, - $this->getInstalledPlugins() - ); + }, + $this->getInstalledPlugins() + ); } protected function loadPluginInfo() { $this->pluginInfo = array(); - foreach($this->files as $fileInfo) { + foreach ($this->files as $fileInfo) { if ($fileInfo instanceof \SplFileInfo) { if ($fileInfo->isFile()) { $this->addPluginFromFile($fileInfo); @@ -101,5 +101,4 @@ class FilesPluginInformation implements InstalledPluginInformation return $namespace . '\\' . $className; } - -} \ No newline at end of file +} diff --git a/PHPCI/Plugin/Util/InstalledPluginInformation.php b/PHPCI/Plugin/Util/InstalledPluginInformation.php index f63c432a..133b8de8 100644 --- a/PHPCI/Plugin/Util/InstalledPluginInformation.php +++ b/PHPCI/Plugin/Util/InstalledPluginInformation.php @@ -20,4 +20,4 @@ interface InstalledPluginInformation * @return string[] */ public function getPluginClasses(); -} \ No newline at end of file +} diff --git a/PHPCI/Plugin/Util/PluginInformationCollection.php b/PHPCI/Plugin/Util/PluginInformationCollection.php index 23245a8d..9017ba72 100644 --- a/PHPCI/Plugin/Util/PluginInformationCollection.php +++ b/PHPCI/Plugin/Util/PluginInformationCollection.php @@ -24,7 +24,7 @@ class PluginInformationCollection implements InstalledPluginInformation public function getInstalledPlugins() { $arr = array(); - foreach($this->pluginInformations as $single) { + foreach ($this->pluginInformations as $single) { $arr = array_merge($arr, $single->getInstalledPlugins()); } return $arr; @@ -39,10 +39,10 @@ class PluginInformationCollection implements InstalledPluginInformation public function getPluginClasses() { $arr = array(); - foreach($this->pluginInformations as $single) { + foreach ($this->pluginInformations as $single) { $arr = array_merge($arr, $single->getPluginClasses()); } return $arr; } -} \ No newline at end of file +} From 6431ef501ed07afc0f93f889613607939b616023 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Thu, 27 Feb 2014 14:04:08 +0000 Subject: [PATCH 04/22] fix psr2 violations in EmailPlugin --- PHPCI/Plugin/Email.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/PHPCI/Plugin/Email.php b/PHPCI/Plugin/Email.php index 5d29de65..f6317197 100644 --- a/PHPCI/Plugin/Email.php +++ b/PHPCI/Plugin/Email.php @@ -41,13 +41,13 @@ class Email implements \PHPCI\Plugin */ protected $fromAddress; - public function __construct(Builder $phpci, - Build $build, - \Swift_Mailer $mailer, - array $options = array() + public function __construct( + Builder $phpci, + Build $build, + \Swift_Mailer $mailer, + array $options = array() - ) - { + ) { $this->phpci = $phpci; $this->build = $build; $this->options = $options; @@ -168,14 +168,14 @@ class Email implements \PHPCI\Plugin protected function getCcAddresses() { - $cc = array(); + $ccAddresses = array(); if (isset($this->options['cc'])) { foreach ($this->options['cc'] as $address) { - $cc[] = $address; + $ccAddresses[] = $address; } } - return $cc; + return $ccAddresses; } -} \ No newline at end of file +} From 5178c4c2299b2d86185476a710fdca18a35b7e84 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Thu, 27 Feb 2014 14:12:19 +0000 Subject: [PATCH 05/22] tidy up code in Command namespace --- PHPCI/Command/CreateAdminCommand.php | 4 ++-- PHPCI/Command/DaemoniseCommand.php | 14 ++++++++++++-- PHPCI/Command/PollCommand.php | 5 +++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/PHPCI/Command/CreateAdminCommand.php b/PHPCI/Command/CreateAdminCommand.php index 6122a108..647dffca 100644 --- a/PHPCI/Command/CreateAdminCommand.php +++ b/PHPCI/Command/CreateAdminCommand.php @@ -46,7 +46,7 @@ class CreateAdminCommand extends Command if (empty($adminEmail)) { return; } - + $adminPass = $this->ask('Admin password: '); $adminName = $this->ask('Admin name: '); @@ -64,7 +64,7 @@ class CreateAdminCommand extends Command } catch (\Exception $ex) { print 'There was a problem creating your account. :(' . PHP_EOL; print $ex->getMessage(); - print PHP_EOL; + print PHP_EOL; } } diff --git a/PHPCI/Command/DaemoniseCommand.php b/PHPCI/Command/DaemoniseCommand.php index 5d2f003a..f8cbc45b 100644 --- a/PHPCI/Command/DaemoniseCommand.php +++ b/PHPCI/Command/DaemoniseCommand.php @@ -36,6 +36,16 @@ class DaemoniseCommand extends Command */ protected $output; + /** + * @var boolean + */ + protected $run; + + /** + * @var int + */ + protected $sleep; + /** * @param \Monolog\Logger $logger * @param string $name @@ -67,14 +77,14 @@ class DaemoniseCommand extends Command $this->sleep = 0; $runner = new RunCommand($this->logger); - $in = new ArgvInput(array()); + $emptyInput = new ArgvInput(array()); while ($this->run) { $buildCount = 0; try { - $buildCount = $runner->run($in, $output); + $buildCount = $runner->run($emptyInput, $output); } catch (\Exception $e) { var_dump($e); } diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index 8bbe83cf..503e83a8 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -80,7 +80,9 @@ class PollCommand extends Command $this->logger->info("Last commit to github for " . $project->getTitle() . " is " . $last_commit); if ($project->getLastCommit() != $last_commit && $last_commit != "") { - $this->logger->info("Last commit is different from database, adding new build for " . $project->getTitle()); + $this->logger->info( + "Last commit is different from database, adding new build for " . $project->getTitle() + ); $build = new Build(); $build->setProjectId($project->getId()); @@ -101,4 +103,3 @@ class PollCommand extends Command $this->logger->addInfo("Finished processing builds"); } } - From b60e278cf9cd7693fd240196eda5b76d8fd615ed Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Thu, 27 Feb 2014 14:23:51 +0000 Subject: [PATCH 06/22] psr2 tidy up of logging code. --- PHPCI/Logging/BuildDBLogHandler.php | 4 ++-- PHPCI/Logging/BuildLogger.php | 4 ++-- PHPCI/Logging/LoggedBuildContextTidier.php | 4 ++-- PHPCI/Logging/LoggerConfig.php | 25 +++++++++++----------- PHPCI/Logging/OutputLogHandler.php | 4 ++-- Tests/PHPCI/Logging/LoggerConfigTest.php | 2 +- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/PHPCI/Logging/BuildDBLogHandler.php b/PHPCI/Logging/BuildDBLogHandler.php index 91196dc3..a877fe50 100644 --- a/PHPCI/Logging/BuildDBLogHandler.php +++ b/PHPCI/Logging/BuildDBLogHandler.php @@ -16,7 +16,7 @@ class BuildDBLogHandler extends AbstractProcessingHandler protected $logValue; - function __construct( + public function __construct( Build $build, $level = LogLevel::INFO, $bubble = true @@ -35,4 +35,4 @@ class BuildDBLogHandler extends AbstractProcessingHandler $this->logValue .= $message . PHP_EOL; $this->build->setLog($this->logValue); } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/BuildLogger.php b/PHPCI/Logging/BuildLogger.php index f3f5ebce..f652ba01 100644 --- a/PHPCI/Logging/BuildLogger.php +++ b/PHPCI/Logging/BuildLogger.php @@ -20,7 +20,7 @@ class BuildLogger implements LoggerAwareInterface */ protected $build; - function __construct(LoggerInterface $logger = null, Build $build) + public function __construct(LoggerInterface $logger, Build $build) { $this->logger = $logger; $this->build = $build; @@ -93,4 +93,4 @@ class BuildLogger implements LoggerAwareInterface { $this->logger = $logger; } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/LoggedBuildContextTidier.php b/PHPCI/Logging/LoggedBuildContextTidier.php index aa852ae5..2b70f443 100644 --- a/PHPCI/Logging/LoggedBuildContextTidier.php +++ b/PHPCI/Logging/LoggedBuildContextTidier.php @@ -6,7 +6,7 @@ use PHPCI\Model\Build; class LoggedBuildContextTidier { - function __invoke() + public function __invoke() { return $this->tidyLoggedBuildContext(func_get_arg(0)); } @@ -29,4 +29,4 @@ class LoggedBuildContextTidier } return $logRecord; } -} \ No newline at end of file +} diff --git a/PHPCI/Logging/LoggerConfig.php b/PHPCI/Logging/LoggerConfig.php index 5c579f6e..13b1f5e7 100644 --- a/PHPCI/Logging/LoggerConfig.php +++ b/PHPCI/Logging/LoggerConfig.php @@ -6,9 +6,10 @@ namespace PHPCI\Logging; use Monolog\Logger; -class LoggerConfig { +class LoggerConfig +{ - const KEY_AlwaysLoaded = "_"; + const KEY_ALWAYS_LOADED = "_"; private $config; @@ -23,8 +24,7 @@ class LoggerConfig { { if (file_exists($filePath)) { $configArray = require($filePath); - } - else { + } else { $configArray = array(); } return new self($configArray); @@ -36,7 +36,8 @@ class LoggerConfig { * array of LogHandlers. * @param array $configArray */ - function __construct(array $configArray = array()) { + public function __construct(array $configArray = array()) + { $this->config = $configArray; } @@ -46,13 +47,15 @@ class LoggerConfig { * @param $name * @return Logger */ - public function getFor($name) { - $handlers = $this->getHandlers(self::KEY_AlwaysLoaded); + public function getFor($name) + { + $handlers = $this->getHandlers(self::KEY_ALWAYS_LOADED); $handlers = array_merge($handlers, $this->getHandlers($name)); return new Logger($name, $handlers); } - protected function getHandlers($key) { + protected function getHandlers($key) + { $handlers = array(); // They key is expected to either be an array or @@ -60,12 +63,10 @@ class LoggerConfig { if (isset($this->config[$key])) { if (is_callable($this->config[$key])) { $handlers = call_user_func($this->config[$key]); - } - elseif(is_array($this->config[$key])) { + } elseif (is_array($this->config[$key])) { $handlers = $this->config[$key]; } } return $handlers; } - -} \ No newline at end of file +} diff --git a/PHPCI/Logging/OutputLogHandler.php b/PHPCI/Logging/OutputLogHandler.php index a136ad0f..d573b03d 100644 --- a/PHPCI/Logging/OutputLogHandler.php +++ b/PHPCI/Logging/OutputLogHandler.php @@ -14,7 +14,7 @@ class OutputLogHandler extends AbstractProcessingHandler */ protected $output; - function __construct( + public function __construct( OutputInterface $output, $level = LogLevel::INFO, $bubble = true @@ -30,4 +30,4 @@ class OutputLogHandler extends AbstractProcessingHandler } -} \ No newline at end of file +} diff --git a/Tests/PHPCI/Logging/LoggerConfigTest.php b/Tests/PHPCI/Logging/LoggerConfigTest.php index 68f28f3a..f1e78245 100644 --- a/Tests/PHPCI/Logging/LoggerConfigTest.php +++ b/Tests/PHPCI/Logging/LoggerConfigTest.php @@ -24,7 +24,7 @@ class LoggerConfigTest extends \PHPUnit_Framework_TestCase { $expectedHandler = new \Monolog\Handler\NullHandler(); $config = new LoggerConfig(array( - LoggerConfig::KEY_AlwaysLoaded => function() use ($expectedHandler) { + LoggerConfig::KEY_ALWAYS_LOADED => function() use ($expectedHandler) { return array($expectedHandler); } )); From 6d4e49d07b66762215034d9712ee575bfd7f7c13 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 2 Mar 2014 19:59:52 +0000 Subject: [PATCH 07/22] Add code to allow configuration for the plugin factory to be stored on a per install basis. --- PHPCI/Plugin/Util/Factory.php | 22 +++++++++++++++ .../PHPCI/Plugin/Util/ExamplePluginConfig.php | 22 +++++++++++++++ Tests/PHPCI/Plugin/Util/FactoryTest.php | 27 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php diff --git a/PHPCI/Plugin/Util/Factory.php b/PHPCI/Plugin/Util/Factory.php index 0e526023..8adfd99d 100644 --- a/PHPCI/Plugin/Util/Factory.php +++ b/PHPCI/Plugin/Util/Factory.php @@ -37,6 +37,28 @@ class Factory { ); } + /** + * Trys to get a function from the file path specified. If the + * file returns a function then $this will be passed to it. + * This enables the config file to call any public methods. + * + * @param $configPath + * @return bool - true if the function exists else false. + */ + public function addConfigFromFile($configPath) + { + // The file is expected to return a function which can + // act on the pluginFactory to register any resources needed. + if (file_exists($configPath)) { + $configFunction = require($configPath); + if (is_callable($configFunction)) { + $configFunction($this); + return true; + } + } + return false; + } + public function getLastOptions() { return $this->currentPluginOptions; } diff --git a/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php b/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php new file mode 100644 index 00000000..4e4279b9 --- /dev/null +++ b/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php @@ -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 diff --git a/Tests/PHPCI/Plugin/Util/FactoryTest.php b/Tests/PHPCI/Plugin/Util/FactoryTest.php index 3265e07c..72ed714b 100644 --- a/Tests/PHPCI/Plugin/Util/FactoryTest.php +++ b/Tests/PHPCI/Plugin/Util/FactoryTest.php @@ -148,6 +148,33 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { $this->assertArrayHasKey('thing', $plugin->Options); } + public function testAddConfigFromFile_ReturnsTrueForValidFile() + { + $result = $this->testedFactory->addConfigFromFile( + realpath(__DIR__ . "/ExamplePluginConfig.php") + ); + + $this->assertTrue($result); + } + + public function testAddConfigFromFile_RegistersResources() + { + $this->testedFactory->addConfigFromFile( + realpath(__DIR__ . "/ExamplePluginConfig.php") + ); + + $namespace = '\\PHPCI\\Plugin\\Tests\\Util\\'; + $pluginName = $namespace . 'ExamplePluginWithSingleRequiredArg'; + + $plugin = $this->testedFactory->buildPlugin($pluginName); + + // The Example config file defines an array as the resource. + $this->assertEquals( + array("bar" => "Hello"), + $plugin->RequiredArgument + ); + } + /** * Registers mocked Builder and Build classes so that realistic plugins * can be tested. From 20d5e5a6b294e8b2709d0418b74d119c4b741a01 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 2 Mar 2014 20:00:43 +0000 Subject: [PATCH 08/22] 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 From 3c1cb07e97df1f6fa6def58b5be4dd5530f944cb Mon Sep 17 00:00:00 2001 From: meadsteve Date: Sun, 2 Mar 2014 20:10:48 +0000 Subject: [PATCH 09/22] Update test ExamplePluginConfg.php to match test. --- Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php b/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php index 4e4279b9..0b883071 100644 --- a/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php +++ b/Tests/PHPCI/Plugin/Util/ExamplePluginConfig.php @@ -4,19 +4,10 @@ return function (PHPCI\Plugin\Util\Factory $factory) { // This function will be called when the resource is needed. function() { return array( - 'Foo' => "Stuff", - 'Bar' => "More Stuff" + 'bar' => "Hello", ); }, - - // 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 + "requiredArgument", + null ); }; \ No newline at end of file From ff9ebdf744f49b106d218df226fa658376ca9c56 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Mon, 10 Mar 2014 12:08:16 +0000 Subject: [PATCH 10/22] Add debug logging to findBinary() --- PHPCI/Helper/CommandExecutor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index 9b7fe442..a422d970 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -4,6 +4,7 @@ namespace PHPCI\Helper; use \PHPCI\Logging\BuildLogger; +use Psr\Log\LogLevel; class CommandExecutor { @@ -112,13 +113,16 @@ class CommandExecutor } foreach ($binary as $bin) { + $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); // Check project root directory: if (is_file($this->rootDir . $bin)) { + $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); return $this->rootDir . $bin; } // Check Composer bin dir: if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { + $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); return $this->rootDir . 'vendor/bin/' . $bin; } @@ -127,6 +131,7 @@ class CommandExecutor $findCmdResult = trim(shell_exec($findCmd . ' ' . $bin)); if (!empty($findCmdResult)) { + $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); return $findCmdResult; } } From 3aa4806e250c5ac197179625654941fa180147e3 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Sat, 15 Mar 2014 12:57:06 +0700 Subject: [PATCH 11/22] Windows fixes --- PHPCI/Helper/CommandExecutor.php | 2 +- PHPCI/Model/Build/LocalBuild.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index 70bfcff5..2e88b938 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -127,7 +127,7 @@ class CommandExecutor } // Use "where" for windows and "which" for other OS - $findCmd = IS_WIN ? 'which' : 'where'; + $findCmd = IS_WIN ? 'where' : 'which'; $findCmdResult = trim(shell_exec($findCmd . ' ' . $bin)); if (!empty($findCmdResult)) { diff --git a/PHPCI/Model/Build/LocalBuild.php b/PHPCI/Model/Build/LocalBuild.php index 485376ad..8cf3844b 100644 --- a/PHPCI/Model/Build/LocalBuild.php +++ b/PHPCI/Model/Build/LocalBuild.php @@ -47,7 +47,7 @@ class LocalBuild extends Build } else { $cmd = 'cp -Rf "%s" "%s/"'; if (IS_WIN) { - $cmd = 'copy /Y "%s" "%s/"'; + $cmd = 'xcopy /E /Y "%s" "%s/*"'; } $builder->executeCommand($cmd, $reference, $buildPath); } From 92647c6bf9aa0b678e6da4108bd29fa5c5acf34f Mon Sep 17 00:00:00 2001 From: Corpsee Date: Tue, 18 Mar 2014 01:10:47 +0700 Subject: [PATCH 12/22] Added simple error/exception handler and logging --- PHPCI/Logging/Handler.php | 100 +++++++++++++++++++++++++++++++++ PHPCI/Logging/LoggerConfig.php | 4 +- bootstrap.php | 7 ++- console | 4 +- 4 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 PHPCI/Logging/Handler.php diff --git a/PHPCI/Logging/Handler.php b/PHPCI/Logging/Handler.php new file mode 100644 index 00000000..3ae5e93f --- /dev/null +++ b/PHPCI/Logging/Handler.php @@ -0,0 +1,100 @@ + 'Warning', + E_NOTICE => 'Notice', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Runtime Notice', + E_RECOVERABLE_ERROR => 'Catchable Fatal Error', + E_DEPRECATED => 'Deprecated', + E_USER_DEPRECATED => 'User Deprecated', + ); + + /** + * @var LoggerInterface + */ + protected $logger; + + public function __construct(LoggerInterface $logger = NULL) + { + $this->logger = $logger; + } + + public static function register(LoggerInterface $logger = NULL) + { + $handler = new static($logger); + + set_error_handler(array($handler, 'handleError')); + register_shutdown_function(array($handler, 'handleFatalError')); + + set_exception_handler(array($handler, 'handleException')); + } + + /** + * @param integer $level + * @param string $message + * @param string $file + * @param integer $line + * + * @throws \ErrorException + */ + public function handleError($level, $message, $file, $line) + { + if (error_reporting() & $level) { + + $exception_level = isset($this->levels[$level]) ? $this->levels[$level] : $level; + + throw new \ErrorException( + sprintf('%s: %s in %s line %d', $exception_level, $message, $file, $line), + 0, $level, $file, $line + ); + } + } + + /** + * @throws \ErrorException + */ + public function handleFatalError() + { + $fatal_error = error_get_last(); + + if ($fatal_error['type'] === E_ERROR) { + + $e = new \ErrorException( + sprintf('%s: %s in %s line %d', $fatal_error['type'], $fatal_error['message'], $fatal_error['file'], $fatal_error['line']), + 0, $fatal_error['type'], $fatal_error['file'], $fatal_error['line'] + ); + $this->log($e); + } + } + + /** + * @param \Exception $exception + */ + public function handleException(\Exception $exception) + { + $this->log($exception); + } + + protected function log(\Exception $exception) + { + if (null !== $this->logger) { + + $message = sprintf( + '%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine() + ); + $this->logger->error($message); + } + } +} \ No newline at end of file diff --git a/PHPCI/Logging/LoggerConfig.php b/PHPCI/Logging/LoggerConfig.php index 5c579f6e..3eb0a5b2 100644 --- a/PHPCI/Logging/LoggerConfig.php +++ b/PHPCI/Logging/LoggerConfig.php @@ -22,7 +22,7 @@ class LoggerConfig { public static function newFromFile($filePath) { if (file_exists($filePath)) { - $configArray = require($filePath); + $configArray = require_once($filePath); } else { $configArray = array(); @@ -48,7 +48,7 @@ class LoggerConfig { */ public function getFor($name) { $handlers = $this->getHandlers(self::KEY_AlwaysLoaded); - $handlers = array_merge($handlers, $this->getHandlers($name)); + //$handlers = array_merge($handlers, $this->getHandlers($name)); return new Logger($name, $handlers); } diff --git a/bootstrap.php b/bootstrap.php index 01301dbb..a8ececf3 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,6 +8,9 @@ */ // Let PHP take a guess as to the default timezone, if the user hasn't set one: +use PHPCI\Logging\Handler; +use PHPCI\Logging\LoggerConfig; + date_default_timezone_set(@date_default_timezone_get()); // Set up a basic autoloader for PHPCI: @@ -37,10 +40,12 @@ if (!file_exists(dirname(__FILE__) . '/vendor/autoload.php') && defined('PHPCI_I exit(1); } - // Load Composer autoloader: require_once(dirname(__FILE__) . '/vendor/autoload.php'); +$loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); +Handler::register($loggerConfig->getFor('Exceptions')); + // Load configuration if present: $conf = array(); $conf['b8']['app']['namespace'] = 'PHPCI'; diff --git a/console b/console index 8a65f1c5..43fc2b8f 100755 --- a/console +++ b/console @@ -21,8 +21,6 @@ use PHPCI\Command\PollCommand; use PHPCI\Command\CreateAdminCommand; use Symfony\Component\Console\Application; -$loggerConfig = \PHPCI\Logging\LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); - $application = new Application(); $application->add(new RunCommand($loggerConfig->getFor('RunCommand'))); @@ -33,4 +31,4 @@ $application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand'))); $application->add(new PollCommand($loggerConfig->getFor('PollCommand'))); $application->add(new CreateAdminCommand); -$application->run(); +$application->run(); \ No newline at end of file From e7e685e9bd1203eb3a4a0ade32430784c45e4494 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Tue, 18 Mar 2014 22:57:05 +0700 Subject: [PATCH 13/22] ProjectController::view 404 fix --- PHPCI/Controller/ProjectController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 19fb3149..03c8c1ac 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -17,6 +17,7 @@ use b8\Config; use b8\Controller; use b8\Store; use b8\Form; +use b8\Exception\HttpException\NotFoundException; /** * Project Controller - Allows users to create, edit and view projects. @@ -47,7 +48,11 @@ class ProjectController extends \PHPCI\Controller */ public function view($projectId) { - $project = $this->projectStore->getById($projectId); + $project = $this->projectStore->getById($projectId); + if (!$project) { + throw new NotFoundException('Project with id: ' . $projectId . ' not found'); + } + $page = $this->getParam('p', 1); $builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10)); From b2240104b45a09a940d980d987b5c4688b415c19 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Tue, 18 Mar 2014 23:58:23 +0700 Subject: [PATCH 14/22] Fixed rm for windows --- PHPCI/Builder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index ba6d2e3a..6f04c9d8 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -216,7 +216,12 @@ class Builder implements LoggerAwareInterface // Clean up: $this->buildLogger->log('Removing build.'); - shell_exec(sprintf('rm -Rf "%s"', $this->buildPath)); + + $cmd = 'rm -Rf "%s"'; + if (IS_WIN) { + $cmd = 'deltree /Y "%s"'; + } + $this->executeCommand($cmd, $this->buildPath); // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback(); From b28b5a575f28f5a4b947228a7546ade18fa09712 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Wed, 19 Mar 2014 00:04:29 +0700 Subject: [PATCH 15/22] Fixed rm for windows --- PHPCI/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 6f04c9d8..34373ba8 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -219,7 +219,7 @@ class Builder implements LoggerAwareInterface $cmd = 'rm -Rf "%s"'; if (IS_WIN) { - $cmd = 'deltree /Y "%s"'; + $cmd = 'rmdir /S /Q "%s"'; } $this->executeCommand($cmd, $this->buildPath); From 15d5c022c57e612c6d04c1a1a95c3846ab71185c Mon Sep 17 00:00:00 2001 From: Corpsee Date: Thu, 20 Mar 2014 22:17:54 +0700 Subject: [PATCH 16/22] Improved error/exception handler and logging --- PHPCI/Logging/Handler.php | 13 +++++++++++-- PHPCI/Logging/LoggerConfig.php | 2 +- bootstrap.php | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/PHPCI/Logging/Handler.php b/PHPCI/Logging/Handler.php index 3ae5e93f..36e80844 100644 --- a/PHPCI/Logging/Handler.php +++ b/PHPCI/Logging/Handler.php @@ -69,8 +69,17 @@ class Handler { $fatal_error = error_get_last(); - if ($fatal_error['type'] === E_ERROR) { - + try { + if (($e = error_get_last()) !== null) { + $e = new \ErrorException( + sprintf('%s: %s in %s line %d', $fatal_error['type'], $fatal_error['message'], $fatal_error['file'], $fatal_error['line']), + 0, $fatal_error['type'], $fatal_error['file'], $fatal_error['line'] + ); + $this->log($e); + } + } + catch (\Exception $e) + { $e = new \ErrorException( sprintf('%s: %s in %s line %d', $fatal_error['type'], $fatal_error['message'], $fatal_error['file'], $fatal_error['line']), 0, $fatal_error['type'], $fatal_error['file'], $fatal_error['line'] diff --git a/PHPCI/Logging/LoggerConfig.php b/PHPCI/Logging/LoggerConfig.php index 3eb0a5b2..b0ebeeec 100644 --- a/PHPCI/Logging/LoggerConfig.php +++ b/PHPCI/Logging/LoggerConfig.php @@ -48,7 +48,7 @@ class LoggerConfig { */ public function getFor($name) { $handlers = $this->getHandlers(self::KEY_AlwaysLoaded); - //$handlers = array_merge($handlers, $this->getHandlers($name)); + $handlers = array_merge($handlers, $this->getHandlers($name)); return new Logger($name, $handlers); } diff --git a/bootstrap.php b/bootstrap.php index a8ececf3..3cfcf038 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -44,7 +44,7 @@ if (!file_exists(dirname(__FILE__) . '/vendor/autoload.php') && defined('PHPCI_I require_once(dirname(__FILE__) . '/vendor/autoload.php'); $loggerConfig = LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php"); -Handler::register($loggerConfig->getFor('Exceptions')); +Handler::register($loggerConfig->getFor('_')); // Load configuration if present: $conf = array(); From 2730b47e0b07e88ea3a37cd49e20a7c607a8a9c0 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Thu, 20 Mar 2014 22:32:57 +0700 Subject: [PATCH 17/22] Fixed log pathes --- loggerconfig.php.example | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/loggerconfig.php.example b/loggerconfig.php.example index dad42f17..c306673b 100644 --- a/loggerconfig.php.example +++ b/loggerconfig.php.example @@ -1,16 +1,16 @@ function() { return array( - new \Monolog\Handler\StreamHandler('c:\temp\errors.log', \Monolog\Logger::ERROR), + new \Monolog\Handler\StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'errors.log', \Monolog\Logger::ERROR), ); }, - /** Loggers for the RunCommand */ 'RunCommand' => function() { return array( - new \Monolog\Handler\RotatingFileHandler('c:\temp\everything',3, \Monolog\Logger::INFO), + new \Monolog\Handler\RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'everything',3, \Monolog\Logger::DEBUG), ); - } + }, ); \ No newline at end of file From 1cdb29840e31e37abc8e20c59f424ac2807d6633 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Thu, 20 Mar 2014 22:33:25 +0700 Subject: [PATCH 18/22] Fixed log pathes --- loggerconfig.php.example | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/loggerconfig.php.example b/loggerconfig.php.example index dad42f17..c306673b 100644 --- a/loggerconfig.php.example +++ b/loggerconfig.php.example @@ -1,16 +1,16 @@ function() { return array( - new \Monolog\Handler\StreamHandler('c:\temp\errors.log', \Monolog\Logger::ERROR), + new \Monolog\Handler\StreamHandler(__DIR__ . DIRECTORY_SEPARATOR . 'errors.log', \Monolog\Logger::ERROR), ); }, - /** Loggers for the RunCommand */ 'RunCommand' => function() { return array( - new \Monolog\Handler\RotatingFileHandler('c:\temp\everything',3, \Monolog\Logger::INFO), + new \Monolog\Handler\RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'everything',3, \Monolog\Logger::DEBUG), ); - } + }, ); \ No newline at end of file From 04dae16157f2ee099bd6d5a3392a064722292366 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Thu, 20 Mar 2014 22:51:30 +0700 Subject: [PATCH 19/22] Fixed require() in LoggerConfig --- PHPCI/Logging/LoggerConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Logging/LoggerConfig.php b/PHPCI/Logging/LoggerConfig.php index b0ebeeec..5c579f6e 100644 --- a/PHPCI/Logging/LoggerConfig.php +++ b/PHPCI/Logging/LoggerConfig.php @@ -22,7 +22,7 @@ class LoggerConfig { public static function newFromFile($filePath) { if (file_exists($filePath)) { - $configArray = require_once($filePath); + $configArray = require($filePath); } else { $configArray = array(); From 08a15d872429bb625b0ef69213a2dfcef52cddd0 Mon Sep 17 00:00:00 2001 From: Corpsee Date: Mon, 24 Mar 2014 23:43:20 +0700 Subject: [PATCH 20/22] Added exception context for errror/exception handler logging --- PHPCI/Logging/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Logging/Handler.php b/PHPCI/Logging/Handler.php index 36e80844..55e0e4a3 100644 --- a/PHPCI/Logging/Handler.php +++ b/PHPCI/Logging/Handler.php @@ -103,7 +103,7 @@ class Handler $message = sprintf( '%s: %s (uncaught exception) at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine() ); - $this->logger->error($message); + $this->logger->error($message, array('exception' => $exception)); } } } \ No newline at end of file From 7e669ada4797fcce9e7e5c1d21e1bbcd3ad11db2 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Tue, 25 Mar 2014 14:17:03 +0000 Subject: [PATCH 21/22] Merge remote-tracking branch 'origin/master' into feature/pluginfactoryconfig Conflicts: PHPCI/Builder.php PHPCI/Plugin/Util/Factory.php --- PHPCI/Plugin/Util/Factory.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/PHPCI/Plugin/Util/Factory.php b/PHPCI/Plugin/Util/Factory.php index 9740516f..097f8bf5 100644 --- a/PHPCI/Plugin/Util/Factory.php +++ b/PHPCI/Plugin/Util/Factory.php @@ -36,7 +36,28 @@ class Factory { 'array' ); } - + + /** + * Trys to get a function from the file path specified. If the + * file returns a function then $this will be passed to it. + * This enables the config file to call any public methods. + * + * @param $configPath + * @return bool - true if the function exists else false. + */ + public function addConfigFromFile($configPath) + { + // The file is expected to return a function which can + // act on the pluginFactory to register any resources needed. + if (file_exists($configPath)) { + $configFunction = require($configPath); + if (is_callable($configFunction)) { + $configFunction($this); + return true; + } + } + return false; + } public function getLastOptions() { From 326113ebbcc40fd83b00e61a44061f469f140e98 Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Tue, 25 Mar 2014 14:18:50 +0000 Subject: [PATCH 22/22] psr tidy up of util/Factory.php --- PHPCI/Plugin/Util/Factory.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/PHPCI/Plugin/Util/Factory.php b/PHPCI/Plugin/Util/Factory.php index 097f8bf5..971b3e23 100644 --- a/PHPCI/Plugin/Util/Factory.php +++ b/PHPCI/Plugin/Util/Factory.php @@ -4,7 +4,8 @@ namespace PHPCI\Plugin\Util; -class Factory { +class Factory +{ const TYPE_ARRAY = "array"; const TYPE_CALLABLE = "callable"; @@ -18,18 +19,17 @@ class Factory { */ private $container; - function __construct(\Pimple $container = null) + public function __construct(\Pimple $container = null) { if ($container) { $this->container = $container; - } - else { + } else { $this->container = new \Pimple(); } $self = $this; $this->registerResource( - function() use ($self) { + function () use ($self) { return $self->getLastOptions(); }, 'options', @@ -89,7 +89,7 @@ class Factory { if ($constructor) { $argsToUse = array(); - foreach($constructor->getParameters() as $param) { + foreach ($constructor->getParameters() as $param) { $argsToUse = $this->addArgFromParam($argsToUse, $param); } $plugin = $reflectedPlugin->newInstanceArgs($argsToUse); @@ -107,11 +107,11 @@ class Factory { * @throws \InvalidArgumentException * @internal param mixed $resource */ - public function registerResource($loader, - $name = null, - $type = null - ) - { + public function registerResource( + $loader, + $name = null, + $type = null + ) { if ($name === null && $type === null) { throw new \InvalidArgumentException( "Type or Name must be specified" @@ -161,9 +161,9 @@ class Factory { $class = $param->getClass(); if ($class) { return $class->getName(); - } elseif($param->isArray()) { + } elseif ($param->isArray()) { return self::TYPE_ARRAY; - } elseif($param->isCallable()) { + } elseif ($param->isCallable()) { return self::TYPE_CALLABLE; } else { return null; @@ -188,4 +188,4 @@ class Factory { return $existingArgs; } -} \ No newline at end of file +}