Habari\Utils::check_request_method PHP Méthode

check_request_method() public static méthode

Checks whether the correct HTTP method was used for the request
public static check_request_method ( array $expected )
$expected array Expected HTTP methods for the request
    public static function check_request_method($expected)
    {
        if (!in_array($_SERVER['REQUEST_METHOD'], $expected)) {
            if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD', 'POST', 'PUT', 'DELETE'))) {
                header('HTTP/1.1 405 Method Not Allowed', true, 405);
            } else {
                header('HTTP/1.1 501 Method Not Implemented', true, 501);
            }
            header('Allow: ' . implode(',', $expected));
            exit;
        }
    }

Usage Example

Exemple #1
0
 /**
  * Handle incoming requests for the Atom entry collection for comments on an entry
  */
 function act_entry_comments()
 {
     Utils::check_request_method(array('GET', 'HEAD', 'POST'));
     if (isset($this->handler_vars['slug'])) {
         $this->act_comments(array('slug' => $this->handler_vars['slug']));
     } else {
         $this->act_comments(array('id' => $this->handler_vars['id']));
     }
 }