- UI Revamp

- Some i18n added/fixed
- WIP on a new testing mechanism
This commit is contained in:
mcndave committed 2026-11-25 19:18:36 +00:00
1 parent f5014e1cee
commit 58c61a8f01
76 files changed
+1428 -313

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Lean\Console\Attribute;
#[\Attribute(flags: \Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
readonly class Test
{
public function __construct(
public string $name,
public ? string $after = null,
public string $method = "GET",
public array $arguments = [],
public array $withParsedBody = [],
public array $withQueryParams = [],
) {}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace Lean\Console\Attribute;
#[\Attribute(flags: \Attribute::TARGET_CLASS)]
readonly class TestParameter
{
public function __construct(
public ? string $waitFor = null,
) { }
}
+9 -3
View File
@@ -6,10 +6,9 @@ use League\Route\Router;
use Picea\{FileFetcher, Picea, Caching\Opcache, Extension\UrlExtension, Ui\Method\FormHandler};
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Lean\Console\{ Form, Lib };
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
use Notes\Route\Attribute\Method\Route;
class Caching extends Console {
use Lib\ConsoleControllerTrait;
#[Route(route: "/caching/picea", name: "lean.console:caching")]
public function picea(ServerRequestInterface $request, array $arguments) : ResponseInterface
@@ -17,9 +16,16 @@ class Caching extends Console {
$list = [];
if ( isset($this->picea) ) {
new FormHandler($request, new Form\Caching\Picea($this->picea, $list), $this->pushContext(new Lib\FormContext($request, "caching.picea")));
$context =$this->pushContext(new Lib\FormContext($request, "caching.picea"));
new FormHandler($request, new Form\Caching\Picea($this->picea, $list), $context);
if ($context->getExecutionStatus()) {
return $this->redirect($this->route('lean.console:caching'));
}
}
return $this->renderView("lean-console/page/caching/picea", get_defined_vars());
}
}
-20
View File
@@ -11,24 +11,4 @@ use \Lean\Console\{ Lib, Form };
class Console {
use Lib\ConsoleControllerTrait;
#[Route(route: "/", name: "lean.console:home")]
public function home(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
return $this->renderView("lean-console/page/dashboard/index", [
]);
}
#[Route(route: "/update", name: "lean.console:update")]
public function update(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
new FormHandler($request, $git = new Form\Update\Git(getenv('PROJECT_PATH')));
$status = iterator_to_array($git->run("/usr/bin/git status -s"));
$diff = iterator_to_array($git->run("/usr/bin/git diff"));
$lastUpdate = iterator_to_array($git->run("/usr/bin/git show --no-patch --format=%ci"))[0] ?? null;
return $this->renderView("lean-console/page/update/index", get_defined_vars());
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Lean\Console\Controller;
use Picea\Ui\Method\FormHandler;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
use \Lean\Console\{ Lib, Form };
class Core extends Console {
#[Route(route: "/", name: "lean.console:home")]
public function home(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
return $this->renderView("lean-console/page/dashboard/index", get_defined_vars());
}
#[Route(route: "/update", name: "lean.console:update")]
public function update(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
new FormHandler($request, $git = new Form\Update\Git(getenv('PROJECT_PATH')));
$status = iterator_to_array($git->run("/usr/bin/git status -s"));
$diff = iterator_to_array($git->run("/usr/bin/git diff"));
$lastUpdate = iterator_to_array($git->run("/usr/bin/git show --no-patch --format=%ci"))[0] ?? null;
return $this->renderView("lean-console/page/update/index", get_defined_vars());
}
}
+6
View File
@@ -39,6 +39,12 @@ class Debugging extends Console {
$phpinfo = ob_get_contents() ;
ob_end_clean() ;
$phpinfo = str_replace([
'body {background-color: #fff;'
], [
'body {'
], $phpinfo);
return $this->renderView("lean-console/page/debugging/phpinfo", get_defined_vars());
}
}
+5 -18
View File
@@ -2,20 +2,15 @@
namespace Lean\Console\Controller;
use League\Route\Router;
use Picea\Ui\Method\FormHandler;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Notes\Tell\Attribute\Language, Notes\Route\Attribute\Method\Route;
use Notes\Route\Attribute\Method\Route;
use \Lean\Console\Lib,
\Lean\Console\Form;
use Lean\Console\Lib,
Lean\Console\Form;
use Picea\Extension\UrlExtension;
use Ulmus\Annotation\Classes\Table,
Ulmus\Container\AdapterProxy;
use Ulmus\Container\AdapterProxy;
class Storage extends Console {
use Lib\ConsoleControllerTrait;
@@ -69,15 +64,7 @@ class Storage extends Console {
#[Route(route: "/storage/session/content/{hash}", name: "lean.console:storage.session_content")] # migrated from: "/storage/session/content/{hash}", "name" => "lean.console:storage.session_content"
public function sessionContent(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$sess = session_encode();
session_decode(file_get_contents($this->sessionPath() . $arguments['hash']));
$data = array_combine(array_keys($_SESSION), array_values($_SESSION));
session_decode($sess);
return $this->renderJson($data);
return $this->renderText(file_get_contents($this->sessionPath() . $arguments['hash']) ?: "-");
}
protected function sessionPath() : string
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace Lean\Console\Controller;
use DI\Attribute\Inject;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
use Notes\Route\Attribute\Method\Route;
use Lean\Console\{ Lib, Form };
class Testing extends Console {
use Lib\ConsoleControllerTrait;
#[Inject]
protected Lib\Testing\TestFetcher $testFetcher;
#[Route(route: "/testing/tests", name: "lean.console:testing.tests", method: [ 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTION', 'HEAD' ])]
public function tests(ServerRequestInterface $request, array $arguments) : ResponseInterface
{
$context = new Form\Testing\TestContext($request, "tests.run");
$this->form(new Form\Testing\Test($this->container, $this->testFetcher), $context);
if ($context->formExecuted) {
return $context->formExecutionStatus;
}
return $this->renderView("lean-console/page/testing/tests", get_defined_vars());
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
<?php
namespace Lean\Console\Entity\Mysql;
namespace Lean\Console\Entity\Sqlite;
use Ulmus\Common\EntityField;
use Ulmus\Entity\Field\Datetime,
@@ -11,7 +11,7 @@ use Ulmus\Migration\FieldDefinition;
use Ulmus\Attribute\Obj\Table;
#[Table(name: "columns", database: "information_schema")]
class Column extends Sqlite
class Column extends Sqlite\Column
{
public function differsFromFieldDefinition(FieldDefinition $definition) : bool
{
+2 -1
View File
@@ -45,7 +45,7 @@ class Picea implements FormInterface
return $context->valid();
}
public function execute(FormContextInterface $context) : void
public function execute(FormContextInterface $context) : mixed
{
$deleted = $failed = 0;
@@ -57,6 +57,7 @@ class Picea implements FormInterface
}
if ($deleted) {
return true;
# $context->pushMessage();
}
@@ -23,8 +23,6 @@ class GenerateEntity implements FormInterface
public function validate(FormContextInterface $context) : bool
{
return $context->valid();
}
+16 -11
View File
@@ -131,22 +131,27 @@ class Migrate implements FormInterface
$alter = $context->alterAll ? explode(',', $context->alterAll) : [ $context->alter ];
foreach(array_filter($alter) as $entity) {
if ($this->definition[$entity]['table']->modifier->type === Lib\Database\ModifierTypeEnum::Alter) {
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
try {
foreach (array_filter($alter) as $entity) {
if ($this->definition[$entity]['table']->modifier->type === Lib\Database\ModifierTypeEnum::Alter) {
$adapter = $entity::resolveEntity()->sqlAdapter()->adapter();
$def = $this->definition[$entity]['columns']->filterAlter();
$def = $this->definition[$entity]['columns']->filterAlter();
if ( $adapter->splitAlterQuery() ) {
$def->walk(fn(Lib\Database\Definition $definition) =>
$entity::repository()->alterTable([ $definition->toArray() ])
);
}
else {
$entity::repository()->alterTable($def->map( fn(Lib\Database\Definition $e) => $e->toArray() ));
if ($adapter->splitAlterQuery()) {
$def->walk(fn(Lib\Database\Definition $definition) => $entity::repository()->alterTable([$definition->toArray()])
);
} else {
$entity::repository()->alterTable($def->map(fn(Lib\Database\Definition $e) => $e->toArray()));
}
}
}
}
catch(\Throwable $t) {
$context->pushMessage(
Lib\Message::generateError($t->getMessage())
);
}
$this->initialize($context);
}
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace Lean\Console\Form\Testing;
use Picea\Ui\Method\{ FormInterface, FormContextInterface };
use Lean\Console\{Attribute\TestParameter, Lib, Entity};
use Ulmus\{ EntityCollection };
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
class Test implements FormInterface
{
protected Lib\Testing\TestPreprocessorInterface $waitFor;
protected Lib\Testing\TestFetcherItem $definition;
public function __construct(
protected ContainerInterface $container,
protected Lib\Testing\TestFetcher $testFetcher,
) {}
public function initialize(FormContextInterface $context) : void
{
if ($context->class ?? false) {
$this->definition = $this->testFetcher->compile()[$context->class];
}
}
public function validate(FormContextInterface $context) : bool
{
if (isset($this->definition->attribute) && $this->definition->attribute->waitFor) {
$this->waitFor = new $this->definition->attribute->waitFor();
}
return $context->valid();
}
public function execute(FormContextInterface $context) : mixed
{
if (isset($this->waitFor)) {
$this->waitFor->run();
}
$controller = $this->container->get($context->class);
$test = $this->definition->methods->filtersOne(fn($e) => $e->attribute->name === $context->name);
$request = $context->getRequest()
->withMethod($context->method)
->withAttribute('arguments', $test->attribute->arguments)
->withQueryParams($test->attribute->withQueryParams)
->withParsedBody($test->attribute->withParsedBody);
$arguments = []; # @todo
$result = $controller->{$test->name}($request, $arguments);
return $result;
}
public function attributeCollection(array $collection) : EntityCollection
{
$collection = new EntityCollection(...$collection);
$collection->entityClass = static::class;
return $collection;
}
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace Lean\Console\Form\Testing;
use \Lean\Console\{ Lib, Entity };
class TestContext extends Lib\FormContext
{
public string $class;
public string $name;
public string $method;
}
+103
View File
@@ -0,0 +1,103 @@
<?php declare(strict_types=1);
namespace Lean\Console\Lib;
use Picea\Ui\Method\FormMessage;
class Message implements FormMessage {
const MESSAGE_TYPE = [
'success' => [
'class' => 'success',
'header' => 'Succès !',
'message' => ''
],
'error' => [
'class' => 'danger',
'header' => 'Error !',
'message' => ''
],
'warning' => [
'class' => 'warning',
'header' => 'Attention !',
'message' => ''
],
];
public string $type;
public string $message;
public string $class;
public ? string $header = null;
public function __construct(string $message, string $type = "error", ? string $header = null, ? string $class = null)
{
$this->message = $message;
$this->type = $type;
if ( $header !== null ) {
$this->header = $header;
}
else {
$this->header = static::MESSAGE_TYPE[$type]['header'];
}
if ( $class !== null ) {
$this->class = $class;
}
else {
$this->class = static::MESSAGE_TYPE[$type]['class'];
}
}
public function render() : string
{
return <<<HTML
<article class="message type-{$this->class}" role="alert">
<div class="message-body">
<strong class="message-header">{$this->header}</strong>
<span class="message-content">{$this->message}</span>
</div>
</article>
HTML;
}
public function renderJson() : array
{
return [
'name' => 'show-notification',
'type' => [
'error' => 'danger',
'success' => 'success',
'warning' => 'warning',
][$this->type],
'shake' => '.wrapper',
'message' => $this->message,
];
}
public function isError() : bool
{
return $this->type === "error";
}
public static function generateSuccess(string $message, ? string $header = null, ? string $class = null) : self
{
return new static($message, 'success', $header, $class);
}
public static function generateError(string $message, ? string $header = null, ? string $class = null) : self
{
return new static($message, 'error', $header, $class);
}
public static function generateWarning(string $message, ? string $header = null, ? string $class = null) : self
{
return new static($message, 'warning', $header, $class);
}
}
+125
View File
@@ -0,0 +1,125 @@
<?php namespace Lean\Console\Lib\Testing;
use Kash\HandleCacheTrait;
use Lean\Api\Entity\ArrayCollection;
use Lean\Console\Attribute;
use Notes\ObjectResolver;
use Psr\SimpleCache\CacheInterface;
use RuntimeException, DirectoryIterator, Generator;
class TestFetcher {
use HandleCacheTrait;
protected array $folderList;
protected array $annotations;
public function __construct( ?array $folderList = null, ?array $annotations = null, ? CacheInterface $cache = null)
{
$this->cache = $cache;
if ($folderList !== null) {
$this->folderList = $folderList;
}
if ($annotations !== null) {
$this->annotations = $annotations;
}
else {
$this->annotations = [
'object' => [ Attribute\TestParameter::class ],
'method' => [ Attribute\Test::class ],
];
}
}
public function addFolder($folder) : void
{
$this->folderList[] = $folder;
}
public function setFolderList(array $list) : void
{
$this->folderList = $list;
}
public function getNodeList() : array
{
$list = [];
return $list;
}
public function compile() : array
{
return $this->handleCaching(substr(md5(serialize($this->annotations)), 0, 7), function() : array {
foreach($this->scan() as $namespace => $file) {
if ($file->getExtension() !== "php") {
continue;
}
$class = $this->generateClassname($file->getBasename(".php"), $namespace);
$objectResolver = new ObjectResolver($class, $this->cache);
$testParam = $objectResolver->reflectedClass->getClassAttributeListFromClassname($this->annotations['object'], true, false)[0] ?? false;
if ($testParam) {
$entity = new TestFetcherItem();
$entity->attribute = $testParam;
$entity->methods = ArrayCollection::instance();
/* $list[$class] = [
'attribute' => $testParam,
'methods' => [],
];
*/
foreach ($objectResolver->reflectedClass->getMethodAttributeListFromClassname($this->annotations['method'], false, false) as $method => $controllers) {
foreach ($controllers as $test) {
/*$list[$class]['methods'][] = [
'name' => $method,
'attribute' => $test
] ;*/
$entity->methods->push(new TestFetcherMethod(
name: $method,
attribute: $test
));
}
}
$list[$class] = $entity;
}
}
return $list ?? [];
});
}
private function scan(? array $folders = null) : Generator
{
foreach($folders ?: $this->folderList as $namespace => $folder) {
if ( ! file_exists($folder) ) {
throw new RuntimeException(sprintf("Folder `%s` can not be found or scanned", $folder));
}
foreach (new DirectoryIterator($folder) as $fileinfo) {
if ( ! $fileinfo->isDot() ) {
if ( $fileinfo->isDir() ) {
foreach($this->scan([ "{$namespace}\\" . $fileinfo->getBasename() => $fileinfo->getPathname() ]) as $ns2 => $fi2) {
yield $ns2 => $fi2;
}
}
else {
yield $namespace => $fileinfo;
}
}
}
}
}
protected function generateClassname($file, $namespace)
{
return "\\$namespace\\$file";
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Lean\Console\Lib\Testing;
use Lean\Api\Entity\ArrayCollection;
use Ulmus\Attribute\Property\ArrayOf;
use Ulmus\Attribute\Property\Field;
class TestFetcherItem
{
#[Field]
public \Lean\Console\Attribute\TestParameter $attribute;
#[Field, ArrayOf(TestFetcherMethod::class)]
public ArrayCollection $methods;
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Lean\Console\Lib\Testing;
use Picea\Ui\Method\Context\FormContextCastableInterface;
use Ulmus\Attribute\Property\Field;
use Ulmus\Entity\JsonUnserializable;
class TestFetcherMethod
{
public function __construct(
public string $name,
public \Lean\Console\Attribute\Test $attribute,
) {}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Lean\Console\Lib\Testing;
use Lean\Console\Attribute\Test;
class TestNode
{
public function __construct(
public Test $attribute,
public array/*<TestNode>*/ $children = [],
) {}
}
@@ -0,0 +1,8 @@
<?php
namespace Lean\Console\Lib\Testing;
interface TestPreprocessorInterface
{
public function run() : void;
}