- Work done on DatabaseMigration part and separation from Lean main package too.

This commit is contained in:
Dave M. 2021-01-21 20:59:00 +00:00
parent 923b2be49e
commit f6fadd715e
5 changed files with 69 additions and 26 deletions

View File

@ -0,0 +1,35 @@
<?php
use Lean\Console\Lib\DatabaseMigrations;
return [
'lean.console' => [
'picea' => [
'view' => [
[
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/view/",
'order' => 99,
],
],
],
'ulmus' => [],
'tell' => [
'json' => [
[
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/meta/i18n",
'order' => 99,
],
]
],
'routes' => [
'Lean\\Console\\Controller' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean-console/src/Controller/",
],
],
DatabaseMigrations::class => function($c) {
return new DatabaseMigrations( $c->get(Lean\Lean::class)->getEntities() );
},
];

View File

@ -15,7 +15,7 @@ use \Lean\Console\Lib;
use Picea\Extension\UrlExtension; use Picea\Extension\UrlExtension;
/** /**
* @Language("lean.route") * @Language("lean.request")
*/ */
class Request extends Console { class Request extends Console {
use Lib\ConsoleControllerTrait; use Lib\ConsoleControllerTrait;

View File

@ -62,7 +62,6 @@ class Database implements FormInterface
public function execute(FormContextInterface $context) : void public function execute(FormContextInterface $context) : void
{ {
try {
if ( $context->create ?? false ) { if ( $context->create ?? false ) {
$context->create::repository()->createTable(); $context->create::repository()->createTable();
} }
@ -74,16 +73,7 @@ class Database implements FormInterface
$this->initialize($context); $this->initialize($context);
} }
catch (\Exception $ex) {
dump($ex);
$context->pushMessage(new Message(
"Une erreur inattendue semble avoir été provoquée lors de la sauvegarde des données. Le programmeur en charge du logiciel en a été avisé par courriel."
));
# @TODO ADD THEBUGS EMAIL SENDING HERE !!!
}
}
public function getContext(ServerRequestInterface $request) : FormContextInterface public function getContext(ServerRequestInterface $request) : FormContextInterface
{ {
return new class($request) extends FormContext { return new class($request) extends FormContext {

13
src/Lean.php Normal file
View File

@ -0,0 +1,13 @@
<?php
namespace Lean\Console;
use Psr\Container\ContainerInterface;
abstract class Lean
{
public static function definitions() : array
{
return require(dirname(__DIR__) . "/meta/definitions/software.php");
}
}

View File

@ -17,10 +17,11 @@ class DatabaseMigrations
{ {
$this->entities = []; $this->entities = [];
foreach($this->folderList as $folder => $namespace) { foreach($this->folderList as $namespace => $folder) {
foreach(static::files($folder) as $file) { foreach(static::files($folder) as $file) {
$name = $file->getBasename(".".$file->getExtension()); $name = $file->getBasename("." . $file->getExtension());
$entity = rtrim($namespace, "\\") . "\\{$name}"; $subNs = substr($file->getPath(), strlen($folder));
$entity = rtrim($namespace, "\\") . ( $subNs ? "\\$subNs" : "" ) . "\\{$name}";
$this->entities[$entity] = $entity::resolveEntity(); $this->entities[$entity] = $entity::resolveEntity();
} }
} }
@ -33,14 +34,18 @@ class DatabaseMigrations
foreach ($iterator as $file) { foreach ($iterator as $file) {
if ( $file->isFile() || $file->isDir() ) { if ( $file->isFile() || $file->isDir() ) {
if ($fileExtension && ( $file->getExtension() === $fileExtension )) { if ($fileExtension) {
if ( $file->getExtension() === $fileExtension ) {
yield $file; yield $file;
} }
}
else { else {
if ( $file->isFile() ) {
yield $file; yield $file;
} }
} }
} }
} }
} }
}
} }