From 475b52e67cffbf5ce75b367a62b535d079fb8822 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 9 May 2023 16:07:44 +0000 Subject: [PATCH] fixes --- .../Connection/PostgresConnection.php | 1 - .../Database/Connection/SQLiteConnection.php | 1 - .../Connection/SqlServerConnection.php | 1 - Localization/Defaults/Country.php | 20 -------- Localization/Defaults/CountryMapper.php | 1 - Localization/Defaults/localization.sqlite | Bin 24178688 -> 24178688 bytes Localization/NullBaseStringL11nType.php | 47 ++++++++++++++++++ Message/Http/HttpHeader.php | 26 ++++++++-- Message/Http/HttpRequest.php | 3 ++ Message/Http/HttpResponse.php | 14 ++++-- Utils/ArrayUtils.php | 24 +++++++++ 11 files changed, 105 insertions(+), 33 deletions(-) create mode 100644 Localization/NullBaseStringL11nType.php diff --git a/DataStorage/Database/Connection/PostgresConnection.php b/DataStorage/Database/Connection/PostgresConnection.php index cb0818377..928c6b9c9 100755 --- a/DataStorage/Database/Connection/PostgresConnection.php +++ b/DataStorage/Database/Connection/PostgresConnection.php @@ -16,7 +16,6 @@ namespace phpOMS\DataStorage\Database\Connection; use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; use phpOMS\DataStorage\Database\Query\Grammar\PostgresGrammar; use phpOMS\DataStorage\Database\Schema\Grammar\PostgresGrammar as PostgresSchemaGrammar; diff --git a/DataStorage/Database/Connection/SQLiteConnection.php b/DataStorage/Database/Connection/SQLiteConnection.php index 0d1ddc241..81ed53a92 100755 --- a/DataStorage/Database/Connection/SQLiteConnection.php +++ b/DataStorage/Database/Connection/SQLiteConnection.php @@ -16,7 +16,6 @@ namespace phpOMS\DataStorage\Database\Connection; use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; use phpOMS\DataStorage\Database\Query\Grammar\SQLiteGrammar; use phpOMS\DataStorage\Database\Schema\Grammar\SQLiteGrammar as SQLiteSchemaGrammar; diff --git a/DataStorage/Database/Connection/SqlServerConnection.php b/DataStorage/Database/Connection/SqlServerConnection.php index 6daeee484..91f54535d 100755 --- a/DataStorage/Database/Connection/SqlServerConnection.php +++ b/DataStorage/Database/Connection/SqlServerConnection.php @@ -16,7 +16,6 @@ namespace phpOMS\DataStorage\Database\Connection; use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; use phpOMS\DataStorage\Database\Query\Grammar\SqlServerGrammar; use phpOMS\DataStorage\Database\Schema\Grammar\SqlServerGrammar as SqlServerSchemaGrammar; diff --git a/Localization/Defaults/Country.php b/Localization/Defaults/Country.php index e6a20fd54..204c118b8 100755 --- a/Localization/Defaults/Country.php +++ b/Localization/Defaults/Country.php @@ -72,14 +72,6 @@ class Country */ protected string $subdevision = ''; - /** - * Country region. - * - * @var string - * @since 1.0.0 - */ - protected string $region = ''; - /** * Country developed. * @@ -160,18 +152,6 @@ class Country return $this->subdevision; } - /** - * Get country region - * - * @return string - * - * @since 1.0.0 - */ - public function getRegion() : string - { - return $this->region; - } - /** * Is country developed * diff --git a/Localization/Defaults/CountryMapper.php b/Localization/Defaults/CountryMapper.php index 851d24d57..388bd6a30 100755 --- a/Localization/Defaults/CountryMapper.php +++ b/Localization/Defaults/CountryMapper.php @@ -41,7 +41,6 @@ class CountryMapper extends DataMapperFactory 'country_code2' => ['name' => 'country_code2', 'type' => 'string', 'internal' => 'code2'], 'country_code3' => ['name' => 'country_code3', 'type' => 'string', 'internal' => 'code3'], 'country_numeric' => ['name' => 'country_numeric', 'type' => 'int', 'internal' => 'numeric'], - 'country_region' => ['name' => 'country_region', 'type' => 'string', 'internal' => 'region'], 'country_developed' => ['name' => 'country_developed', 'type' => 'bool', 'internal' => 'isDeveloped'], ]; diff --git a/Localization/Defaults/localization.sqlite b/Localization/Defaults/localization.sql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IEXdW%1WweUc(I(nPyJ#OB zqGNQ5&e0|IimuTux<`-b8NH%+^ohRFFZ#!T7#M?Ma14o|F)W71h!`28Vswm&u`w>j z$Ap*|lVWmAiK#IyrpMkfBWA{|m>qLsZp@4Mu^{&R-zWBsg|S~Oip8-cmd3JJ9xDpl lSy>oVRC4UhuD!Z$+FG=-kgVF1)qAq0uw!e{+QOV&{{x>f^a=m~ diff --git a/Localization/NullBaseStringL11nType.php b/Localization/NullBaseStringL11nType.php new file mode 100644 index 000000000..516bdc1c8 --- /dev/null +++ b/Localization/NullBaseStringL11nType.php @@ -0,0 +1,47 @@ +id = $id; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() : mixed + { + return ['id' => $this->id]; + } +} diff --git a/Message/Http/HttpHeader.php b/Message/Http/HttpHeader.php index a97f34ffd..44511e282 100755 --- a/Message/Http/HttpHeader.php +++ b/Message/Http/HttpHeader.php @@ -53,6 +53,11 @@ final class HttpHeader extends HeaderAbstract */ public int $status = RequestStatusCode::R_200; + public function initCurrentRequest() : void + { + $this->header = self::getAllHeaders(); + } + /** * {@inheritdoc} */ @@ -159,16 +164,29 @@ final class HttpHeader extends HeaderAbstract \str_replace( ' ', '-', - \ucwords( - \strtolower( - \str_replace('_', ' ', \substr($name, 5)) - ) + \strtolower( + \str_replace('_', ' ', \substr($name, 5)) ) ) ] = $value; } } + $temp = []; + foreach (self::$serverHeaders as $key => $value) { + $key = \strtolower($key); + if (!isset($temp[$key])) { + $temp[$key] = []; + } + + $values = \explode(',', $value); + foreach ($values as $val) { + $temp[$key][] = \trim($val); + } + } + + self::$serverHeaders = $temp; + return self::$serverHeaders; } diff --git a/Message/Http/HttpRequest.php b/Message/Http/HttpRequest.php index 322395dda..d9c112bc4 100755 --- a/Message/Http/HttpRequest.php +++ b/Message/Http/HttpRequest.php @@ -32,6 +32,8 @@ use phpOMS\Uri\UriInterface; * @since 1.0.0 * * @SuppressWarnings(PHPMD.Superglobals) + * + * @property HttpHeader $header */ final class HttpRequest extends RequestAbstract { @@ -112,6 +114,7 @@ final class HttpRequest extends RequestAbstract $this->uri = HttpUri::fromCurrent(); $this->data = $_POST + $_GET; $this->files = $_FILES; + $this->header->initCurrentRequest(); $this->header->l11n->setLanguage($this->getRequestLanguage()); $this->header->l11n->setCountry($this->getRequestCountry()); diff --git a/Message/Http/HttpResponse.php b/Message/Http/HttpResponse.php index 52a961ec0..3139b418b 100755 --- a/Message/Http/HttpResponse.php +++ b/Message/Http/HttpResponse.php @@ -19,6 +19,7 @@ use phpOMS\Localization\Localization; use phpOMS\Log\FileLogger; use phpOMS\Message\ResponseAbstract; use phpOMS\System\MimeType; +use phpOMS\Utils\ArrayUtils; use phpOMS\Utils\StringUtils; use phpOMS\Views\View; @@ -114,15 +115,18 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface foreach ($types as $type) { if (\stripos($type, MimeType::M_JSON) !== false) { return (string) \json_encode($this->jsonSerialize()); + } elseif (\stripos($type, MimeType::M_CSV) !== false) { + return ArrayUtils::arrayToCsv($this->toArray()); + } elseif (\stripos($type, MimeType::M_XML) !== false) { + return ArrayUtils::arrayToXml($this->toArray()); + } elseif (\stripos($type, MimeType::M_HTML) !== false) { + /** @var array{0:bool} $data */ + return $this->getRaw($data[0] ?? false); } } /** @var array{0:bool} $data */ - return $this->getRaw( - \stripos($type ?? '', MimeType::M_HTML) !== false - ? ($data[0] ?? false) - : false - ); + return $this->getRaw($data[0] ?? false); } /** diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 7ad4b3340..e5ce8ebe3 100755 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -269,6 +269,30 @@ final class ArrayUtils return $csv === false ? '' : $csv; } + /** + * Convert array to xml string. + * + * @param array $data Data to convert + * @param \SimpleXMLElement $xml XML parent + * + * @return string + * + * @since 1.0.0 + */ + public static function arrayToXml(array $data, \SimpleXMLElement $xml = null) : string + { + $xml ??= new \SimpleXMLElement(''); + + foreach ($data as $key => $value) { + if (is_array($value)) { + self::arrayToXml($value, $xml->addChild($key)); + } else { + $xml->addChild($key, \htmlspecialchars($value)); + } + } + return $xml->asXML(); + } + /** * Get array value by argument id. *