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.sqlite index 224ec7e30..a27865cd6 100755 Binary files a/Localization/Defaults/localization.sqlite and b/Localization/Defaults/localization.sqlite differ 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. *