continue implementations

This commit is contained in:
Dennis Eichhorn 2024-01-12 00:30:03 +00:00
parent 6ba73f88b0
commit bab1a5b83b
2 changed files with 222 additions and 8 deletions

View File

@ -0,0 +1,184 @@
<?php
$jsonStr = '';
$name = 'ItemPackaging';
$namespace = 'Modules\IteManagement\Models';
$output = __DIR__ . '/../../../' . \str_replace('\\', '/', $namespace) . '/';
//////////// Create Mapper
$mapper = <<< MAPPER
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package {$namespace}
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace {$namespace};
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* {$name} mapper class.
*
* @package {$namespace}
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*
* @template T of {$name}
* @extends DataMapperFactory<T>
*/
final class ItemMapper extends DataMapperFactory
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
public const COLUMNS = [
{$columns}
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = '{$table}';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = '{$primaryfield}';
/**
* Has many relation.
*
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0
*/
public const HAS_MANY = [
];
}
MAPPER;
\file_put_contents($output . $name . 'Mapper.php', $mapper);
//////////// Create model
$model = <<< MODEL
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package {$namespace}
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace {$namespace};
/**
* {$name} class.
*
* @package {$namespace}
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class {$name} implements \JsonSerializable
{
{$members}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}
MODEL;
\file_put_contents($output . $name . '.php', $model);
//////////// Create null model
$nullmodel = <<< NULLMODEL
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package {$namespace}
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace {$namespace};
/**
* Null model
*
* @package {$namespace}
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class Null{$name} extends {$name}
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}
NULLMODEL;
\file_put_contents($output . 'Null' . $name . '.php', $nullmodel);

View File

@ -16,22 +16,22 @@ declare(strict_types=1);
function printUsage() : void
{
echo 'Usage: -d <DESTINATION_PATH> -m <PATH>
echo 'Usage: -m <PATH>';
';
echo "\t" . '-d Destination/output directory.' . "\n";
echo "\t" . '-m Module directory.' . "\n";
echo "\t" . '-m Module name.' . "\n";
}
$destination = ($key = \array_search('-d', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
$modulePath = ($key = \array_search('-m', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
// $destination = ($key = \array_search('-d', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
$moduleName = ($key = \array_search('-m', $argv)) === false || $key === \count($argv) - 1 ? null : \trim($argv[$key + 1], '" ');
if (!isset($destination) || !isset($modulePath)) {
if (!isset($moduleName)) {
\printUsage();
return;
}
$modulePath = __DIR__ . '/../../../Modules/' . $moduleName;
$sources = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modulePath));
$tpls = [];
$langs = [];
@ -69,7 +69,8 @@ foreach($langs as $lang => $data) {
$fileContent = \file_get_contents($tpl);
foreach ($data as $key => $word) {
if (\stripos($fileContent, '$this->getHtml(\'' . $key . '\')') !== false
if ((\stripos($fileContent, '$this->getHtml(\'' . $key . '\')') !== false
|| \stripos($fileContent, '$this->getHtml(\'' . $key . '\', \'' . $moduleName . '\', \'Backend\')') !== false)
&& ($key = \array_search($key, $unusedLanguage)) !== false
) {
unset($unusedLanguage[$key]);
@ -81,3 +82,32 @@ foreach($langs as $lang => $data) {
echo 'Language files have different length: ' . ($unequalLength ? 'yes' : 'no') . "\n";
echo 'Unused language components: ' . "\n";
\var_dump($unusedLanguage);
$sources = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modulePath));
$tpls = [];
$langs = [];
foreach ($sources as $source) {
if ($source->isFile()
&& (($temp = \strlen($source->getPathname()) - \strlen('lang.php')) >= 0 && \strpos($source->getPathname(), 'lang.php', $temp) !== false)
&& \strlen(\explode('.', \basename($source->getPathname()))[0]) === 2
) {
$file = \file_get_contents($source->getPathname());
$lines = \explode("\n", $file);
$exclude = [];
foreach ($lines as $line) {
foreach ($unusedLanguage as $unused) {
if (\strpos($line, ' \'' . $unused . '\' ') !== false
&& \stripos($unused, ':') === false
) {
continue 2;
}
}
$exclude[] = $line;
}
\file_put_contents($source->getPathname(), \implode("\n", $exclude));
}
}