- First commit, routes and database builder are usable
This commit is contained in:
commit
5f6ce82fd2
23 files changed
+787
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Controller;
|
||||
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
|
||||
use Notes\Route\Annotation\Object\Route as RouteParam,
|
||||
Notes\Route\Annotation\Method\Route,
|
||||
Notes\Security\Annotation\Security,
|
||||
Notes\Tell\Annotation\Language;
|
||||
|
||||
use \Lean\Console\Lib;
|
||||
|
||||
/**
|
||||
* @Language("lean.console")
|
||||
*/
|
||||
class Console {
|
||||
use Lib\ConsoleControllerTrait;
|
||||
|
||||
/**
|
||||
* @Route("/", "name" => "lean.console:home")
|
||||
* @param ServerRequestInterface $request
|
||||
* @param array $arguments
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function home(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
return $this->renderView("page/dashboard/index", [
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Controller;
|
||||
|
||||
use League\Route\Router;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
|
||||
use Notes\Route\Annotation\Object\Route as RouteParam,
|
||||
Notes\Route\Annotation\Method\Route,
|
||||
Notes\Security\Annotation\Security,
|
||||
Notes\Tell\Annotation\Language;
|
||||
|
||||
use \Lean\Console\Lib;
|
||||
|
||||
use Picea\Extension\UrlExtension;
|
||||
|
||||
/**
|
||||
* @Language("lean.route")
|
||||
*/
|
||||
class Request extends Console {
|
||||
use Lib\ConsoleControllerTrait;
|
||||
|
||||
/**
|
||||
* @Route("/request/routes", "name" => "lean.console:request.route")
|
||||
* @param ServerRequestInterface $request
|
||||
* @param array $arguments
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function routes(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$routes = $this->container->has(UrlExtension::class) ? $this->container->get(UrlExtension::class)->getRouteList(true) : false;
|
||||
|
||||
uksort($routes, function($a, $b) {
|
||||
return $a <=> $b;
|
||||
});
|
||||
|
||||
return $this->renderView("page/request/route", [
|
||||
'routes' => $routes
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Controller;
|
||||
|
||||
use League\Route\Router;
|
||||
|
||||
use Picea\Ui\Method\FormHandler;
|
||||
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
|
||||
|
||||
use Notes\Route\Annotation\Object\Route as RouteParam,
|
||||
Notes\Route\Annotation\Method\Route,
|
||||
Notes\Security\Annotation\Security,
|
||||
Notes\Tell\Annotation\Language;
|
||||
|
||||
use \Lean\Console\Lib,
|
||||
\Lean\Console\Form;
|
||||
|
||||
use Picea\Extension\UrlExtension;
|
||||
|
||||
use Ulmus\Annotation\Classes\Table,
|
||||
Ulmus\Container\AdapterProxy;
|
||||
|
||||
|
||||
/**
|
||||
* @Language("lean.storage")
|
||||
*/
|
||||
class Storage extends Console {
|
||||
use Lib\ConsoleControllerTrait;
|
||||
|
||||
/**
|
||||
* @Route("/storage/database", "name" => "lean.console:request.route")
|
||||
* @param ServerRequestInterface $request
|
||||
* @param array $arguments
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function database(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$connections = $this->container->has(AdapterProxy::class) ? $this->container->get(AdapterProxy::class)->connections : false;
|
||||
$migrations = $this->container->has(Lib\DatabaseMigrations::class) ? $this->container->get(Lib\DatabaseMigrations::class) : false;
|
||||
$migrations->getEntities();
|
||||
|
||||
$form = new FormHandler($request, new Form\Database($migrations), null);
|
||||
$context = $form->context;
|
||||
|
||||
return $this->renderView("page/storage/database", get_defined_vars());
|
||||
}
|
||||
|
||||
public function createTable() : void
|
||||
{
|
||||
foreach($migrations->entities as $table) {
|
||||
// $repository = $table
|
||||
// $entity::repository()->createTable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Entity;
|
||||
|
||||
use Ulmus\Common\EntityField;
|
||||
use Ulmus\Entity\Field\Datetime,
|
||||
Ulmus\Entity\InformationSchema;
|
||||
use Ulmus\EntityCollection;
|
||||
use Ulmus\Migration\FieldDefinition;
|
||||
|
||||
/**
|
||||
* @Table('name' => "columns", 'database' => "information_schema")
|
||||
*/
|
||||
class Column extends InformationSchema\Column
|
||||
{
|
||||
|
||||
public function differsFromFieldDefinition(FieldDefinition $definition) : bool
|
||||
{
|
||||
switch(true) {
|
||||
//case $definition->
|
||||
|
||||
// return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* public static function entityCollection(...$arguments) : EntityCollection
|
||||
{
|
||||
return new class(...$arguments) extends EntityCollection
|
||||
{
|
||||
public function getEntityData() : array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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\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) {
|
||||
|
||||
$table = Table::repository()->where(Table::field('name'), $table->tableName())
|
||||
->where(Table::field('schema'), $table->databaseName())
|
||||
->loadOne();
|
||||
|
||||
if ( $table ) {
|
||||
#$fields = $entiy::resolveEntity()->fieldList();
|
||||
|
||||
foreach($table->columns as $col) {
|
||||
dump( $entity::field($col->name) );
|
||||
}
|
||||
|
||||
# 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
|
||||
{
|
||||
try {
|
||||
if ( $context->create ?? false ) {
|
||||
$context->create::repository()->createTable();
|
||||
}
|
||||
elseif ( $context->createAll ?? false ) {
|
||||
foreach(explode(',', $context->createAll) as $entity) {
|
||||
$entity::repository()->createTable();
|
||||
}
|
||||
}
|
||||
|
||||
$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
|
||||
{
|
||||
return new class($request) extends FormContext {
|
||||
|
||||
public array $status = [];
|
||||
|
||||
public array $actions = [];
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Lib;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use Storage\Session;
|
||||
|
||||
use Picea;
|
||||
|
||||
/**
|
||||
* @Language("lean.route")
|
||||
* @RouteParam("methods" => [ 'GET', 'POST', 'DELETE' ], "base" => "/~")
|
||||
* @Security('locked' => false)
|
||||
*/
|
||||
trait ConsoleControllerTrait
|
||||
{
|
||||
use \Lean\Console\ControllerTrait;
|
||||
|
||||
protected ContainerInterface $container;
|
||||
|
||||
public function __construct(? Picea\Picea $picea, Session $session, ContainerInterface $container) {
|
||||
$this->picea = $picea;
|
||||
$this->session = $session;
|
||||
$this->container = $container;
|
||||
// $this->mailer = $mailer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Lib;
|
||||
|
||||
class DatabaseMigrations
|
||||
{
|
||||
public array $folderList;
|
||||
|
||||
public array $entities;
|
||||
|
||||
public function __construct(array $folders = [])
|
||||
{
|
||||
$this->folderList = $folders;
|
||||
}
|
||||
|
||||
public function getEntities() : void
|
||||
{
|
||||
$this->entities = [];
|
||||
|
||||
foreach($this->folderList as $folder => $namespace) {
|
||||
foreach(static::files($folder) as $file) {
|
||||
$name = $file->getBasename(".".$file->getExtension());
|
||||
$entity = rtrim($namespace, "\\") . "\\{$name}";
|
||||
$this->entities[$entity] = $entity::resolveEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function files(string $path, string $fileExtension = "") : \Generator
|
||||
{
|
||||
if ( \file_exists($path) ) {
|
||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST, \RecursiveIteratorIterator::CATCH_GET_CHILD);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ( $file->isFile() || $file->isDir() ) {
|
||||
if ($fileExtension && ( $file->getExtension() === $fileExtension )) {
|
||||
yield $file;
|
||||
}
|
||||
else {
|
||||
yield $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user