From 417a42b455f388fe0ec35835b1d958f86294f317 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 18 Sep 2017 18:46:23 +0200 Subject: [PATCH] Optimize code order --- Message/HeaderAbstract.php | 69 +++++++++++++++++++------------------- Message/Http/Header.php | 48 +++++++++++++------------- Message/Http/Request.php | 46 ++++++++++++------------- Uri/Http.php | 28 ++++++++-------- 4 files changed, 95 insertions(+), 96 deletions(-) diff --git a/Message/HeaderAbstract.php b/Message/HeaderAbstract.php index e3ede1c63..dc7881e8b 100644 --- a/Message/HeaderAbstract.php +++ b/Message/HeaderAbstract.php @@ -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; - } } diff --git a/Message/Http/Header.php b/Message/Http/Header.php index a8aa9a873..fb71aec8b 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -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); } } diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 086e2e7e3..a86dd49df 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -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 * diff --git a/Uri/Http.php b/Uri/Http.php index bc305030a..6dfbc0dce 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -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} */