Compare commits

...

3 Commits

12 changed files with 143 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator }; use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator, MethodNotAllowedInterface, };
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
@ -17,4 +17,5 @@ return [
EmitterInterface::class => create(SapiEmitter::class), EmitterInterface::class => create(SapiEmitter::class),
ThrowableHandlerInterface::class => autowire(ThrowableHandler::class), ThrowableHandlerInterface::class => autowire(ThrowableHandler::class),
NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class), NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class),
# MethodNotAllowedInterface::class => autowire(MethodNotAllowedDecorator::class),
]; ];

View File

@ -5,6 +5,15 @@
"week": "week" "week": "week"
}, },
"interval": {
"years": "{$years} year(s)",
"months": "{$months} month(s)",
"days": "{$days} day(s)",
"hours": "{$hours} hour(s)",
"minutes": "{$minutes} minutes(s)",
"seconds": "{$seconds} second(s)"
},
"month": { "month": {
"list": [ "list": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember" "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember"

View File

@ -4,6 +4,15 @@
"week": "semaine" "week": "semaine"
}, },
"interval": {
"years": "{$years} années(s)",
"months": "{$months} mois",
"days": "{$days} jour(s)",
"hours": "{$hours} heure(s)",
"minutes": "{$minutes} minutes(s)",
"seconds": "{$seconds} seconde(s)"
},
"month": { "month": {
"list": [ "list": [
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"

View File

@ -7,6 +7,10 @@ use function DI\{ autowire, add, create, get };
$dir = dirname(__DIR__, 2); $dir = dirname(__DIR__, 2);
return [ return [
\%NAMESPACE%\Factory\FormFactoryInterface::class => autowire(\%NAMESPACE%\Factory\FormFactory::class),
\Lean\Api\Factory\MessageFactoryInterface::class => autowire(\%NAMESPACE%\Lib\Message::class),
'%APPKEY%' => [ '%APPKEY%' => [
'picea' => [ 'picea' => [
'context' => "%ESCAPED_NAMESPACE%\\View", 'context' => "%ESCAPED_NAMESPACE%\\View",

View File

@ -0,0 +1,46 @@
<?php
namespace %NAMESPACE%\Factory;
use Lean\Api\Factory\MessageFactoryInterface;
use Lean\LanguageHandler;
use Picea\Ui\Method\FormContextInterface;
use Picea\Ui\Method\FormInterface;
use Psr\Http\Message\ServerRequestInterface;
use Storage\Session;
use Ulmus\Entity\EntityInterface;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authenticate;
class FormFactory implements FormFactoryInterface
{
/*
public function __construct(
protected ServerRequestInterface $request,
protected Authenticate $authenticate,
protected Session $session,
protected LanguageHandler $languageHandler,
protected MessageFactoryInterface $messageFactory,
) {}
public function save(EntityInterface $entity): FormInterface
{
return new Form\Save($this->languageHandler, $this->messageFactory, $entity);
}
public function saveContext(? ServerRequestInterface $request = null, ? string $formName = null): FormContextInterface
{
return new Form\SaveContext($request ?: $this->request, $formName);
}
public function delete(EntityInterface $entity): FormInterface
{
return new Form\Delete($this->languageHandler, $this->messageFactory, $entity);
}
public function deleteContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface
{
return new Lib\FormContext($request, $formName);
}
*/
}

View File

@ -0,0 +1,25 @@
<?php
namespace %NAMESPACE%\Factory;
use Lean\Api\Factory\MessageFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Picea\Ui\Method\{ FormInterface, FormContextInterface };
use Storage\Session;
use Lean\LanguageHandler;
use Ulmus\Entity\EntityInterface;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authenticate;
interface FormFactoryInterface
{
/* public function __construct(ServerRequestInterface $request, Authenticate $authenticate, Session $session, LanguageHandler $languageHandler, MessageFactoryInterface $messageFactory,);
public function save(EntityInterface $entity): FormInterface;
public function saveContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface;
public function delete(EntityInterface $entity): FormInterface;
public function deleteContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface;*/
}

View File

@ -2,8 +2,10 @@
namespace Lean; namespace Lean;
use League\Route\Http\Exception\MethodNotAllowedException;
use League\Route\Strategy; use League\Route\Strategy;
use League\Route\Http\Exception\NotFoundException; use League\Route\Http\Exception\NotFoundException;
use Lean\ApplicationStrategy\MethodNotAllowedInterface;
use Lean\ApplicationStrategy\NotFoundDecoratorInterface; use Lean\ApplicationStrategy\NotFoundDecoratorInterface;
use Lean\ApplicationStrategy\ThrowableHandlerInterface; use Lean\ApplicationStrategy\ThrowableHandlerInterface;
use Lean\Factory\HttpFactoryInterface; use Lean\Factory\HttpFactoryInterface;
@ -31,4 +33,9 @@ class ApplicationStrategy extends Strategy\ApplicationStrategy {
{ {
return $this->getContainer()->get(ThrowableHandlerInterface::class); return $this->getContainer()->get(ThrowableHandlerInterface::class);
} }
public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception): MiddlewareInterface
{
return $this->getContainer()->has(MethodNotAllowedInterface::class) ? $this->getContainer()->get(MethodNotAllowedInterface::class) : parent::getMethodNotAllowedDecorator($exception);
}
} }

View File

@ -0,0 +1,10 @@
<?php
namespace Lean\ApplicationStrategy;
use Psr\Http\Server\MiddlewareInterface;
interface MethodNotAllowedInterface extends MiddlewareInterface
{
}

View File

@ -8,6 +8,7 @@ use Notes\Attribute\Ignore;
use Notes\Route\Attribute\Object\Route; use Notes\Route\Attribute\Object\Route;
use Notes\Security\Attribute\Security; use Notes\Security\Attribute\Security;
use Picea, Picea\Ui\Method\FormContext; use Picea, Picea\Ui\Method\FormContext;
use Picea\Ui\Method\FormContextInterface;
use TheBugs\Email\MailerInterface; use TheBugs\Email\MailerInterface;
use Storage\{ Cookie, Session }; use Storage\{ Cookie, Session };
use League\CommonMark\CommonMarkConverter; use League\CommonMark\CommonMarkConverter;
@ -212,7 +213,7 @@ trait ControllerTrait {
} }
#[Ignore] #[Ignore]
public function pushContext(FormContext $context) : FormContext public function pushContext(FormContextInterface $context) : FormContextInterface
{ {
$this->contextList[$context->formName ?? uniqid("context_")] = $context; $this->contextList[$context->formName ?? uniqid("context_")] = $context;
@ -220,7 +221,7 @@ trait ControllerTrait {
} }
#[Ignore] #[Ignore]
public function context(? string $name = null) : ? FormContext public function context(? string $name = null) : ? FormContextInterface
{ {
return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null; return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null;
} }

View File

@ -27,18 +27,15 @@ class Kernel {
public array $paths = []; public array $paths = [];
public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE; public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE;
public array $definitionFilePaths; public array $definitionFilePaths;
public string $errorLogPath; public string $errorLogPath;
public string $projectPath; public function __construct(
public string $projectPath
public function __construct(string $projectPath) ) {
{
$this->projectPath = $projectPath;
$this->setEnvironment(); $this->setEnvironment();
$this->initializeEngine(); $this->initializeEngine();
$this->setupContainer(); $this->setupContainer();

View File

@ -0,0 +1,23 @@
{% arguments \DateInterval $interval %}
{% if $interval->y %}
{% lang "lean.date.interval.years", [ 'years' => $interval->y ] %},
{% endif %}
{% if $interval->m %}
{% lang "lean.date.interval.months", [ 'months' => $interval->m ] %},
{% endif %}
{% if $interval->d %}
{% lang "lean.date.interval.days", [ 'days' => $interval->d ] %},
{% endif %}
{% if $interval->h %}
{% lang "lean.date.interval.hours", [ 'hours' => $interval->h ] %},
{% endif %}
{% if $interval->i %}
{% lang "lean.date.interval.minutes", [ 'minutes' => $interval->i ] %}
{% else %}
{% lang "lean.date.interval.seconds", [ 'seconds' => $interval->s ] %}
{% endif %}