- Worked th error layout
- Added some picto for the error views - Bugfixes
This commit is contained in:
1 parent
421024f260
commit
fd693fc8fc
15 files changed
+101
-18
No files matched your search
+10
-4
@@ -10,7 +10,7 @@ use Picea,
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Storage\Session;
|
||||
|
||||
use Laminas\Diactoros\Response\{ HtmlResponse, TextResponse, RedirectResponse, JsonResponse };
|
||||
use Laminas\Diactoros\Response\{ HtmlResponse, TextResponse, RedirectResponse, JsonResponse, EmptyResponse };
|
||||
|
||||
use Ulmus\EntityCollection;
|
||||
|
||||
@@ -21,12 +21,13 @@ use TheBugs\Email\MailerInterface;
|
||||
use Notes\Route\Annotation\Object\Route as RouteParam,
|
||||
Notes\Route\Annotation\Method\Route,
|
||||
Notes\Security\Annotation\Security,
|
||||
Notes\Security\Annotation\Taxus,
|
||||
Notes\Tell\Annotation\Language;
|
||||
|
||||
use function file_get_contents;
|
||||
|
||||
/**
|
||||
* @Security("locked" => false)
|
||||
* @Security("locked" => true)
|
||||
* @RouteParam("methods" => [ "GET", "POST", "DELETE" ])
|
||||
*/
|
||||
trait ControllerTrait {
|
||||
@@ -68,9 +69,9 @@ trait ControllerTrait {
|
||||
return new RedirectResponse($url, $code, $headers);
|
||||
}
|
||||
|
||||
public function renderPdf($rawdata, int $status = 200, array $headers = []) : PdfResponse
|
||||
public static function renderNothing(int $code = 204, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new PdfResponse($rawdata, $status, $headers);
|
||||
return new EmptyResponse($code, $headers);
|
||||
}
|
||||
|
||||
public static function renderText(string $text, int $code = 200, array $headers = []) : ResponseInterface
|
||||
@@ -88,6 +89,11 @@ trait ControllerTrait {
|
||||
return new JsonResponse($data, $code, $headers);
|
||||
}
|
||||
|
||||
public function renderPdf($rawdata, int $status = 200, array $headers = []) : PdfResponse
|
||||
{
|
||||
return new PdfResponse($rawdata, $status, $headers);
|
||||
}
|
||||
|
||||
public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
|
||||
{
|
||||
return new DownloadResponse($data, $filename, $code, $headers);
|
||||
|
||||
+17
-7
@@ -58,19 +58,25 @@ class Kernel {
|
||||
// Environment vars (accessible from \DI\env(), getenv(), $_ENV and $_SERVER)
|
||||
Dotenv::create(getenv("PROJECT_PATH"))->load();
|
||||
|
||||
// Paths and directories
|
||||
foreach($this->paths as $name => $envkey) {
|
||||
if ( ! getenv($name) ) {
|
||||
static::putenv($name, realpath(getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey)));
|
||||
}
|
||||
}
|
||||
|
||||
// Override using headers
|
||||
foreach(['APP_ENV', 'DEBUG', ] as $env) {
|
||||
if ( null !== $value = $_SERVER["HTTP_$env"] ?? null ) {
|
||||
static::putenv($env, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Paths and directories
|
||||
foreach($this->paths as $name => $envkey) {
|
||||
if ( ! getenv($name) ) {
|
||||
$path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey);
|
||||
|
||||
if (getenv('DEBUG') && ! file_exists($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
|
||||
static::putenv($name, realpath($path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function initializeEngine() : self
|
||||
@@ -81,6 +87,10 @@ class Kernel {
|
||||
setlocale(LC_ALL, $this->locale = getenv("DEFAULT_LOCAL"));
|
||||
setlocale(LC_TIME, getenv("DEFAULT_TIME"), getenv("DEFAULT_TIME_FALLBACK"));
|
||||
|
||||
if ( class_exists('Locale') ) {
|
||||
\Locale::setDefault($this->locale);
|
||||
}
|
||||
|
||||
ini_set("log_errors", "1");
|
||||
ini_set("error_log", $this->errorLogPath);
|
||||
ini_set('display_errors', getenv("DEBUG") ? 'on' : 'on');
|
||||
|
||||
+13
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Lean;
|
||||
|
||||
use function DI\autowire, DI\create;
|
||||
use Taxus\Taxus;
|
||||
|
||||
use League\Route\RouteGroup,
|
||||
League\Route\Router;
|
||||
@@ -23,6 +23,8 @@ use Picea\Picea,
|
||||
use Storage\Cookie,
|
||||
Storage\Session;
|
||||
|
||||
use function DI\autowire, DI\create;
|
||||
|
||||
class Routing {
|
||||
|
||||
protected Session $session;
|
||||
@@ -37,6 +39,8 @@ class Routing {
|
||||
|
||||
protected LanguageHandler $language;
|
||||
|
||||
protected Taxus $taxus;
|
||||
|
||||
public function __construct(
|
||||
Session $session,
|
||||
Cookie $cookie,
|
||||
@@ -44,7 +48,8 @@ class Routing {
|
||||
Router $router,
|
||||
RouteFetcher $routeFetcher,
|
||||
SecurityHandler $security,
|
||||
LanguageHandler $language
|
||||
LanguageHandler $language,
|
||||
Taxus $taxus
|
||||
)
|
||||
{
|
||||
$this->session = $session;
|
||||
@@ -54,6 +59,7 @@ class Routing {
|
||||
$this->security = $security;
|
||||
$this->language = $language;
|
||||
$this->router = $router;
|
||||
$this->taxus = $taxus;
|
||||
}
|
||||
|
||||
public function registerRoute(ContainerInterface $container, string $urlBase) {
|
||||
@@ -84,12 +90,16 @@ class Routing {
|
||||
$object = $container->get($class);
|
||||
|
||||
# Checking if user needs to be logged
|
||||
if ( ! $object->user->logged && ( $redirect = $this->security->verify($class, $method) ) ) {
|
||||
if ( ( $redirect = $this->security->verify($class, $method) ) && ( empty($object->user) || ! $object->user->logged ) ) {
|
||||
$this->session->redirectedFrom = (string) $request->getUri();
|
||||
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
if ( $forbidden = $this->security->taxus($class, $method, $object->user) ) {
|
||||
return $forbidden;
|
||||
}
|
||||
|
||||
if ( $container->has(Picea::class) ) {
|
||||
$container->get(Picea::class)->globalVariables['route'] = $annotation;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user