Scalr\Api\Rest\Application::run PHP Method

run() public method

Runs application
public run ( )
    public function run()
    {
        $this->response->setHeader('X-Scalr-Inittime', microtime(true) - $this->startTime);
        $this->call();
        $this->response->setHeader('X-Scalr-Actiontime', microtime(true) - $this->startTime);
        //Fetch status, header, and body
        list($status, $headers, $body) = $this->response->finalize();
        if (headers_sent() === false) {
            if (strpos(PHP_SAPI, 'cgi') === 0) {
                header(sprintf('Status: %s', Response::getCodeMessage($status)));
            } else {
                header(sprintf('HTTP/%s %s', '1.1', Response::getCodeMessage($status)));
            }
            @header_remove('X-Powered-By');
            if (isset($this->settings[static::SETTING_API_VERSION])) {
                $headers['X-Powered-By'] = sprintf("Scalr API/%s", $this->settings[static::SETTING_API_VERSION]);
            }
            //Send headers
            foreach ($headers as $name => $value) {
                //Normalizes the header name
                $name = implode('-', array_map(function ($v) {
                    return ucfirst(strtolower($v));
                }, preg_split('/[_-]/', $name)));
                $a = explode("\n", $value);
                if ($a) {
                    foreach ($a as $v) {
                        header("{$name}: {$v}", false);
                    }
                }
            }
        }
        if ($this->request->getMethod() !== Request::METHOD_HEAD) {
            echo $body;
        }
    }

Usage Example

Example #1
0
 /**
  * @test
  */
 public function testRun()
 {
     $this->app->run();
 }