Ejemplo n.º 1
0
 public static function run($uri = '')
 {
     self::$dispatcher = new Dispatcher($uri);
     $controller_class = ucfirst(self::$dispatcher->getController()) . 'Controller';
     $controller_method = strtolower(self::$dispatcher->getAction()) . 'Action';
     $controller_object = new $controller_class();
     if (method_exists($controller_object, $controller_method)) {
         $controller_object->{$controller_method}();
         $layout = $controller_object->getLayout();
         if ($layout != '') {
             $page = new Page($layout, $controller_object->getData());
         } else {
             $page = new Page('default');
         }
         $page->render();
     } else {
         throw new Exception('Method ' . $controller_method . ' of ' . $controller_class . ' class in not found!');
     }
 }
Ejemplo n.º 2
0
 /**
  * @covers \Phix\App::dispatcher
  */
 public function testDefaultDispatcher()
 {
     $app = new App();
     $callback = $app->dispatcher();
     $callback($app, function ($app) {
         $app->output('foo');
     });
     $this->assertEquals('foo', $app->output());
     $app->reset();
     $callback($app, function ($app) {
         echo 'bar';
     });
     $this->assertEquals('bar', $app->output());
     $this->assertTrue(in_array('Content-Type: text/html;charset=utf-8', $app->headers()));
 }