dispatch() публичный Метод

public dispatch ( $request )
Пример #1
0
*
* This is a modified BSD license (the third clause has been removed).
* The BSD license may be found here:
* 
* http://www.opensource.org/licenses/bsd-license.php
*
*/
// include heavy metal
include '../sys/sys.php';
// init the framework
init(dirname(dirname(__FILE__) . "..") . "/");
uses('sys.app.http.http_dispatcher');
uses('sys.app.config');
// load the environment
Config::LoadEnvironment();
// start buffering
ob_start();
// dispatch the request
try {
    $dispatcher = new HTTPDispatcher();
    print trim($dispatcher->dispatch());
} catch (DispatcherException $ex) {
    ob_end_clean();
    header('HTTP/1.0 404 Not Found');
} catch (ErrorResponseException $ex) {
    ob_end_clean();
    header('HTTP/1.0 ' . $ex->error_code());
}
Config::ShutdownEnvironment();
// flush the buffer
ob_flush();
Пример #2
0
 /**
  * Tests rendering ajax views
  */
 public function testAjaxView()
 {
     $_SERVER['HTTP_X_REQUESTED_WITH'] = 'prototype?';
     $dispatcher = new HTTPDispatcher('/test/dispatch');
     $output = $dispatcher->dispatch();
     $this->assertTrue($output == 'ajax says hello world');
 }
Пример #3
0
 /**
  * Parses out portlets.  Portlets make a request to "controller" and then render the "view" inside the "container_template"
  * @param string $rendered The view's rendered output that may contain control or uses tags
  */
 protected function parse_ports(&$rendered)
 {
     // extract php control includes
     $regex = '#<[\\s]*render[\\s]*:[\\s]*port([^>]*?)[\\s]*/[\\s]*>#is';
     // extracts the tag
     // parse the rendered view
     $matches = array();
     while (preg_match($regex, $rendered, $matches, PREG_OFFSET_CAPTURE) == 1) {
         $parsed_attr = array();
         preg_match_all(View::REGEX_ATTRIBUTE, $matches[1][0], $parsed_attr, PREG_SET_ORDER);
         $path = null;
         $target = null;
         foreach ($parsed_attr as $attr) {
             switch ($attr[1]) {
                 case 'path':
                     $path = $attr[3];
                     break;
                 case 'target':
                     $target = $attr[3];
                     break;
                 default:
                     if (preg_match('#{[^}]*}#is', $attr[3])) {
                         $key = trim(trim($attr[3], '{'), '}');
                         if (strpos($key, '@') !== false) {
                             $key = trim($key, '@');
                             $model = $this->data[$key];
                             if ($model instanceof Model) {
                                 $this->data[$attr[1]] = $model->to_array();
                             } else {
                                 if ($model) {
                                     $this->data[$attr[1]] = $model;
                                 } else {
                                     user_error("Cannot bind to variable '{$key}'.", E_USER_WARNING);
                                 }
                             }
                         } else {
                             if (isset($this->data[$key])) {
                                 $this->data[$attr[1]] = $this->data[$key];
                             } else {
                                 user_error("Cannot bind to variable '{$key}'.", E_USER_WARNING);
                             }
                         }
                     } else {
                         $this->data[$attr[1]] = $attr[3];
                     }
                     break;
             }
         }
         if ($path != null) {
             $port_dispatcher = new HTTPDispatcher($path);
             $result = $port_dispatcher->dispatch();
             if ($this->layout != null && $target != null) {
                 $this->layout->add_content($target, $result);
                 $rendered = str_replace($matches[0][0], '', $rendered);
             } else {
                 $rendered = str_replace($matches[0][0], $result, $rendered);
             }
         } else {
             $rendered = str_replace($matches[0][0], '', $rendered);
         }
     }
 }