Optimize code order

This commit is contained in:
Dennis Eichhorn 2017-09-18 18:46:23 +02:00
parent 57a93bd60a
commit 417a42b455
4 changed files with 95 additions and 96 deletions

View File

@ -70,6 +70,29 @@ abstract class HeaderAbstract
$this->l11n = new Localization();
}
/**
* Set header locked.
*
* @since 1.0.0
*/
public static function lock() /* : void */
{
// todo: maybe pass session as member and make lock not static
self::$isLocked = true;
}
/**
* Is header locked?
*
* @return bool
*
* @since 1.0.0
*/
public static function isLocked() : bool
{
return self::$isLocked;
}
/**
* Get Localization
*
@ -81,7 +104,7 @@ abstract class HeaderAbstract
{
return $this->l11n;
}
/**
* Set localization
*
@ -121,7 +144,6 @@ abstract class HeaderAbstract
{
$this->account = $account;
}
/**
* Set status code
@ -138,6 +160,15 @@ abstract class HeaderAbstract
$this->generate($status);
}
/**
* Generate header based on status code.
*
* @param int $statusCode Status code
*
* @since 1.0.0
*/
abstract public function generate(int $statusCode) /* : void */;
/**
* Get status code
*
@ -149,7 +180,7 @@ abstract class HeaderAbstract
{
return $this->status;
}
/**
* Get protocol version.
*
@ -170,15 +201,6 @@ abstract class HeaderAbstract
*/
abstract public function set(string $key, string $value, bool $overwrite = false);
/**
* Generate header based on status code.
*
* @param int $statusCode Status code
*
* @since 1.0.0
*/
abstract public function generate(int $statusCode) /* : void */;
/**
* Get header by key.
*
@ -200,27 +222,4 @@ abstract class HeaderAbstract
* @since 1.0.0
*/
abstract public function has(string $key) : bool;
/**
* Set header locked.
*
* @since 1.0.0
*/
public static function lock() /* : void */
{
// todo: maybe pass session as member and make lock not static
self::$isLocked = true;
}
/**
* Is header locked?
*
* @return bool
*
* @since 1.0.0
*/
public static function isLocked() : bool
{
return self::$isLocked;
}
}

View File

@ -92,14 +92,6 @@ class Header extends HeaderAbstract
return true;
}
/**
* {@inheritdoc}
*/
public function getProtocolVersion() : string
{
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
}
/**
* Is security header.
*
@ -117,6 +109,14 @@ class Header extends HeaderAbstract
|| $key === 'x-frame-options';
}
/**
* {@inheritdoc}
*/
public function getProtocolVersion() : string
{
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
}
/**
* Get status code.
*
@ -194,6 +194,14 @@ class Header extends HeaderAbstract
return false;
}
/**
* {@inheritdoc}
*/
public function getReasonPhrase() : string
{
return $this->get('Status');
}
/**
* Get header by name.
*
@ -208,14 +216,6 @@ class Header extends HeaderAbstract
return $this->header[strtolower($key)] ?? [];
}
/**
* {@inheritdoc}
*/
public function getReasonPhrase() : string
{
return $this->get('Status');
}
/**
* Check if header is defined.
*
@ -339,12 +339,12 @@ class Header extends HeaderAbstract
*
* @since 1.0.0
*/
private function generate500() /* : void */
private function generate503() /* : void */
{
$this->set('HTTP', 'HTTP/1.0 500 Internal Server Error');
$this->set('Status', 'Status: 500 Internal Server Error');
$this->set('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
$this->set('Status', 'Status: 503 Service Temporarily Unavailable');
$this->set('Retry-After', 'Retry-After: 300');
\http_response_code(500);
\http_response_code(503);
}
/**
@ -354,11 +354,11 @@ class Header extends HeaderAbstract
*
* @since 1.0.0
*/
private function generate503() /* : void */
private function generate500() /* : void */
{
$this->set('HTTP', 'HTTP/1.0 503 Service Temporarily Unavailable');
$this->set('Status', 'Status: 503 Service Temporarily Unavailable');
$this->set('HTTP', 'HTTP/1.0 500 Internal Server Error');
$this->set('Status', 'Status: 500 Internal Server Error');
$this->set('Retry-After', 'Retry-After: 300');
\http_response_code(503);
\http_response_code(500);
}
}

View File

@ -83,29 +83,6 @@ class Request extends RequestAbstract
$this->init();
}
/**
* Create request from super globals.
*
* @param Localization $l11n Localization
*
* @return Request
*
* @since 1.0.0
*/
public static function createFromSuperglobals(Localization $l11n = null) : Request
{
return new self($l11n);
}
/**
* {@inheritdoc}
*/
public function setUri(UriInterface $uri) /* : void */
{
$this->uri = $uri;
$this->data += $uri->getQueryArray();
}
/**
* Init request.
*
@ -213,6 +190,29 @@ class Request extends RequestAbstract
}
}
/**
* Create request from super globals.
*
* @param Localization $l11n Localization
*
* @return Request
*
* @since 1.0.0
*/
public static function createFromSuperglobals(Localization $l11n = null) : Request
{
return new self($l11n);
}
/**
* {@inheritdoc}
*/
public function setUri(UriInterface $uri) /* : void */
{
$this->uri = $uri;
$this->data += $uri->getQueryArray();
}
/**
* Create request hashs of current request
*

View File

@ -278,6 +278,20 @@ class Http implements UriInterface
return $this->path . (!empty($query) ? '?' . $this->getQuery() : '');
}
/**
* {@inheritdoc}
*/
public function getQuery(string $key = null) /* : ?string */
{
if(isset($key)) {
$key = strtolower($key);
return $this->query[$key] ?? '';
}
return $this->queryString;
}
/**
* {@inheritdoc}
*/
@ -294,20 +308,6 @@ class Http implements UriInterface
return explode('/', $this->path);
}
/**
* {@inheritdoc}
*/
public function getQuery(string $key = null) /* : ?string */
{
if(isset($key)) {
$key = strtolower($key);
return $this->query[$key] ?? '';
}
return $this->queryString;
}
/**
* {@inheritdoc}
*/