action_type); return new $class($action); } /** * Returns the class name to be used for actions with the given name. This is a lookup function * that will match the given action type (ie. "change_category") to the matching class name * (SetCategory) using the configuration (firefly.php). * * @param string $actionType * * @return string * @throws FireflyException */ public static function getActionClass(string $actionType): string { $actionTypes = self::getActionTypes(); if (!array_key_exists($actionType, $actionTypes)) { throw new FireflyException('No such action exists ("' . e($actionType) . '").'); } $class = $actionTypes[$actionType]; if (!class_exists($class)) { throw new FireflyException('Could not instantiate class for rule action type "' . e($actionType) . '" (' . e($class) . ').'); } return $class; } /** * Returns a map with actiontypes, mapped to the class representing that type * * @return array */ protected static function getActionTypes(): array { if (count(self::$actionTypes) === 0) { self::$actionTypes = Domain::getRuleActions(); } return self::$actionTypes; } }