diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index 066192afa..dfca67533 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -645,7 +645,7 @@ class FinanceFormulas * * @since 1.0.0 */ - public static function getCurrentRaio(float $assets, float $liabilities) : float + public static function getCurrentRatio(float $assets, float $liabilities) : float { return $assets / $liabilities; } diff --git a/Message/Http/Header.php b/Message/Http/Header.php index d668f2c60..9992e3c0c 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -117,7 +117,7 @@ class Header extends HeaderAbstract */ public static function getStatusCode() : int { - return http_response_code(); + return \http_response_code(); } /** @@ -129,7 +129,7 @@ class Header extends HeaderAbstract */ public function getHeaders() : array { - return getallheaders(); + return self::getAllHeaders(); } /** @@ -141,7 +141,30 @@ class Header extends HeaderAbstract */ public function getHeader(string $name) : string { - return getallheaders()[$name]; + return self::getAllHeaders()[$name] ?? ''; + } + + /** + * Get all headers for apache and nginx + * + * @return array + * + * @since 1.0.0 + */ + private static function getAllHeaders() : array + { + if (function_exists('getallheaders')) { + return getallheaders(); + } + + $headers = []; + foreach ($_SERVER as $name => $value) { + if (substr($name, 0, 5) == 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + + return $headers; } /** @@ -257,7 +280,7 @@ class Header extends HeaderAbstract { $this->set('HTTP', 'HTTP/1.0 403 Forbidden'); $this->set('Status', 'Status: HTTP/1.0 403 Forbidden'); - http_response_code(403); + \http_response_code(403); } /** @@ -271,7 +294,7 @@ class Header extends HeaderAbstract { $this->set('HTTP', 'HTTP/1.0 404 Not Found'); $this->set('Status', 'Status: HTTP/1.0 404 Not Found'); - http_response_code(404); + \http_response_code(404); } /** @@ -285,7 +308,7 @@ class Header extends HeaderAbstract { $this->set('HTTP', 'HTTP/1.0 406 Not acceptable'); $this->set('Status', 'Status: 406 Not acceptable'); - http_response_code(406); + \http_response_code(406); } /** @@ -312,7 +335,7 @@ class Header extends HeaderAbstract $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(500); + \http_response_code(500); } /** @@ -327,6 +350,6 @@ class Header extends HeaderAbstract $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(503); + \http_response_code(503); } } \ No newline at end of file diff --git a/Message/Http/Request.php b/Message/Http/Request.php index acac47d42..4505bded9 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -96,6 +96,16 @@ class Request extends RequestAbstract return new self($l11n); } + /** + * {@inheritdoc} + */ + public function setUri(UriInterface $uri) /* : void */ + { + $this->uri = $uri; + $this->path = explode('/', $this->uri->getPath()); + $this->data += $uri->getQueryArray(); + } + /** * Init request. * diff --git a/Message/Http/Response.php b/Message/Http/Response.php index 01302f027..37b1155fb 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -62,15 +62,13 @@ class Response extends ResponseAbstract implements RenderableInterface /** * Remove response by ID. * - * @param int $id Response ID + * @param mixed $id Response ID * * @return bool * - * @throws \Exception - * * @since 1.0.0 */ - public function remove(int $id) : bool + public function remove($id) : bool { if (isset($this->response[$id])) { unset($this->response[$id]); diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 5133b8204..855a80c6b 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -214,7 +214,7 @@ abstract class RequestAbstract implements MessageInterface public function setRequestSource(int $source) /* : void */ { if (!RequestSource::isValidValue($source)) { - throw new InvalidEnumValue($source); + throw new InvalidEnumValue((string) $source); } $this->source = $source; diff --git a/Message/ResponseAbstract.php b/Message/ResponseAbstract.php index b8692ef41..d5c402383 100644 --- a/Message/ResponseAbstract.php +++ b/Message/ResponseAbstract.php @@ -60,7 +60,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable * @var int * @since 1.0.0 */ - protected $account = null; + protected $account = 0; /** * Header. @@ -122,7 +122,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable * {@inheritdoc} * todo: shouldn't this only be available in the header?! */ - public function getStatusCode() : string + public function getStatusCode() : int { return $this->status; } diff --git a/Uri/Http.php b/Uri/Http.php index a7466bd77..406924df5 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -165,6 +165,8 @@ class Http implements UriInterface parse_str($this->queryString, $this->query); } + $this->query = array_change_key_case($this->query, CASE_LOWER); + $this->fragment = $url['fragment'] ?? ''; $this->base = $this->scheme . '://' . $this->host . $this->rootPath; } @@ -282,7 +284,21 @@ class Http implements UriInterface */ public function getQuery(string $key = null) /* : ?string */ { - return isset($key) ? $this->query[$key] ?? null : $this->queryString; + if(isset($key)) { + $key = strtolower($key); + + return $this->query[$key] ?? ''; + } + + return $this->queryString; + } + + /** + * {@inheritdoc} + */ + public function getQueryArray() : array + { + return $this->query; } /** diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 5c1a6d91d..d75f968dd 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -117,6 +117,11 @@ class UriFactory self::setQuery('/', $uri->getPath()); self::setQuery(':user', $uri->getUser()); self::setQuery(':pass', $uri->getPass()); + + $data = $uri->getQueryArray(); + foreach($data as $key => $value) { + self::setQuery('?' . $key, $value); + } } /** @@ -224,7 +229,7 @@ class UriFactory */ public static function build(string $uri, array $toMatch = []) /* : ?string */ { - $parsed = preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) { + $parsed = preg_replace_callback('(\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\})', function ($match) use ($toMatch) { $match = substr($match[0], 1, strlen($match[0]) - 2); return $toMatch[$match] ?? self::$uri[$match] ?? $match; diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 8c194509f..f5907c521 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -320,7 +320,7 @@ class ArrayUtils */ public static function arraySum(array $array, int $start = 0, int $count = 0) { - $count = $count === 0 ? count($array) : $count; + $count = $count === 0 ? count($array) : $start + $count; $sum = 0; $array = array_values($array); diff --git a/Utils/JsonBuilder.php b/Utils/JsonBuilder.php index e447e6a7f..dec4a70b2 100644 --- a/Utils/JsonBuilder.php +++ b/Utils/JsonBuilder.php @@ -108,11 +108,11 @@ class JsonBuilder implements \Serializable, \JsonSerializable */ public function unserialize($serialized) { - $this->json = json_decode($serialized); + $this->json = json_decode($serialized, true); } public function jsonSerialize() { - return $this->json(); + return $this->getJson(); } } diff --git a/Validation/ValidatorAbstract.php b/Validation/ValidatorAbstract.php index afc98b019..4f4ef5d85 100644 --- a/Validation/ValidatorAbstract.php +++ b/Validation/ValidatorAbstract.php @@ -58,4 +58,10 @@ abstract class ValidatorAbstract implements ValidatorInterface { return self::$error; } + + public static function resetError() /* : void */ + { + self::$error = 0; + self::$msg = ''; + } }