Пример #1
0
 /**
  * Routes the request to a registered page handler
  *
  * This function triggers a plugin hook `'route', $identifier` so that plugins can
  * modify the routing or handle a request.
  *
  * @param Elgg_Http_Request $request The request to handle.
  * @return boolean Whether the request was routed successfully.
  * @access private
  */
 public function route(Elgg_Http_Request $request)
 {
     $segments = $request->getUrlSegments();
     if ($segments) {
         $identifier = array_shift($segments);
     } else {
         $identifier = '';
         // this plugin hook is deprecated. Use elgg_register_page_handler()
         // to register for the '' (empty string) handler.
         // allow plugins to override the front page (return true to indicate
         // that the front page has been served)
         $result = elgg_trigger_plugin_hook('index', 'system', null, false);
         if ($result === true) {
             elgg_deprecated_notice("The 'index', 'system' plugin has been deprecated. See elgg_front_page_handler()", 1.9);
             exit;
         }
     }
     // return false to stop processing the request (because you handled it)
     // return a new $result array if you want to route the request differently
     $result = array('identifier' => $identifier, 'handler' => $identifier, 'segments' => $segments);
     $result = $this->hooks->trigger('route', $identifier, null, $result);
     if ($result === false) {
         return true;
     }
     $identifier = $result['identifier'];
     $segments = $result['segments'];
     $handled = false;
     if (isset($this->handlers[$identifier]) && is_callable($this->handlers[$identifier])) {
         $function = $this->handlers[$identifier];
         $handled = call_user_func($function, $segments, $identifier);
     }
     return $handled || headers_sent();
 }
 /**
  * 1. Register a page handler for `/foo`
  * 2. Register a plugin hook that uses the "handler" result param
  *    to route all `/bar/*` requests to the `/foo` handler.
  * 3. Route a request for a `/bar` page.
  * 4. Check that the `/foo` handler was called.
  */
 function testRouteSupportsSettingHandlerInHookResultForBackwardsCompatibility()
 {
     $this->router->registerPageHandler('foo', array($this, 'foo_page_handler'));
     $this->hooks->registerHandler('route', 'bar', array($this, 'bar_route_handler'));
     $query = http_build_query(array('__elgg_uri' => 'bar/baz'));
     ob_start();
     $this->router->route(Elgg_Http_Request::create("http://localhost/?{$query}"));
     ob_end_clean();
     $this->assertEquals(1, $this->fooHandlerCalls);
 }
Пример #3
0
 function testCanUnregisterPageHandlers()
 {
     $this->router->registerPageHandler('hello', array($this, 'hello_page_handler'));
     $this->router->unregisterPageHandler('hello');
     $request = Elgg_Http_Request::create('http://localhost/hello/');
     ob_start();
     $handled = $this->router->route($request);
     $output = ob_get_clean();
     // Normally we would expect the router to return false for this request,
     // but since it checks for headers_sent() and PHPUnit issues output before
     // this test runs, the headers have already been sent. It's enough to verify
     // that the output we buffered is empty.
     // $this->assertFalse($handled);
     $this->assertEmpty($output);
 }
 /**
  * Gets the normalized query string for the Request.
  *
  * It builds a normalized query string, where keys/value pairs are alphabetized
  * and have consistent escaping.
  *
  * @return string|null A normalized query string for the Request
  */
 public function getQueryString()
 {
     $qs = Elgg_Http_Request::normalizeQueryString($this->server->get('QUERY_STRING'));
     return '' === $qs ? null : $qs;
 }
Пример #5
0
 /**
  * Request factory
  * 
  * @param Elgg_Di_ServiceProvider $c Dependency injection container
  * @return Elgg_Http_Request
  */
 protected function getRequest(Elgg_Di_ServiceProvider $c)
 {
     return Elgg_Http_Request::createFromGlobals();
 }