Source

Ray / Ray / Request.php

<?php

namespace Ray;

class Request{
    
    const METHOD_HEAD = 'HEAD';
    
    const METHOD_GET = 'GET';
    
    const METHOD_POST = 'POST';
    
    const METHOD_PUT = 'PUT';
    
    const METHOD_DELETE = 'DELETE';
    
    const METHOD_PATCH = 'PATCH';
    
    const METHOD_OPTIONS = 'OPTIONS';
    
    protected $additionalHeaders = array(
        'content-type', 'content-length', 'php-auth-user',
        'php-auth-pw', 'auth-type', 'x-requested-with'
    );
    
    private $request;
    
    public function __construct(){
        
        $headers = array();
        foreach ( $_SERVER as $key => $value ) {
            $key = $this->convertHeader($key);
            if ( strpos($key, 'http-') === 0 || in_array($key, $this->additionalHeaders) ) {
                $name = str_replace('http-', '', $key);
                $headers[$name] = $value;
            }
        }
        
        $this->request = (object) array(
            'host'    => $_SERVER['HTTP_HOST'],
            'method'  => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : self::METHOD_GET,
            'headers' => $headers,
            'uri'     => $_SERVER['PATH_INFO']
        );
        
    }

    protected function convertHeader( $name ) {
        return str_replace('_', '-', strtolower($name));
    }
    
    public function isAjax() {
        return ( isset($this->request->headers['X_REQUESTED_WITH']) &&
                $this->request->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest' );
    }
    
    public function getRequest(){
        return $this->request;
    }
    
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.