many small fixes

This commit is contained in:
Dennis Eichhorn 2023-02-10 18:20:57 +01:00
parent df4611731f
commit bbbeee84e1
16 changed files with 285 additions and 100 deletions

View File

@ -389,10 +389,10 @@ final class ReadMapper extends DataMapperAbstract
)
)
*/
$where1 = new Where($query->db);
$where1 = new Where($this->db);
$where1->where($this->mapper::TABLE . '_d' . $this->depth . '.' . $col, $comparison, $where['value'], 'and');
$where2 = new Builder($query->db);
$where2 = new Builder($this->db);
$where2->select('1')
->from($this->mapper::TABLE . '_d' . $this->depth)
->where($this->mapper::TABLE . '_d' . $this->depth . '.' . $col, 'in', $alt);

View File

@ -160,7 +160,7 @@ final class WriteMapper extends DataMapperAbstract
}
try {
$sth = $this->db->con->prepare($query->toSql());
$sth = $this->db->con->prepare($a = $query->toSql());
$sth->execute();
} catch (\Throwable $t) {
// @codeCoverageIgnoreStart

View File

@ -1395,7 +1395,7 @@ class Builder extends BuilderAbstract
$sth = null;
try {
$sth = $this->connection->con->prepare($this->toSql());
$sth = $this->connection->con->prepare($a = $this->toSql());
if ($sth === false) {
return null;
}

View File

@ -349,6 +349,7 @@ final class EventManager implements \Countable
{
if (isset($this->callbacks[$group])) {
unset($this->callbacks[$group]);
return true;
}
@ -368,6 +369,7 @@ final class EventManager implements \Countable
{
if (isset($this->groups[$group])) {
unset($this->groups[$group]);
return true;
}

View File

@ -525,4 +525,6 @@ class ISO3166CharEnum extends Enum
public const _ZWE = 'ZWE';
public const _XXX = 'XXX';
use ISO3166RegionTrait;
}

View File

@ -452,7 +452,7 @@ class ISO3166NameEnum extends Enum
public const _SJM = 'Svalbard and Jan Mayen';
public const _SWZ = 'Swaziland';
public const _SWZ = 'Eswatini';
public const _SWE = 'Sweden';

View File

@ -525,4 +525,6 @@ class ISO3166NumEnum extends Enum
public const _ZWE = '716';
public const _XXX = '000';
use ISO3166RegionTrait;
}

View File

@ -0,0 +1,216 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package phpOMS\Localization
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\Localization;
trait ISO3166RegionTrait
{
public static function getRegion(string $region) : array
{
$region = \strtolower($region);
switch ($region) {
case 'europe':
return \array_merge(
self::getRegion('north-europe'),
self::getRegion('south-europe'),
self::getRegion('east-europe'),
self::getRegion('west-europe')
);
case 'asia':
return \array_merge(
self::getRegion('central-asia'),
self::getRegion('south-asia'),
self::getRegion('southeast-asia'),
self::getRegion('east-asia'),
self::getRegion('west-asia')
);
case 'america':
return \array_merge(
self::getRegion('north-america'),
self::getRegion('south-america'),
self::getRegion('central-america'),
self::getRegion('caribbean')
);
case 'oceania':
return \array_merge(
self::getRegion('australia'),
self::getRegion('polynesia'),
self::getRegion('melanesia'),
self::getRegion('micronesia'),
self::getRegion('antartica')
);
case 'africa':
return \array_merge(
self::getRegion('north-africa'),
self::getRegion('south-africa'),
self::getRegion('east-africa'),
self::getRegion('west-africa'),
self::getRegion('central-africa')
);
case 'eu':
return [
self::_AUT, self::_BEL, self::_BGR, self::_HRV, self::_CYP,
self::_CZE, self::_DNK, self::_EST, self::_FIN, self::_FRA,
self::_DEU, self::_GRC, self::_HUN, self::_IRL, self::_ITA,
self::_LVA, self::_LTU, self::_LUX, self::_MLT, self::_NLD,
self::_POL, self::_PRT, self::_ROU, self::_SVK, self::_SVN,
self::_ESP, self::_SWE,
];
case 'euro':
return [
self::_AUT, self::_BEL, self::_HRV, self::_CYP, self::_EST,
self::_FIN, self::_FRA, self::_DEU, self::_GRC, self::_IRL,
self::_ITA, self::_LVA, self::_LTU, self::_LUX, self::_MLT,
self::_NLD, self::_PRT, self::_SVK, self::_SVN, self::_ESP,
];
case 'north-europe':
return [
self::_ALA, self::_DNK, self::_EST, self::_FRO, self::_FIN,
self::_GGY, self::_ISL, self::_IRL, self::_IMN, self::_JEY,
self::_LVA, self::_LTU, self::_NOR, self::_SJM, self::_SWE,
self::_GBR,
];
case 'south-europe':
return [
self::_ALB, self::_AND, self::_BIH, self::_HRV, self::_GIB,
self::_GRC, self::_ITA, self::_XKK, self::_MLT, self::_MNE,
self::_MKD, self::_PRT, self::_SMR, self::_SRB, self::_SVN,
self::_ESP, self::_VAT,
];
case 'east-europe':
return [
self::_BLR, self::_BGR, self::_CZE, self::_HUN, self::_MDA,
self::_POL, self::_ROU, self::_RUS, self::_SVK, self::_UKR,
];
case 'west-europe':
return [
self::_AUT, self::_BEL, self::_FRA, self::_DEU, self::_LIE,
self::_LUX, self::_NLD, self::_MCO, self::_CHE
];
case 'middle-east':
return [
self::_BHR, self::_CYP, self::_EGY, self::_IRN, self::_IRQ,
self::_ISR, self::_JOR, self::_KWT, self::_LBN, self::_OMN,
self::_PSE, self::_QAT, self::_SAU, self::_SYR, self::_TUR,
self::_ARE, self::_YEM,
];
case 'south-america':
return [
self::_ARG, self::_BOL, self::_BVT, self::_BRA, self::_CHL,
self::_COL, self::_ECU, self::_FLK, self::_GUF, self::_GUY,
self::_PRY, self::_PER, self::_SGS, self::_SUR, self::_URY,
self::_VEN,
];
case 'north-america':
return [
self::_BMU, self::_CAN, self::_GRL, self::_SPM, self::_USA,
];
case 'central-america':
return [
self::_BLZ, self::_CRI, self::_SLV, self::_HND, self::_MEX,
self::_NIC, self::_PAN, self::_GTM,
];
case 'caribbean':
return [
self::_ATG, self::_ABW, self::_BHS, self::_BRB, self::_VGB,
self::_CYM, self::_CUB, self::_CUW, self::_DMA, self::_VIR,
self::_DOM, self::_GRD, self::_GLP, self::_HTI, self::_JAM,
self::_MTQ, self::_MSR, self::_PRI, self::_BLM, self::_KNA,
self::_LCA, self::_MAF, self::_SXM, self::_VCT, self::_TTO,
self::_TCA, self::_AIA, self::_BES,
];
case 'central-asia':
return [
self::_KAZ, self::_KGZ, self::_TJK, self::_TKM, self::_UZB,
];
case 'south-asia':
return [
self::_AFG, self::_BGD, self::_BTN, self::_IND, self::_IRN,
self::_MDV, self::_NPL, self::_PAK, self::_LKA,
];
case 'southeast-asia':
return [
self::_BRN, self::_KHM, self::_TLS, self::_IDN, self::_LAO,
self::_MYS, self::_MMR, self::_PHL, self::_SGP, self::_THA,
self::_VNM,
];
case 'east-asia':
return [
self::_CHN, self::_HKG, self::_JPN, self::_MAC, self::_MNG,
self::_KOR, self::_PRK, self::_TWN,
];
case 'west-asia':
return [
self::_ARM, self::_AZE, self::_BHR, self::_CYP, self::_GEO,
self::_IRQ, self::_ISR, self::_JOR, self::_KWT, self::_LBN,
self::_OMN, self::_PSE, self::_QAT, self::_SAU, self::_SYR,
self::_TUR, self::_ARE, self::_YEM,
];
case 'central-africa':
return [
self::_AGO, self::_CMR, self::_CAF, self::_TCD, self::_COD,
self::_GNQ, self::_GAB, self::_COG, self::_STP,
];
case 'south-africa':
return [
self::_BWA, self::_SWZ, self::_LSO, self::_NAM, self::_ZAF,
];
case 'north-africa':
return [
self::_DZA, self::_EGY, self::_LBY, self::_MAR, self::_SSD,
self::_SDN, self::_TUN, self::_ESH,
];
case 'east-africa':
return [
self::_IOT, self::_BDI, self::_COM, self::_DJI, self::_ERI,
self::_ETH, self::_KEN, self::_MDG, self::_MWI, self::_MUS,
self::_MYT, self::_MOZ, self::_RWA, self::_SYC, self::_SOM,
self::_TZA, self::_UGA, self::_ZMB, self::_ZWE, self::_REU,
];
case 'west-africa':
return [
self::_BEN, self::_BFA, self::_CPV, self::_GMB, self::_GHA,
self::_GIN, self::_GNB, self::_CIV, self::_LBR, self::_MLI,
self::_MRT, self::_NER, self::_NGA, self::_SHN, self::_SEN,
self::_SLE, self::_TGO,
];
case 'australia':
return [
self::_AUS, self::_CXR, self::_CCK, self::_HMD, self::_NZL,
self::_NFK,
];
case 'polynesia':
return [
self::_WSM, self::_COK, self::_PYF, self::_NIU, self::_PCN,
self::_WSM, self::_TKL, self::_TON, self::_TUV, self::_WLF,
];
case 'melanesia':
return [
self::_FJI, self::_NCL, self::_PNG, self::_SLB, self::_VUT,
];
case 'micronesia':
return [
self::_FSM, self::_GUM, self::_KIR, self::_MHL, self::_NRU,
self::_MNP, self::_PLW, self::_UMI,
];
case 'antarctica':
return [
self::_ATA, self::_ATF,
];
default:
return [];
}
}
}

View File

@ -527,4 +527,6 @@ class ISO3166TwoEnum extends Enum
public const _XKK = 'XK';
public const _XXX = 'XX';
use ISO3166RegionTrait;
}

View File

@ -32,7 +32,7 @@ final class Money extends FloatInt
* @var int
* @since 1.0.0
*/
private int $position = 1;
private int $position = 0;
/**
* Currency symbol.
@ -53,11 +53,8 @@ final class Money extends FloatInt
*
* @since 1.0.0
*/
public function __construct(int | float | string $value = 0, string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0)
public function __construct(int | float | string $value = 0, string $thousands = ',', string $decimal = '.')
{
$this->symbol = $symbol;
$this->position = $position;
parent::__construct($value, $thousands, $decimal);
}
@ -92,9 +89,11 @@ final class Money extends FloatInt
*
* @since 1.0.0
*/
public function getCurrency(?int $decimals = 2) : string
public function getCurrency(?int $decimals = 2, int $position = null, string $symbol = null) : string
{
return ($this->position === 0 && !empty($this->symbol) ? $this->symbol . ' ' : '') . $this->getAmount($decimals) . ($this->position === 1 ? ' ' . $this->symbol : '');
return (($position ?? $this->position) === 0 && !empty($symbol ?? $this->symbol) ? ($symbol ?? $this->symbol) . ' ' : '' )
. $this->getAmount($decimals)
. (($position ?? $this->position) === 1 && !empty($symbol ?? $this->symbol) ? ' ' . ($smbol ?? $this->symbol) : '');
}
/**

View File

@ -304,6 +304,23 @@ abstract class RequestAbstract implements MessageInterface
return $this->files;
}
public function getFile(string $name) : array
{
return $this->files[$name] ?? [];
}
/**
* Has files.
*
* @return bool
*
* @since 1.0.0
*/
public function hasFiles() : bool
{
return !empty($this->files);
}
/**
* Add file to request
*

View File

@ -40,7 +40,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var string
* @since 1.0.0
*/
private string $title = '';
public string $title = '';
/**
* Message.
@ -48,7 +48,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var string
* @since 1.0.0
*/
private string $message = '';
public string $message = '';
/**
* Delay in ms.
@ -56,7 +56,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var int
* @since 1.0.0
*/
private int $delay = 0;
public int $delay = 0;
/**
* Stay in ms.
@ -64,7 +64,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var int
* @since 1.0.0
*/
private int $stay = 0;
public int $stay = 0;
/**
* Level or type.
@ -72,7 +72,7 @@ final class Notify implements \JsonSerializable, SerializableInterface
* @var int
* @since 1.0.0
*/
private int $level = NotifyType::INFO;
public string $level = NotifyType::INFO;
/**
* Constructor.
@ -82,82 +82,12 @@ final class Notify implements \JsonSerializable, SerializableInterface
*
* @since 1.0.0
*/
public function __construct(string $msg = '', int $level = NotifyType::INFO)
public function __construct(string $msg = '', string $level = NotifyType::INFO)
{
$this->message = $msg;
$this->level = $level;
}
/**
* Set delay.
*
* @param int $delay Delay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setDelay(int $delay) : void
{
$this->delay = $delay;
}
/**
* Set delay.
*
* @param int $stay Stay in ms
*
* @return void
*
* @since 1.0.0
*/
public function setStay(int $stay) : void
{
$this->stay = $stay;
}
/**
* Set title.
*
* @param string $title Title
*
* @return void
*
* @since 1.0.0
*/
public function setTitle(string $title) : void
{
$this->title = $title;
}
/**
* Set message.
*
* @param string $message Message
*
* @return void
*
* @since 1.0.0
*/
public function setMessage(string $message) : void
{
$this->message = $message;
}
/**
* Set level/type.
*
* @param int $level Notification type/level
*
* @return void
*
* @since 1.0.0
*/
public function setLevel(int $level) : void
{
$this->level = $level;
}
/**
* Render message.
*

View File

@ -26,13 +26,17 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class NotifyType extends Enum
{
public const BINARY = 0;
public const BINARY = 'binary';
public const INFO = 1;
public const OK = 'ok';
public const WARNING = 2;
public const INFO = 'info';
public const ERROR = 3;
public const WARNING = 'warning';
public const FATAL = 4;
public const ERROR = 'error';
public const FATAL = 'fatal';
public const HIDDEN = 'hidden';
}

View File

@ -340,7 +340,9 @@ abstract class ModuleAbstract
*/
protected function updateModel(int $account, mixed $old, mixed $new, string | \Closure $mapper, string $trigger, string $ip) : void
{
$this->app->eventManager->triggerSimilar('PRE:Module:' . static::NAME . '-' . $trigger . '-update', '', $old);
$trigger = static::NAME . '-' . $trigger . '-update';
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $old);
$id = 0;
if (\is_string($mapper)) {
@ -349,7 +351,7 @@ abstract class ModuleAbstract
$mapper();
}
$this->app->eventManager->triggerSimilar('POST:Module:' . static::NAME . '-' . $trigger . '-update', '',
$this->app->eventManager->triggerSimilar('POST:Module:' . $trigger, '',
[
$account,
$old, $new,
@ -405,7 +407,7 @@ abstract class ModuleAbstract
* Create a model relation
*
* @param int $account Account id
* @param mixed $rel1 Object relation1
* @param mixed $rel1 Object relation1 (parent object)
* @param mixed $rel2 Object relation2
* @param string $mapper Object mapper
* @param string $field Relation field
@ -416,7 +418,15 @@ abstract class ModuleAbstract
*
* @since 1.0.0
*/
protected function createModelRelation(int $account, mixed $rel1, mixed $rel2, string $mapper, string $field, string $trigger, string $ip) : void
protected function createModelRelation(
int $account,
mixed $rel1,
mixed $rel2,
string $mapper,
string $field,
string $trigger,
string $ip
) : void
{
$trigger = static::NAME . '-' . $trigger . '-relation-create';

View File

@ -92,7 +92,8 @@ final class PhpCode
*/
public static function hasUnicode(string $source) : bool
{
return (bool) \preg_match('/[^\x00-\x7f]/', $source);
return ((bool) \preg_match("/[\x00-\x7f]/", $source))
|| ((bool) \preg_match('/(0|\\)x([a-fA-F0-9]){2}/', $source));
}
/**

View File

@ -296,11 +296,11 @@ abstract class ViewAbstract implements RenderableInterface
if ($this->isBuffered) {
--$obLevel;
$ob = (string) \ob_get_clean();
$ob .= (string) \ob_get_clean();
}
if (\is_array($includeData)) {
$ob = (string) \json_encode($includeData);
$ob .= (string) \json_encode($includeData);
}
} catch (\Throwable $e) {
if ($obLevel > 0 && $this->isBuffered) {