From bbbeee84e11e5d70eb0cf0ea45e6087a7bd285a7 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 10 Feb 2023 18:20:57 +0100 Subject: [PATCH] many small fixes --- DataStorage/Database/Mapper/ReadMapper.php | 4 +- DataStorage/Database/Mapper/WriteMapper.php | 2 +- DataStorage/Database/Query/Builder.php | 2 +- Event/EventManager.php | 2 + Localization/ISO3166CharEnum.php | 2 + Localization/ISO3166NameEnum.php | 2 +- Localization/ISO3166NumEnum.php | 2 + Localization/ISO3166RegionTrait.php | 216 ++++++++++++++++++++ Localization/ISO3166TwoEnum.php | 2 + Localization/Money.php | 13 +- Message/RequestAbstract.php | 17 ++ Model/Message/Notify.php | 82 +------- Model/Message/NotifyType.php | 14 +- Module/ModuleAbstract.php | 18 +- Security/PhpCode.php | 3 +- Views/ViewAbstract.php | 4 +- 16 files changed, 285 insertions(+), 100 deletions(-) create mode 100644 Localization/ISO3166RegionTrait.php diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 684483a11..e281ebd3d 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -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); diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 14d16799c..7388506e6 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -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 diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 13ecdbf45..3cc10f24e 100755 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -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; } diff --git a/Event/EventManager.php b/Event/EventManager.php index 24d8fee10..6e746d96e 100755 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -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; } diff --git a/Localization/ISO3166CharEnum.php b/Localization/ISO3166CharEnum.php index d27d1cac6..d4c06c252 100755 --- a/Localization/ISO3166CharEnum.php +++ b/Localization/ISO3166CharEnum.php @@ -525,4 +525,6 @@ class ISO3166CharEnum extends Enum public const _ZWE = 'ZWE'; public const _XXX = 'XXX'; + + use ISO3166RegionTrait; } diff --git a/Localization/ISO3166NameEnum.php b/Localization/ISO3166NameEnum.php index cd7e3d260..bd9992fe8 100755 --- a/Localization/ISO3166NameEnum.php +++ b/Localization/ISO3166NameEnum.php @@ -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'; diff --git a/Localization/ISO3166NumEnum.php b/Localization/ISO3166NumEnum.php index 423373486..fae1664bd 100755 --- a/Localization/ISO3166NumEnum.php +++ b/Localization/ISO3166NumEnum.php @@ -525,4 +525,6 @@ class ISO3166NumEnum extends Enum public const _ZWE = '716'; public const _XXX = '000'; + + use ISO3166RegionTrait; } diff --git a/Localization/ISO3166RegionTrait.php b/Localization/ISO3166RegionTrait.php new file mode 100644 index 000000000..009637d3b --- /dev/null +++ b/Localization/ISO3166RegionTrait.php @@ -0,0 +1,216 @@ +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) : ''); } /** diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index c58fbab6a..20a2b8f00 100755 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -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 * diff --git a/Model/Message/Notify.php b/Model/Message/Notify.php index 0272648ce..a27de8b2f 100755 --- a/Model/Message/Notify.php +++ b/Model/Message/Notify.php @@ -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. * diff --git a/Model/Message/NotifyType.php b/Model/Message/NotifyType.php index d70406df8..657334fb6 100755 --- a/Model/Message/NotifyType.php +++ b/Model/Message/NotifyType.php @@ -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'; } diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index a325ad7b7..cf19985be 100755 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -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'; diff --git a/Security/PhpCode.php b/Security/PhpCode.php index 58b0d5810..9aaacb38d 100755 --- a/Security/PhpCode.php +++ b/Security/PhpCode.php @@ -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)); } /** diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 14a1e4aba..a977a9014 100755 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -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) {