- 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:
mcndave committed 2021-03-01 16:01:27 +00:00
1 parent 09b3e47c19
commit 01bb926ca7
30 files changed
+887 -2

No files matched your search

+33
View File
@@ -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();
}
}
+7
View File
@@ -0,0 +1,7 @@
<?php
namespace %NAMESPACE%\Lib;
trait EntityTrait {
use \Ulmus\EntityTrait;
}
+5
View File
@@ -0,0 +1,5 @@
<?php
namespace %NAMESPACE%\Lib;
class FormContext extends \Picea\Ui\Method\FormContext { }
+103
View File
@@ -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);
}
}