Exemplo n.º 1
0
 public function test_get_nonexistent_default()
 {
     $this->assertEquals(null, \veneer\app::get_default('oogabooga'));
 }
Exemplo n.º 2
0
 /**
  * Discover route matches and invoke any corresponding methods found.
  * Handles route parsing and route parameters using some simple
  * regular expression pattern matching and function calling.
  *
  * @param string $method  The URL bit to match routes against
  * @param \veneer\http\response $response  Response object
  * @return bool
  */
 public function invoke($method, \veneer\http\response &$response)
 {
     $method = trim($method, '/');
     $request = explode('/', $method);
     $this->response =& $response;
     $router = new \veneer\router();
     $request_method = array_key_exists('REQUEST_METHOD', $_SERVER) ? strtolower($_SERVER['REQUEST_METHOD']) : 'get';
     foreach (array('get', 'post', 'put', 'delete') as $http_method) {
         if ($http_method == $request_method) {
             if (isset($this->{$http_method})) {
                 foreach ($this->{$http_method} as $route => $data) {
                     $router->add_route($http_method, $route, $data);
                 }
             }
         }
     }
     $data = null;
     $params = array();
     $router->select_route($method, $data, $params);
     if (is_array($data) && array_key_exists('output_handler_param', $data)) {
         $handler_param = $data['output_handler_param'];
     } else {
         $handler_param = \veneer\app::get_default('output_handler_param');
     }
     if (is_array($data) && array_key_exists('output_handler', $data)) {
         $default_handler = $data['output_handler'];
     } else {
         $default_handler = \veneer\app::get_default('output_handler');
     }
     $this->response->configure_handler($handler_param, $default_handler, $this->request_params);
     $params = array_merge($this->request_params, $params);
     if ($fn = self::validate($data, $params)) {
         if (method_exists($this, $fn)) {
             call_user_func(array($this, $fn), $params);
         }
     }
     if (!$this->response->is_set()) {
         if ($request_method == 'options') {
             $this->response->set($this->retrieve_detail(), 200);
         } else {
             $this->response->set('Incomplete response data returned by endpoint', 500);
         }
     }
 }