API::cors PHP Method

cors() protected method

protected cors ( $verb = 'GET' )
    protected function cors($verb = 'GET')
    {
        if (isset($_SERVER['HTTP_ORIGIN'])) {
            header("Access-Control-Allow-Origin: *");
        }
        if ($this->verb == 'GET' || $this->verb == 'OPTIONS') {
            header("Access-Control-Expose-Headers: content-type, content-range, accept-range");
        }
        if ($this->verb == "OPTIONS") {
            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
                header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
            }
            if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
                header("Access-Control-Allow-Headers: " . "origin, content-type, accept, session-token, authorization");
            }
            exit(0);
        }
    }

Usage Example

Esempio n. 1
0
 public static function run()
 {
     API::cors();
     $authInfo = API::getAuth();
     $authUser = $authInfo['user'];
     $authPass = $authInfo['password'];
     $key = $authInfo['key'];
     $pathUri = join('?', array('/' . $authInfo['path'], $_SERVER['QUERY_STRING']));
     $method = strtolower($_SERVER['REQUEST_METHOD']);
     $client = new Redmine_Client(API::$url, $authUser, $authPass, $key);
     switch ($method) {
         case 'post':
             break;
         case 'put':
             break;
         case 'delete':
             break;
         default:
             echo $client->get($pathUri, false);
             break;
     }
 }