/** * Adds an action to the front controller action stack. Please note, that the namespace of * the namespace of the action config is added the current context. The name of the * config file is concatenated by the current environment and the string * <em>*_actionconfig.ini</em>. * * @param string $namespace Namespace of the action. * @param string $name Name of the action (section key of the config file). * @param array $params (Input-)params of the action. * * @throws InvalidArgumentException In case the action cannot be found within the appropriate * configuration or the action implementation classes are not available. * * @author Christian Achatz * @version * Version 0.1, 05.06.2007<br /> * Version 0.2, 01.07.2007<br /> * Version 0.3, 02.09.2007<br /> * Version 0.4, 08.09.2007 (Bug-fix: input params from config are now evaluated)<br /> * Version 0.5, 08.11.2007 (Changed action stack construction to hash offsets)<br /> * Version 0.6, 21.06.2008 (Replaced APPS__ENVIRONMENT constant with a value from the Registry)<br /> * Version 0.7, 27.09.2010 (Removed synthetic "actions" sub-namespace)<br /> * Version 0.8, 09.04.2011 (Made input implementation optional, removed separate action and input class file definition)<br /> * Version 0.9. 20.08.2013 Jan Wiese (Added support for actions generated by thw DIServiceManager)<br /> */ public function addAction($namespace, $name, array $params = []) { // re-map namespace $namespace = $this->getActionNamespaceByURLString($namespace); // load the action configuration $config = $this->getConfiguration($namespace, 'actionconfig.ini'); // throw exception, in case the action config is not present if (!$config->hasSection($name)) { $env = Registry::retrieve('APF\\core', 'Environment'); throw new InvalidArgumentException('[Frontcontroller::addAction()] No config ' . 'section for action key "' . $name . '" available in configuration file "' . $env . '_actionconfig.ini" in namespace "' . $namespace . '" and context "' . $this->getContext() . '"!', E_USER_ERROR); } $actionConfig = $config->getSection($name); // evaluate which method to use: simple object or di service $actionServiceName = $actionConfig->getValue('ActionServiceName'); $actionServiceNamespace = $actionConfig->getValue('ActionServiceNamespace'); if (!(empty($actionServiceName) || empty($actionServiceNamespace))) { // use di service try { $action = DIServiceManager::getServiceObject($actionServiceNamespace, $actionServiceName, $this->getContext(), $this->getLanguage()); } catch (Exception $e) { throw new InvalidArgumentException('[Frontcontroller::addAction()] Action could not be created using DIServiceManager with service name "' . $actionServiceName . '" and service namespace "' . $actionServiceNamespace . '". Please check your action and service configuration files! Message from DIServiceManager was: ' . $e->getMessage(), $e->getCode()); } } else { // use simple object // include action implementation $actionClass = $actionConfig->getValue('ActionClass'); // check for class being present if (!class_exists($actionClass)) { throw new InvalidArgumentException('[Frontcontroller::addAction()] Action class with name "' . $actionClass . '" could not be found. Please check your action configuration file!', E_USER_ERROR); } // init action $action = new $actionClass(); /* @var $action Action */ $action->setContext($this->getContext()); $action->setLanguage($this->getLanguage()); } // init action $action->setActionNamespace($namespace); $action->setActionName($name); // check for custom input implementation $inputClass = $actionConfig->getValue('InputClass'); // include input implementation in case a custom implementation is desired if (empty($inputClass)) { $inputClass = FrontcontrollerInput::class; } // check for class being present if (!class_exists($inputClass)) { throw new InvalidArgumentException('[Frontcontroller::addAction()] Input class with name "' . $inputClass . '" could not be found. Please check your action configuration file!', E_USER_ERROR); } // init input $input = new $inputClass(); /* @var $input FrontcontrollerInput */ // merge input params with the configured params (params included in the URL are kept!) $input->setParameters(array_merge($this->generateParamsFromInputConfig($actionConfig->getValue('InputParams')), $params)); $input->setAction($action); $action->setInput($input); // set the frontcontroller as a parent object to the action $action->setFrontController($this); // add the action as a child $this->actionStack[] = $action; // ID#83: Sort actions to allow prioritization of actions. This is done using // uksort() in order to both respect Action::getPriority() // and the order of registration for equivalence groups. uksort($this->actionStack, [$this, 'sortActions']); }
/** * Returns a service object, that is initialized by dependency injection. * For details see {@link DIServiceManager}. * * @param string $namespace The namespace of the service object definition. * @param string $name The name of the service object. * * @return APFObject The pre-configured service object. * * @author Christian Achatz * @version * Version 0.1, 18.04.2009<br /> */ protected function &getDIServiceObject($namespace, $name) { return DIServiceManager::getServiceObject($namespace, $name, $this->getContext(), $this->getLanguage()); }
public function testSetterInjectionMultipleParameters() { /* @var $service DummyServiceThree */ $service = DIServiceManager::getServiceObject(self::TEST_VENDOR, 'DummyServiceThree', self::CONTEXT, self::LANGUAGE); $this->assertEquals('foo', $service->getParamOne()); $this->assertEquals('bar', $service->getParamTwo()); $this->assertEquals('baz', $service->getParamThree()); }