This commit is contained in:
Dennis Eichhorn 2023-05-09 16:07:44 +00:00
parent fafa6cd3cd
commit 475b52e67c
11 changed files with 105 additions and 33 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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
*

View File

@ -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'],
];

View File

@ -0,0 +1,47 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Localization
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\Localization;
/**
* Null model
*
* @package phpOMS\Localization
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullBaseStringL11nType extends BaseStringL11nType
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -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;
}

View File

@ -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());

View File

@ -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);
}
/**

View File

@ -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('<root/>');
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.
*