rename module constants and fix some unit test bugs

This commit is contained in:
Dennis Eichhorn 2021-09-28 18:28:43 +02:00
parent d7e89a4a31
commit 79c91d9895
6 changed files with 33 additions and 30 deletions

View File

@ -38,7 +38,7 @@ abstract class ModuleAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODULE_NAME = ''; public const NAME = '';
/** /**
* Module path. * Module path.
@ -46,7 +46,7 @@ abstract class ModuleAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODULE_PATH = __DIR__ . '/../../Modules/'; public const PATH = __DIR__ . '/../../Modules/';
/** /**
* Module version. * Module version.
@ -54,7 +54,7 @@ abstract class ModuleAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODULE_VERSION = '1.0.0'; public const VERSION = '1.0.0';
/** /**
* Module id. * Module id.
@ -62,7 +62,7 @@ abstract class ModuleAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public const MODULE_ID = 0; public const ID = 0;
/** /**
* Receiving modules from? * Receiving modules from?
@ -121,7 +121,7 @@ abstract class ModuleAbstract
public static function getLocalization(string $language, string $destination) : array public static function getLocalization(string $language, string $destination) : array
{ {
$lang = []; $lang = [];
if (\is_file($oldPath = self::MODULE_PATH . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) { if (\is_file($oldPath = self::PATH . static::NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
/** @noinspection PhpIncludeInspection */ /** @noinspection PhpIncludeInspection */
return include $oldPath; return include $oldPath;
} }
@ -179,7 +179,7 @@ abstract class ModuleAbstract
public function getName() : string public function getName() : string
{ {
/** @noinspection PhpUndefinedFieldInspection */ /** @noinspection PhpUndefinedFieldInspection */
return static::MODULE_NAME; return static::NAME;
} }
/** /**
@ -259,7 +259,7 @@ abstract class ModuleAbstract
*/ */
protected function createModel(int $account, mixed $obj, string $mapper, string $trigger, string $ip) : void protected function createModel(int $account, mixed $obj, string $mapper, string $trigger, string $ip) : void
{ {
$trigger = static::MODULE_NAME . '-' . $trigger . '-create'; $trigger = static::NAME . '-' . $trigger . '-create';
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj); $this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj);
$id = $mapper::create($obj); $id = $mapper::create($obj);
@ -268,7 +268,7 @@ abstract class ModuleAbstract
$account, $account,
null, $obj, null, $obj,
StringUtils::intHash($mapper), $trigger, StringUtils::intHash($mapper), $trigger,
static::MODULE_NAME, static::NAME,
(string) $id, (string) $id,
'', '',
$ip, $ip,
@ -291,7 +291,7 @@ abstract class ModuleAbstract
*/ */
protected function createModels(int $account, array $objs, string $mapper, string $trigger, string $ip) : void protected function createModels(int $account, array $objs, string $mapper, string $trigger, string $ip) : void
{ {
$trigger = static::MODULE_NAME . '-' . $trigger . '-create'; $trigger = static::NAME . '-' . $trigger . '-create';
foreach ($objs as $obj) { foreach ($objs as $obj) {
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj); $this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj);
@ -301,7 +301,7 @@ abstract class ModuleAbstract
$account, $account,
null, $obj, null, $obj,
StringUtils::intHash($mapper), $trigger, StringUtils::intHash($mapper), $trigger,
static::MODULE_NAME, static::NAME,
(string) $id, (string) $id,
'', '',
$ip, $ip,
@ -326,7 +326,7 @@ abstract class ModuleAbstract
*/ */
protected function updateModel(int $account, mixed $old, mixed $new, string | \Closure $mapper, string $trigger, string $ip) : void protected function updateModel(int $account, mixed $old, mixed $new, string | \Closure $mapper, string $trigger, string $ip) : void
{ {
$this->app->eventManager->triggerSimilar('PRE:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', $old); $this->app->eventManager->triggerSimilar('PRE:Module:' . static::NAME . '-' . $trigger . '-update', '', $old);
$id = 0; $id = 0;
if (\is_string($mapper)) { if (\is_string($mapper)) {
@ -335,12 +335,12 @@ abstract class ModuleAbstract
$mapper(); $mapper();
} }
$this->app->eventManager->triggerSimilar('POST:Module:' . static::MODULE_NAME . '-' . $trigger . '-update', '', $this->app->eventManager->triggerSimilar('POST:Module:' . static::NAME . '-' . $trigger . '-update', '',
[ [
$account, $account,
$old, $new, $old, $new,
StringUtils::intHash(\is_string($mapper) ? $mapper : \get_class($mapper)), $trigger, StringUtils::intHash(\is_string($mapper) ? $mapper : \get_class($mapper)), $trigger,
static::MODULE_NAME, static::NAME,
(string) $id, (string) $id,
'', '',
$ip, $ip,
@ -363,7 +363,7 @@ abstract class ModuleAbstract
*/ */
protected function deleteModel(int $account, mixed $obj, string $mapper, string $trigger, string $ip) : void protected function deleteModel(int $account, mixed $obj, string $mapper, string $trigger, string $ip) : void
{ {
$trigger = static::MODULE_NAME . '-' . $trigger . '-delete'; $trigger = static::NAME . '-' . $trigger . '-delete';
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj); $this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $obj);
$id = $mapper::delete($obj); $id = $mapper::delete($obj);
@ -372,7 +372,7 @@ abstract class ModuleAbstract
$account, $account,
$obj, null, $obj, null,
StringUtils::intHash($mapper), $trigger, StringUtils::intHash($mapper), $trigger,
static::MODULE_NAME, static::NAME,
(string) $id, (string) $id,
'', '',
$ip, $ip,
@ -397,7 +397,7 @@ abstract class ModuleAbstract
*/ */
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::MODULE_NAME . '-' . $trigger . '-relation-create'; $trigger = static::NAME . '-' . $trigger . '-relation-create';
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $rel1); $this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $rel1);
$mapper::createRelation($field, $rel1, $rel2); $mapper::createRelation($field, $rel1, $rel2);
@ -406,7 +406,7 @@ abstract class ModuleAbstract
$account, $account,
$rel1, $rel2, $rel1, $rel2,
StringUtils::intHash($mapper), $trigger, StringUtils::intHash($mapper), $trigger,
static::MODULE_NAME, static::NAME,
'0', '0',
'', '',
$ip, $ip,
@ -431,7 +431,7 @@ abstract class ModuleAbstract
*/ */
protected function deleteModelRelation(int $account, mixed $rel1, mixed $rel2, string $mapper, string $field, string $trigger, string $ip) : void protected function deleteModelRelation(int $account, mixed $rel1, mixed $rel2, string $mapper, string $field, string $trigger, string $ip) : void
{ {
$trigger = static::MODULE_NAME . '-' . $trigger . '-relation-delete'; $trigger = static::NAME . '-' . $trigger . '-relation-delete';
$this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $rel1); $this->app->eventManager->triggerSimilar('PRE:Module:' . $trigger, '', $rel1);
$mapper::deleteRelation($field, $rel1, $rel2); $mapper::deleteRelation($field, $rel1, $rel2);
@ -440,7 +440,7 @@ abstract class ModuleAbstract
$account, $account,
$rel1, $rel2, $rel1, $rel2,
StringUtils::intHash($mapper), $trigger, StringUtils::intHash($mapper), $trigger,
static::MODULE_NAME, static::NAME,
'0', '0',
'', '',
$ip, $ip,

View File

@ -42,7 +42,7 @@ final class SocketRouter implements RouterInterface
* '{REGEX_PATH}' => [ * '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // can also be static by using :: between namespace and function name * 'dest' => '{DESTINATION_NAMESPACE:method}', // can also be static by using :: between namespace and function name
* 'permission' => [ // optional * 'permission' => [ // optional
* 'module' => '{MODULE_NAME}', * 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE}, * 'type' => PermissionType::{TYPE},
* 'state' => PermissionState::{STATE}, * 'state' => PermissionState::{STATE},
* ], * ],

View File

@ -44,7 +44,7 @@ final class WebRouter implements RouterInterface
* 'verb' => RouteVerb::{VERB}, * 'verb' => RouteVerb::{VERB},
* 'csrf' => true, * 'csrf' => true,
* 'permission' => [ // optional * 'permission' => [ // optional
* 'module' => '{MODULE_NAME}', * 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE}, * 'type' => PermissionType::{TYPE},
* 'state' => PermissionState::{STATE}, * 'state' => PermissionState::{STATE},
* ], * ],

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Utils\IO\Zip; namespace phpOMS\Utils\IO\Zip;
use phpOMS\System\File\FileUtils; use phpOMS\System\File\FileUtils;
use phpOMS\System\File\Local\Directory;
/** /**
* Zip class for handling zip files. * Zip class for handling zip files.
@ -101,10 +102,14 @@ class Zip implements ArchiveInterface
*/ */
public static function unpack(string $source, string $destination) : bool public static function unpack(string $source, string $destination) : bool
{ {
if (!\is_file($source) || !\is_dir($destination)) { if (!\is_file($source)) {
return false; return false;
} }
if (!\is_dir($destination)) {
Directory::create($destination, recursive: true);
}
$destination = \str_replace('\\', '/', $destination); $destination = \str_replace('\\', '/', $destination);
$destination = \rtrim($destination, '/'); $destination = \rtrim($destination, '/');

View File

@ -43,11 +43,11 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
{ {
$this->module = new class() extends ModuleAbstract $this->module = new class() extends ModuleAbstract
{ {
const MODULE_VERSION = '1.2.3'; const VERSION = '1.2.3';
const MODULE_NAME = 'Test'; const NAME = 'Test';
const MODULE_ID = 2; const ID = 2;
protected static array $dependencies = [1, 2]; protected static array $dependencies = [1, 2];
@ -121,8 +121,8 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
*/ */
public function testConstants() : void public function testConstants() : void
{ {
self::assertEquals(2, $this->module::MODULE_ID); self::assertEquals(2, $this->module::ID);
self::assertEquals('1.2.3', $this->module::MODULE_VERSION); self::assertEquals('1.2.3', $this->module::VERSION);
} }
/** /**

View File

@ -74,9 +74,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
// create zip // create zip
Zip::pack( Zip::pack(
[ __DIR__ . '/testPackage',
__DIR__ . '/testPackage' => '/',
],
__DIR__ . '/testPackage.zip' __DIR__ . '/testPackage.zip'
); );
} }