Beispiel #1
0
 public function process(Request $req, Response $res, array $params, array $matchParams)
 {
     $params += array('controller' => null, 'action' => 'index', 'fn' => null);
     if ($params['controller']) {
         if (!class_exists($params['controller'])) {
             throw new Error('The controller was not found: ' . $params['controller']);
         }
         // TODO: use Instantiator?
         $refl = new ReflectionClass($params['controller']);
         $controller = $refl->newInstanceArgs([$this, $req, $res]);
         $data = call_user_func_array([$controller, $params['action']], $matchParams);
     } elseif ($params['fn']) {
         $data = call_user_func_array($params['fn'], array_merge([$req, $res], $matchParams));
     } else {
         throw new Error('Insufficient route parameters');
     }
     if (is_array($data)) {
         $res->data->set($data);
     } elseif (is_string($data)) {
         $res->write($data);
     }
     return $res;
 }
 public function testWrite()
 {
     $res = new Response(new Request('GET', '/test'));
     $res->write('test');
 }