- A lot of fixes done on this for a test project.

This commit is contained in:
mcndave committed 2021-02-16 03:10:04 +00:00
1 parent 52e55f2bba
commit 09b3e47c19
11 files changed
+78 -21

No files matched your search

+6
View File
@@ -8,6 +8,8 @@ class Application
{
public string $piceaContext;
public array $piceaExtensions;
public array $views;
public array $routes;
@@ -25,6 +27,10 @@ class Application
$this->piceaContext = $picea['context'];
}
if ($picea['extensions'] ?? false ) {
$this->piceaExtensions = $picea['extensions'];
}
if ($picea['view'] ?? false) {
$this->views = $picea['view'];
}
+13 -1
View File
@@ -2,6 +2,8 @@
namespace Lean;
use CSLSJ\Common\RequestResponse\DownloadResponse;
use CSLSJ\Common\RequestResponse\ImageResponse;
use Picea,
Picea\Ui\Method\FormContext;
@@ -35,7 +37,7 @@ trait ControllerTrait {
public ? MailerInterface $mailer;
public array $contextList = [];
#medias
public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface
{
foreach($entityClass::repository()->filterServerRequest( $entityClass::searchRequest()->fromRequest($request->withQueryParams($request->getQueryParams() + ['limit' => PHP_INT_MAX,])) )->loadAll() as $entity) {
@@ -76,6 +78,16 @@ trait ControllerTrait {
return new JsonResponse($data, $code, $headers);
}
public static function renderDownloadable(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
{
return new DownloadResponse($data, $filename, $code, $headers);
}
public static function renderImage(string $data, int $code = 200, array $headers = []) : ResponseInterface
{
return new ImageResponse($data, $code, $headers);
}
public function fromResponse(ResponseInterface $response)
{
if ( $response->getStatusCode() === 200 ) {
+10 -3
View File
@@ -11,6 +11,7 @@ use League\Route\Strategy\ApplicationStrategy;
use Psr\Http\Message\ServerRequestInterface;
use Tell\I18n;
use Ulmus\Container\AdapterProxy;
use Zend\Diactoros\ServerRequestFactory,
@@ -82,7 +83,7 @@ class Kernel {
ini_set("log_errors", "1");
ini_set("error_log", $this->errorLogPath);
ini_set('display_errors', getenv("DEBUG") ? 'on' : 'off');
ini_set('display_errors', getenv("DEBUG") ? 'on' : 'on');
error_reporting($this->errorReporting);
@@ -95,8 +96,8 @@ class Kernel {
if (getenv("APP_ENV") === "prod") {
if (getenv("CACHE_PATH")) {
$containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/");
$containerBuilder->writeProxiesToFile(true);
# $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/");
# $containerBuilder->writeProxiesToFile(true);
}
}
@@ -116,6 +117,12 @@ class Kernel {
$this->container->has(AdapterProxy::class) and $this->container->get(AdapterProxy::class);
$this->container->has(Lean::class) and $this->container->get(Lean::class);
if ($this->container->has(I18n::class)) {
$i18n = $this->container->get(I18n::class);
$i18n->locale($this->locale);
$i18n->initialize(!getenv("DEBUG"));
}
return $this;
}
+14 -1
View File
@@ -28,7 +28,7 @@ class Lean
throw new \Exception("You must provide at least one application to autoload within your config file ( 'lean' => 'autoload' => [] )");
}
foreach($list as $application) {
foreach(array_filter($list) as $application) {
if ( $this->container->has($application) ) {
$this->applications[] = ( new Application() )->fromArray($this->container->get($application));
}
@@ -49,6 +49,19 @@ class Lean
return static::DEFAULT_PICEA_CONTEXT;
}
public function getPiceaExtensions() : array
{
$list = [];
foreach(array_reverse($this->applications) as $apps) {
if ( $apps->piceaExtensions ?? null ) {
$list = array_merge($list, $apps->piceaExtensions);
}
}
return $list;
}
public function getRoutable() : array
{
return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));
+11 -4
View File
@@ -17,7 +17,8 @@ use Notes\Security\SecurityHandler;
use Notes\Tell\LanguageHandler;
use Picea\Extension\UrlExtension;
use Picea\Picea,
Picea\Extension\UrlExtension;
use Storage\Cookie,
Storage\Session;
@@ -75,8 +76,8 @@ class Routing {
# $container->set($class, autowire($class)->method($method, $request));
if ( null !== ( $annotation = $this->language->verify($class) ) ) {
if ( $annotation->key ) {
if ( null !== ( $languageAnnotation = $this->language->verify($class) ) ) {
if ( $languageAnnotation->key ) {
# TODO !!! $language
}
}
@@ -85,10 +86,16 @@ class Routing {
# Checking if user needs to be logged
if ( ! $object->user->logged && ( $redirect = $this->security->verify($class, $method) ) ) {
$this->session->redirectedFrom = (string) $request->getUri();
return $redirect;
}
return $object->$method($request, $arguments);
if ( $container->has(Picea::class) ) {
$container->get(Picea::class)->globalVariables['route'] = $annotation;
}
return $object->$method($request->withAttribute('lean.route', $annotation), $arguments);
});
}
}