7 Commits
10 changed files with 121 additions and 139 deletions

No files matched your search

+4
View File
@@ -39,6 +39,10 @@ return [
]
],
'cli' => [
'Lean\\Console\\Cli' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Cli", "" ]),
],
'routes' => ! getenv('DEBUG') ? [] : [
'Lean\\Console\\Controller' => implode(DIRECTORY_SEPARATOR, [ $path, "src", "Controller", "" ]),
],
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Lean\Console\Cli;
use Notes\CLI\Attribute\{Option, Command};
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
use Lean\Console\{Lib, };
# https://www.asciiart.eu/text-to-ascii-art
#[Command(description: PHP_EOL . <<<CLI
#[color:gray, bg: black]╔═════════════════════════╗[#]
#[color:gray, bg: black]║ _ ║[#]
#[color:gray, bg: black]║ | | ___ __ _ _ __ ║[#]
#[color:gray, bg: black]║ | | / _ \/ _` | '_ \ ║[#]
#[color:gray, bg: black]║ | |__| __/ (_| | | | | ║[#]
#[color:gray, bg: black]║ |_____\___|\__,_|_| |_| ║[#]
#[color:gray, bg: black]║ ║[#]
#[color:gray, bg: black]╚═════════════════════════╝[#]
Try #[color:gray, bg: black]'lean console --help'[#] for more information.
CLI
, command: 'console')]
#[Option(toggle: ['-h', '--help'], description: "Display help for the given command. When no command is given display help for the list command")]
#[Option(toggle: ['-q', '--quiet'], description: "Do not output any message")]
#[Option(toggle: ['-n', '--no-interaction'], description: "Run script without user interaction")]
#[Option(toggle: ['-v', '-vv', '-vvv', '--verbose'], description: "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", argument: Option::ARGUMENT_OPTIONAL)]
class Console
{
use Lib\ConsoleControllerTrait;
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace Lean\Console\Cli;
use Notes\CLI\Attribute\{Option, Command};
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
use Lean\Console\{Lib, };
# https://www.asciiart.eu/text-to-ascii-art
#[Command(description: PHP_EOL . <<<CLI
#[color:gray, bg: black]╔═════════════════════════╗[#]
#[color:gray, bg: black]║ _ ║[#]
#[color:gray, bg: black]║ | | ___ __ _ _ __ ║[#]
#[color:gray, bg: black]║ | | / _ \/ _` | '_ \ ║[#]
#[color:gray, bg: black]║ | |__| __/ (_| | | | | ║[#]
#[color:gray, bg: black]║ |_____\___|\__,_|_| |_| ║[#]
#[color:gray, bg: black]║ ║[#]
#[color:gray, bg: black]║ STORAGE ║[#]
#[color:gray, bg: black]╚═════════════════════════╝[#]
Try #[color:gray, bg: black]'lean console storage --help'[#] for more information.
CLI
, command: 'console storage')]
#[Option(toggle: ['-h', '--help'], description: "Display help for the given command. When no command is given display help for the list command")]
#[Option(toggle: ['-q', '--quiet'], description: "Do not output any message")]
#[Option(toggle: ['-n', '--no-interaction'], description: "Run script without user interaction")]
#[Option(toggle: ['-v', '-vv', '-vvv', '--verbose'], description: "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", argument: Option::ARGUMENT_OPTIONAL)]
class Storage
{
use Lib\ConsoleControllerTrait;
#[Command(description: "Generate entities based on an existing connection", command: "entity:generate")]
#[Option(toggle: ['-l', '--list'], description: "")]
public function generate_entity(ServerRequestInterface $request, array $arguments): ResponseInterface
{
dump($arguments);
return $this->renderCLI($request, ":)");
}
}
+2 -10
View File
@@ -27,7 +27,7 @@ class Storage extends Console {
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
$migrations->getEntities();
$context = (new FormHandler($request, new Form\Storage\DatabaseMigration($migrations)))->context;
$context = (new FormHandler($request, new Form\Storage\Database\Migrate($migrations)))->context;
return $this->renderView("lean-console/page/storage/database", get_defined_vars());
}
@@ -39,7 +39,7 @@ class Storage extends Console {
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
$migrations->getEntities();
$form = new Form\Storage\DatabaseImport($migrations, $connections);
$form = new Form\Storage\Database\Import($migrations, $connections);
$context = (new FormHandler($request, $form, $this->pushContext(new Lib\FormContext($request, "database.import"))))->context;
@@ -74,12 +74,4 @@ class Storage extends Console {
{
return rtrim(ini_get("session.save_path"), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
public function createTable() : void
{
foreach($migrations->entities as $table) {
// $repository = $table
// $entity::repository()->createTable();
}
}
}
-122
View File
@@ -1,122 +0,0 @@
<?php
namespace Lean\Console\Form;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
use \Lean\Console\Lib;
use Picea\Compiler\Context;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Common\EntityResolver;
use \Ulmus\Entity\InformationSchema\Table;
class Database implements FormInterface
{
protected ? Lib\DatabaseMigrations $migration;
public function __construct(Lib\DatabaseMigrations $migration)
{
$this->migration = $migration;
}
public function initialize(FormContextInterface $context) : void
{
$context->tableExist = [];
foreach($this->migration->entities as $entity => $table) {
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
$tableName = $table->tableName();
$databaseName = $table->databaseName();
if ( ! $tableName || ! $databaseName ) {
continue;
}
#<<<<<<< HEAD
$tableEntity = $adapter->schemaTable($databaseName, $tableName);
if ( $tableEntity ) {
#$fields = $entiy::resolveEntity()->fieldList();
foreach($tableEntity->columns as $col) {
//dump( $entity::field($col->name) );
#=======
# $table = Table::repository()
# ->where(Table::field('name'), $table->tableName())
# ->where(Table::field('schema'), $table->databaseName())
# ->loadOne();
# if ( $table ) {
# $fields = $entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
# $alter = [];
# foreach($fields as $field => $definition) {
# if ( $table->columns->filtersCollection(fn($e) => $e->name === $field)->count() === 0 ) {
# $alter[$field] = $definition;
# }
#>>>>>>> 7194a33bec884d745e838c8ac2693b353e95a3ce
}
if ( $alter ) {
$context->status[$entity] = [
'msg' => "alter",
"query" => $entity::repository()->alterSqlQuery($alter)->getSqlQuery(true),
];
}
else {
# if columns are different
$context->status[$entity] = [
'msg' => "up-to-date",
'query' => "",
];
}
}
else {
$context->status[$entity] = [
'msg' => "unexisting",
'query' => $entity::repository()->createSqlQuery()->getSqlQuery(true),
];
}
}
if ( $context->formSent() ) {
}
}
public function validate(FormContextInterface $context) : bool
{
return $context->valid();
}
public function execute(FormContextInterface $context) : void
{
if ( $context->create ?? false ) {
$context->create::repository()->createTable();
}
elseif ( $context->createAll ?? false ) {
foreach(explode(',', $context->createAll) as $entity) {
$entity::repository()->createTable();
}
}
elseif ( $context->alter ?? false ) {
}
$this->initialize($context);
}
public function getContext(ServerRequestInterface $request) : FormContextInterface
{
return new class($request) extends FormContext {
public array $status = [];
public array $actions = [];
};
}
}
@@ -0,0 +1,34 @@
<?php
namespace Lean\Console\Form\Storage\Database;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
use \Lean\Console\{ Lib, Entity };
use Picea\Compiler\Context;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\{ EntityCollection };
class GenerateEntity implements FormInterface
{
public function __construct()
{
}
public function initialize(FormContextInterface $context) : void
{
}
public function validate(FormContextInterface $context) : bool
{
return $context->valid();
}
public function execute(FormContextInterface $context) : void
{
}
}
@@ -1,6 +1,6 @@
<?php
namespace Lean\Console\Form\Storage;
namespace Lean\Console\Form\Storage\Database;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
@@ -10,7 +10,7 @@ use Picea\Compiler\Context;
use Psr\Http\Message\ServerRequestInterface;
use Ulmus\{ EntityCollection };
class DatabaseImport implements FormInterface
class Import implements FormInterface
{
protected ? Lib\DatabaseMigrations $migration;
@@ -1,6 +1,6 @@
<?php
namespace Lean\Console\Form\Storage;
namespace Lean\Console\Form\Storage\Database;
use Picea\Ui\Method\{ FormInterface, FormContext, FormContextInterface };
@@ -11,7 +11,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Common\EntityResolver;
use \Ulmus\Entity\InformationSchema\Table;
class DatabaseMigration implements FormInterface
class Migrate implements FormInterface
{
public function __construct(
protected ? Lib\DatabaseMigrations $migration,
+3 -1
View File
@@ -22,7 +22,7 @@ class DatabaseMigrations
foreach($this->folderList as $namespace => $folder) {
foreach(static::files($folder) as $file) {
$name = $file->getBasename("." . $file->getExtension());
$subNs = substr($file->getPath(), strlen($folder));
$subNs = str_replace('/', '\\', substr($file->getPath(), strlen($folder)));
$entity = rtrim($namespace, "\\") . ( $subNs ? "\\$subNs" : "" ) . "\\{$name}";
if ( ! method_exists($entity, 'resolveEntity') ) {
@@ -34,6 +34,8 @@ class DatabaseMigrations
if ( $resolve->sqlAdapter()->adapter() instanceof SqlAdapterInterface) {
$this->entities[$entity] = $resolve;
}
else {
}
}
}
@@ -47,7 +47,7 @@
<div class="col"><span>📄</span> <span>{{ $item->tableName() }}</span></div>
<div class="col">{% _ "database.table.fields", [ 'count' => count( $item->fieldList() ) ] %}</div>
<div class="col col-grow-2">
{% if $context->definition[$entity]['table']->modifier->query %}
{% if $context->definition[$entity]['table']->modifier->query ?? false %}
<code>{{= implode('<br><br>',(array) $context->definition[$entity]['table']->modifier->query) }}</code>
{% else %}
<div style="color:#abecab">&#x2713 {% _ 'database.table.uptodate' %}</div>
@@ -55,7 +55,7 @@
</div>
<div class="col">
{% switch $context->definition[$entity]['table']->modifier->type %}
{% switch $context->definition[$entity]['table']->modifier->type ?? false %}
{% case ModifierTypeEnum::Create %}
{% php $createAll[] = $entity %}