/**
  * @covers ControllerRoute::setHeaders
  */
 public function testSetHeadersDetectsHttpVerb()
 {
     $this->route->setHeaders(array('X-Http-Method-Override' => 'post'));
     $this->assertEquals('POST', $this->route->getHttpVerb());
     $this->route->setHeaders(array('X-Http-Method' => 'GET'));
     $this->assertEquals('GET', $this->route->getHttpVerb());
 }
Exemple #2
0
 /**
  * @param string $action_name
  * @param array $args
  */
 function doAction($action_name = null, $args = array())
 {
     // todo: this probably belongs somewhere else
     if ($this->isRestful()) {
         $has_id = false;
         if ((string) (int) $action_name === (string) $action_name) {
             array_unshift($args, $action_name);
             $action_name = null;
             $has_id = true;
         }
         if (!$action_name) {
             switch ($this->route->getHttpVerb()) {
                 case 'POST':
                 case 'PUT':
                     $action_name = 'save';
                     break;
                 case 'GET':
                     if ($has_id) {
                         $action_name = 'show';
                     }
                     break;
                 case 'DELETE':
                     if ($has_id) {
                         $action_name = 'delete';
                     }
                     break;
             }
         }
     }
     if (!$action_name) {
         $action_name = DEFAULT_CONTROLLER;
     }
     $method_name = str_replace(array('-', '_', ' '), '', $action_name);
     $view = $this->getView($action_name);
     if (!is_array($args) && !$args instanceof ArrayObject) {
         $args = array($args);
     }
     if (!method_exists($this, $method_name) && !method_exists($this, '__call') || strpos($action_name, '_') === 0) {
         file_not_found($view);
     }
     $result = call_user_func_array(array($this, $method_name), $args);
     if (!$this->loadView) {
         return;
     }
     if ($this->isRestful()) {
         $this->loadView($view, $result);
     } else {
         $this->loadView($view);
     }
 }