- Added a new Email defintion (which will soon see it's components changed)
- Added a new post-install script for composer which adds a project skeleton "ready to use". - Error 500 are now handled properly in production; waiting to see if adjustements will be required before adding other code pages.
This commit is contained in:
1 parent
09b3e47c19
commit
01bb926ca7
30 files changed
+887
-2
No files matched your search
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Controller;
|
||||
|
||||
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface };
|
||||
|
||||
use %NAMESPACE%\{ Lib, Entity, Form, };
|
||||
|
||||
use function %NAMESPACE%\View\{ _, lang, url, route, form };
|
||||
|
||||
/**
|
||||
* @Language("%APPKEY%.home")
|
||||
*/
|
||||
class Home {
|
||||
use Lib\ControllerTrait;
|
||||
|
||||
/**
|
||||
* @Route("/", "name" => "home")
|
||||
*/
|
||||
public function index(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
form(new Form\Form(), $this->pushContext(new Lib\FormContext($request, "form.name")));
|
||||
|
||||
return $this->renderView('home');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Entity;
|
||||
|
||||
use Ulmus\Entity\Field\Datetime;
|
||||
|
||||
use %NAMESPACE%\Lib;
|
||||
|
||||
/**
|
||||
* # Table('name' => "user")
|
||||
*/
|
||||
class User extends \Ulmus\User\Entity\User implements \JsonSerializable
|
||||
{
|
||||
use Lib\EntityTrait;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Form;
|
||||
|
||||
use %NAMESPACE%\{ Lib, Entity };
|
||||
use Picea\Ui\Method\{ FormContextInterface, Message\ErrorMessage };
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use function %NAMESPACE%\View\{ lang };
|
||||
|
||||
class Form implements \Picea\Ui\Method\FormInterface {
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
public function execute(FormContextInterface $context) : void
|
||||
{
|
||||
$context->pushMessage(Message::generateSuccess(
|
||||
lang("form.success")
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace %NAMESPACE%;
|
||||
|
||||
use Ulmus\ConnectionAdapter;
|
||||
|
||||
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
new class(dirname(__DIR__)) extends \Lean\Kernel {
|
||||
|
||||
public array $paths = [
|
||||
'CACHE_PATH' => "CACHE_DIR",
|
||||
'LOGS_PATH' => "LOGS_DIR",
|
||||
'META_PATH' => "META_DIR",
|
||||
'PUBLIC_PATH' => "PUBLIC_DIR",
|
||||
'PRIVATE_PATH' => "PRIVATE_DIR",
|
||||
'VIEW_PATH' => "VIEW_DIR",
|
||||
];
|
||||
|
||||
protected function initializeEngine() : self
|
||||
{
|
||||
$this->errorLogPath = getenv("LOGS_PATH") . DIRECTORY_SEPARATOR. date("Y-m").".log";
|
||||
|
||||
$this->definitionFilePath = implode(DIRECTORY_SEPARATOR, [ getenv('META_PATH'), 'definitions', 'definitions.php' ]);
|
||||
|
||||
return parent::initializeEngine();
|
||||
}
|
||||
|
||||
protected function serviceContainer() : self
|
||||
{
|
||||
# $this->container->get(ConnectionAdapter::class);
|
||||
|
||||
return parent::serviceContainer();
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Lib;
|
||||
|
||||
use Picea\Picea;
|
||||
use Storage\Session;
|
||||
use Ulmus\User\Entity\User;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
use %NAMESPACE%\Entity;
|
||||
|
||||
/**
|
||||
* @Security("locked" => false)
|
||||
* @RouteParam("methods" => [ "GET", "POST" ])
|
||||
*/
|
||||
trait ControllerTrait {
|
||||
use \Lean\ControllerTrait;
|
||||
|
||||
public ? \Ulmus\User\Entity\User $user;
|
||||
|
||||
protected Authenticate $authenticate;
|
||||
|
||||
public function __construct(Picea $picea, Session $session, Authenticate $authenticate) {
|
||||
$this->initializeController($picea, $session, $authenticate);
|
||||
}
|
||||
|
||||
public function initializeController(Picea $picea, Session $session, Authenticate $authenticate) {
|
||||
$this->picea = $picea;
|
||||
$this->authenticate = $authenticate;
|
||||
$this->session = $session;
|
||||
$this->user = $authenticate->rememberMe( Entity\User::repository() ) ?: new User();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Lib;
|
||||
|
||||
trait EntityTrait {
|
||||
use \Ulmus\EntityTrait;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Lib;
|
||||
|
||||
class FormContext extends \Picea\Ui\Method\FormContext { }
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace %NAMESPACE%\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 is-{$this->class}" role="alert">
|
||||
<div class="message-body">
|
||||
<strong>{$this->header}</strong>
|
||||
<span>{$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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\Middleware;
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use Storage\Session;
|
||||
|
||||
class Authentication implements MiddlewareInterface {
|
||||
|
||||
public Session $session;
|
||||
|
||||
public string $sessionUserVariable = 'user';
|
||||
|
||||
public ResponseInterface $loginRedirect;
|
||||
|
||||
public function __construct(ResponseInterface $loginRedirect, Session $session)
|
||||
{
|
||||
$this->loginRedirect = $loginRedirect;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Middleware request handling
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||
{
|
||||
$user = $this->session->get( $this->sessionUserVariable() );
|
||||
|
||||
if ( ! $user ) {
|
||||
return $this->loginRedirect;
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter / setter of Session User Variable
|
||||
*
|
||||
* @param string|null sessionUserVariable
|
||||
* @return mixed
|
||||
*/
|
||||
public function sessionUserVariable(?string $set = null) : string
|
||||
{
|
||||
return $set !== null ? $this->sessionUserVariable = $set : $this->sessionUserVariable;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user