public function run_handler($topic, array $args = array()) { if (is_object($topic)) { $component = $topic->component; } else { $component = $topic; $topic = $this->get_component_node($component); } $context = new midcom_core_context(null, $topic); $context->set_current(); $context->set_key(MIDCOM_CONTEXT_URI, midcom_connection::get_url('self') . $topic->name . '/' . implode('/', $args) . '/'); // Parser Init: Generate arguments and instantiate it. $context->parser = midcom::get('serviceloader')->load('midcom_core_service_urlparser'); $context->parser->parse($args); $handler = $context->get_handler($topic); $context->set_key(MIDCOM_CONTEXT_CONTENTTOPIC, $topic); $this->assertTrue(is_a($handler, 'midcom_baseclasses_components_interface'), $component . ' found no handler for ./' . implode('/', $args) . '/'); $result = $handler->handle(); $this->assertTrue($result !== false, $component . ' handle returned false on ./' . implode('/', $args) . '/'); $data =& $handler->_context_data[$context->id]['handler']->_handler['handler'][0]->_request_data; if (is_object($result) && $result instanceof midcom_response) { $data['__openpsa_testcase_response'] = $result; } $data['__openpsa_testcase_handler'] = $handler->_context_data[$context->id]['handler']->_handler['handler'][0]; $data['__openpsa_testcase_handler_method'] = $handler->_context_data[$context->id]['handler']->_handler['handler'][1]; // added to simulate http uri composition $_SERVER['REQUEST_URI'] = $context->get_key(MIDCOM_CONTEXT_URI); return $data; }
/** * Matches the current request to a handler if possible * * @throws midcom_error If topic can't be loaded * @return mixed Handler or false if there is no match */ public function process() { $this->_process_urlmethods(); midcom::get()->set_status(MIDCOM_STATUS_CANHANDLE); do { $object = $this->_context->parser->get_current_object(); if (!is_object($object) || !$object->guid) { throw new midcom_error('Root node missing.'); } if (is_a($object, 'midcom_db_attachment')) { $this->serve_attachment($object); } // Check whether the component can handle the request. // If so, execute it, if not, continue. if ($handler = $this->_context->get_handler($object)) { return $handler; } } while ($this->_context->parser->get_object() !== false); return false; }