protected function loadActionResultTypes($actionName, ResultTypeService $service) { if (!$this->descriptor instanceof Descriptor) { return; } $results = array(); $map = $this->xmlActionResultsXmlMapFactory($actionName); foreach ($this->descriptor->getSourcesXml() as $xml) { $this->descriptor->set('packageDir', dirname($xml->getRealPath())); $parse = $map->execute($xml); $res = isset($parse['results']) ? $parse['results'] : array(); $results = array_merge($results, $res); } foreach ($results as $result => $data) { $service->register($actionName, $result, $data['type'], $data['params']); } $this->descriptor->set('packageDir', null); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $service = new ResultTypeService(); $service->addType('json', new JsonResultType()); $service->addType('php', new PhpTemplateResultType(array('templatesDir' => TEST_RESOURCES_DIR))); $service->addType('redirect', new RedirectResultType()); $service->register('TestAction', \Fwk\Core\Action\Result::SUCCESS, 'json'); $service->register('TestAction', \Fwk\Core\Action\Result::REDIRECT, 'redirect', array('uri' => '/')); $service->register('TestAction', 'template', 'php', array('file' => 'phptemplate_resulttype.php')); $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new ResultTypeListener('resultTypeService')); $app['TestAction'] = function ($result) { return $result; }; $app['TestActionObj'] = function () { return new \stdClass(); }; $app->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true); $app->getServices()->set('resultTypeService', $service, true); $this->object = $app; }