From b671da900a72d32828acacad6b627fd36c7d9507 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 13:24:56 +0100 Subject: [PATCH] Implemented action factory analogue to trigger factory --- app/Rules/Actions/ActionFactory.php | 69 +++++++++++++++++++++++++++++ app/Rules/Processor.php | 9 +--- 2 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 app/Rules/Actions/ActionFactory.php diff --git a/app/Rules/Actions/ActionFactory.php b/app/Rules/Actions/ActionFactory.php new file mode 100644 index 0000000000..43161b56a1 --- /dev/null +++ b/app/Rules/Actions/ActionFactory.php @@ -0,0 +1,69 @@ +action_type; + $class = self::getActionClass($actionType); + + return new $class($action, $journal); + } + + /** + * Returns a map with actiontypes, mapped to the class representing that type + */ + protected static function getActionTypes() { + if( !self::$actionTypes ) { + self::$actionTypes = Domain::getRuleActions(); + } + + return self::$actionTypes; + } +} diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index 5c88a8e23a..4bde8b13c2 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -15,6 +15,7 @@ use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleTrigger; use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\Actions\ActionInterface; +use FireflyIII\Rules\Actions\ActionFactory; use FireflyIII\Rules\Triggers\TriggerInterface; use FireflyIII\Rules\Triggers\TriggerFactory; use FireflyIII\Support\Domain; @@ -103,14 +104,8 @@ class Processor * @var RuleAction $action */ foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $action) { - $type = $action->action_type; - $class = $this->actionTypes[$type]; - Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')'); - if (!class_exists($class)) { - abort(500, 'Could not instantiate class for rule action type "' . $type . '" (' . $class . ').'); - } /** @var ActionInterface $actionClass */ - $actionClass = new $class($action, $this->journal); + $actionClass = ActionFactory::getAction($action, $this->journal); $actionClass->act(); if ($action->stop_processing) { break;