From 2e51ff9f4a8124c8dde98fce5220a20fa004432c Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll <info@mcnd.ca> Date: Tue, 19 Sep 2023 18:54:34 -0400 Subject: [PATCH 1/3] - WIP on File lib and CLI's definition --- meta/definitions/cli.php | 18 ----------------- src/File.php | 43 ++++++++++++++++++++++++++++++++++++++++ src/Lean.php | 2 +- 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 src/File.php diff --git a/meta/definitions/cli.php b/meta/definitions/cli.php index 98a42b2..c6237cd 100644 --- a/meta/definitions/cli.php +++ b/meta/definitions/cli.php @@ -11,24 +11,6 @@ use Notes\CLI\CommandFetcher; use Lean\Lean; return [ - /*CronardMiddleware::class => function($c) { - $cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface { - return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s'))); - }, [], $c->get(TaskFetcher::class)); - - return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class)); - }, - - TaskFetcher::class => function($c) { - $fetcher = new TaskFetcher(null, null, $c->get('cronard.caching')); - - $fetcher->setFolderList(array_map(function($item) { - return $item; - }, $c->get(Lean::class)->getCronard())); - - return $fetcher; - },*/ - CommandFetcher::class => function($c) { $fetcher = new CommandFetcher(null, null, $c->get('cli.caching')); diff --git a/src/File.php b/src/File.php new file mode 100644 index 0000000..1b2d4e2 --- /dev/null +++ b/src/File.php @@ -0,0 +1,43 @@ +<?php + +namespace Lean; + +class File +{ + public static function tail(string $path, int $lines = 10) : false|array + { + $handle = fopen($path, "r"); + + $counter = $lines; + + $pos = -2; + $beginning = false; + $text = array(); + + while ($counter && ! $beginning) { + $t = ""; + + while ($t !== PHP_EOL) { + if(fseek($handle, $pos, SEEK_END) == -1) { + $beginning = true; + break; + } + + $t = fgetc($handle); + $pos --; + } + + $counter --; + + if ($beginning) { + rewind($handle); + } + + $text[$lines - $counter - 1] = fgets($handle); + } + + fclose ($handle); + + return array_reverse($text); + } +} \ No newline at end of file diff --git a/src/Lean.php b/src/Lean.php index af51de6..7e3dc77 100644 --- a/src/Lean.php +++ b/src/Lean.php @@ -133,7 +133,7 @@ class Lean $path = dirname(__DIR__) . "/meta/definitions/"; return array_merge( - class_exists(\Mcnd\CLI\Middleware::class) ? require($path . "cli.php") : [], + class_exists(\Mcnd\CLI\CliMiddleware::class) ? require($path . "cli.php") : [], class_exists(\Cronard\CronardMiddleware::class) ? require($path . "cronard.php") : [], require($path . "email.php"), require($path . "event.php"), From 8a5f5f052b925c10055814bc5cf459e7cae27bcb Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll <info@mcnd.ca> Date: Wed, 20 Sep 2023 18:42:13 +0000 Subject: [PATCH 2/3] - Fixed some bugs within Skeleton's package --- skeleton/meta/config.php | 6 ++++++ skeleton/meta/definitions/auth.php | 2 -- skeleton/meta/definitions/security.php | 2 +- skeleton/meta/definitions/storage.php | 2 -- skeleton/src/Controller/Home.php | 3 ++- skeleton/src/Entity/User.php | 2 +- skeleton/src/Lib/ControllerTrait.php | 3 ++- skeleton/src/Middleware/Authentication.php | 12 ++---------- skeleton/view/base/layout/default.phtml | 1 - skeleton/view/home.phtml | 4 ++++ 10 files changed, 18 insertions(+), 19 deletions(-) diff --git a/skeleton/meta/config.php b/skeleton/meta/config.php index 99fbb40..2e40b90 100644 --- a/skeleton/meta/config.php +++ b/skeleton/meta/config.php @@ -30,6 +30,12 @@ return [ 'charset' => getenv("DATABASE_CHARSET"), ], ], + + #'sqlite' => [ + # 'adapter' => getenv("SQLITE_ADAPTER"), + # 'path' => getenv('PROJECT_PATH') . DIRECTORY_SEPARATOR . getenv("SQLITE_PATH"), + # 'pragma' => explode(',', getenv("SQLITE_PRAGMA")), + #], ] ] ]; diff --git a/skeleton/meta/definitions/auth.php b/skeleton/meta/definitions/auth.php index 9405214..7e37832 100644 --- a/skeleton/meta/definitions/auth.php +++ b/skeleton/meta/definitions/auth.php @@ -63,6 +63,4 @@ return [ return $email; }, - - PermissionGrantInterface::class => create(%NAMESPACE%\PrivilegeGrantAccess::class)->constructor(get(ServerRequestInterface::class), get(Session::class)), ]; diff --git a/skeleton/meta/definitions/security.php b/skeleton/meta/definitions/security.php index 1cc4c09..892ac27 100644 --- a/skeleton/meta/definitions/security.php +++ b/skeleton/meta/definitions/security.php @@ -18,5 +18,5 @@ return [ ); }, - PermissionGrantInterface::class => create(DefaultPermissionGrant::class)->constructor(get(ServerRequestInterface::class), get(Session::class)), + PermissionGrantInterface::class => create(%NAMESPACE%\PrivilegeGrantAccess::class)->constructor(get(ServerRequestInterface::class), get(Session::class)), ]; diff --git a/skeleton/meta/definitions/storage.php b/skeleton/meta/definitions/storage.php index 4fefaf2..8b485dc 100644 --- a/skeleton/meta/definitions/storage.php +++ b/skeleton/meta/definitions/storage.php @@ -14,8 +14,6 @@ return [ $adapter = new ConnectionAdapter('default', $c->get('config')['ulmus'], true); $adapter->resolveConfiguration(); - $adapter->connect(); - return $adapter; }, diff --git a/skeleton/src/Controller/Home.php b/skeleton/src/Controller/Home.php index 73f6fbf..33d575f 100644 --- a/skeleton/src/Controller/Home.php +++ b/skeleton/src/Controller/Home.php @@ -4,11 +4,12 @@ namespace %NAMESPACE%\Controller; use Psr\Http\Message\{ServerRequestInterface, ResponseInterface }; +use Notes\Route\Attribute\Method\Route; + use %NAMESPACE%\{ Lib, Entity, Form, }; use function %NAMESPACE%\View\{ _, lang, url, route, form }; -#[Language("%APPKEY%.home")] class Home { use Lib\ControllerTrait; diff --git a/skeleton/src/Entity/User.php b/skeleton/src/Entity/User.php index 1ef3fb6..dac9dc5 100644 --- a/skeleton/src/Entity/User.php +++ b/skeleton/src/Entity/User.php @@ -3,7 +3,7 @@ namespace %NAMESPACE%\Entity; use Ulmus\Entity\Field\Datetime; -use Ulmus\{Attribute\Obj\Table; +use Ulmus\{Attribute\Obj\Table}; use %NAMESPACE%\Lib; diff --git a/skeleton/src/Lib/ControllerTrait.php b/skeleton/src/Lib/ControllerTrait.php index 21e6d1f..5fd2679 100644 --- a/skeleton/src/Lib/ControllerTrait.php +++ b/skeleton/src/Lib/ControllerTrait.php @@ -8,7 +8,8 @@ use Ulmus\User\Entity\User; use Ulmus\User\Lib\Authenticate; use Notes\Route\Attribute\Object\Route; use Notes\Security\Attribute\Security; -use %NAMESPACE%\Entity; + +use %NAMESPACE%\{ Entity, Lib, Form }; use Mcnd\Event\EventManager; diff --git a/skeleton/src/Middleware/Authentication.php b/skeleton/src/Middleware/Authentication.php index c939356..c4cc124 100644 --- a/skeleton/src/Middleware/Authentication.php +++ b/skeleton/src/Middleware/Authentication.php @@ -2,11 +2,8 @@ namespace %NAMESPACE%\Middleware; -use Psr\Http\Server\MiddlewareInterface; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Server\RequestHandlerInterface; -use Psr\Http\Message\ResponseInterface; - +use Psr\Http\Server\{ RequestHandlerInterface, MiddlewareInterface }; +use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface }; use Storage\Session; class Authentication implements MiddlewareInterface { @@ -23,9 +20,6 @@ class Authentication implements MiddlewareInterface { $this->session = $session; } - #[param ServerRequestInterface $request] - #[param RequestHandlerInterface $handler] - #[return ResponseInterface] public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { $user = $this->session->get( $this->sessionUserVariable() ); @@ -37,8 +31,6 @@ class Authentication implements MiddlewareInterface { return $handler->handle($request); } - #[param string|null sessionUserVariable] - #[return mixed] public function sessionUserVariable(?string $set = null) : string { return $set !== null ? $this->sessionUserVariable = $set : $this->sessionUserVariable; diff --git a/skeleton/view/base/layout/default.phtml b/skeleton/view/base/layout/default.phtml index ebfa87e..b0f654e 100644 --- a/skeleton/view/base/layout/default.phtml +++ b/skeleton/view/base/layout/default.phtml @@ -5,7 +5,6 @@ <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>{% section "head.title" %}{{ title() }} — {{ lang('application_name') }}{% endsection %}</title> - </style> </head> {% endsection %} diff --git a/skeleton/view/home.phtml b/skeleton/view/home.phtml index 1d7e5c9..e2a7c93 100644 --- a/skeleton/view/home.phtml +++ b/skeleton/view/home.phtml @@ -6,4 +6,8 @@ <div class="main"> Hello World :) ! </div> + + <div> + <a href="{% route 'lean.console:home' %}">Accéder à la console LEAN</a> + </div> {% endsection %} \ No newline at end of file From b6d7e5fad50de9b685c94846e304462eb9057a18 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll <info@mcnd.ca> Date: Fri, 6 Oct 2023 19:09:45 -0400 Subject: [PATCH 3/3] - WIP on picea-asset --- meta/definitions/template.php | 6 ++++++ skeleton/lean | 9 +++++++++ src/ControllerTrait.php | 6 +++++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 skeleton/lean diff --git a/meta/definitions/template.php b/meta/definitions/template.php index 95d3d81..ea13690 100644 --- a/meta/definitions/template.php +++ b/meta/definitions/template.php @@ -7,6 +7,7 @@ use Laminas\Diactoros\Response\HtmlResponse; use Picea\{ Picea, Caching\Cache, Caching\Opcache, Compiler, Compiler\Context, Compiler\BaseContext, FileFetcher, Language\DefaultRegistrations, Method\Request }; use Picea\Extension\{ LanguageHandler, LanguageExtension, TitleExtension, NumberExtension, UrlExtension }; use Picea\Ui\{ Method, Ui }; +use Picea\Asset\Asset; return [ Picea::class => function($c) { @@ -33,6 +34,11 @@ return [ { parent::registerAll($compiler); ( new Ui() )->registerFormExtension($compiler); + + if ( class_exists('Picea\\Asset\\Asset') ) { + ( new Asset() )->registerExtension($compiler); + + } } }); diff --git a/skeleton/lean b/skeleton/lean new file mode 100755 index 0000000..c1e8d30 --- /dev/null +++ b/skeleton/lean @@ -0,0 +1,9 @@ +#!/bin/php +<?php + +try { + require_once(__DIR__."/src/Kernel.php"); +} +catch(\Throwable $t) { + echo sprintf("%s [ %s ]" , $t->getMessage(), var_export($t->getTrace(), true)); +} \ No newline at end of file diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index f9179b1..21e3a77 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -51,7 +51,11 @@ trait ControllerTrait { public function renderRawView(string $view, ?array $variables = null) : string { - return $this->picea->renderHtml($view, $variables ?? [], $this); + if ( null === $content = $this->picea->renderHtml($view, $variables ?? [], $this) ) { + throw new \RuntimeException("Picea's renderHtml() returned NULL as result ; an error occured within your template `$view`."); + } + + return $content; } public function renderView(string $view, ?array $variables = null) : ResponseInterface