- A lot of fixes done on this for a test project.
This commit is contained in:
parent
52e55f2bba
commit
09b3e47c19
|
@ -68,7 +68,7 @@ return [
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
'routes.middlewares' => [ "errorHandler", "dump", SessionMiddleware::class, CronardMiddleware::class, HttpBasicAuthentication::class, JavascriptMiddleware::class ],
|
'routes.middlewares' => [ "dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, HttpBasicAuthentication::class, JavascriptMiddleware::class ],
|
||||||
|
|
||||||
'routes.list' => function($c) {
|
'routes.list' => function($c) {
|
||||||
return function (ContainerInterface $container) {
|
return function (ContainerInterface $container) {
|
||||||
|
|
|
@ -29,6 +29,8 @@ return [
|
||||||
'order' => 99,
|
'order' => 99,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'extensions' => [],
|
||||||
],
|
],
|
||||||
|
|
||||||
'ulmus' => [],
|
'ulmus' => [],
|
||||||
|
@ -60,7 +62,7 @@ return [
|
||||||
Lean::class => autowire(Lean::class),
|
Lean::class => autowire(Lean::class),
|
||||||
|
|
||||||
CronardMiddleware::class => function($c) {
|
CronardMiddleware::class => function($c) {
|
||||||
$cronardMiddleware = new CronardMiddleware(getenv('CRON_KEY'), function() : ResponseInterface {
|
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
|
||||||
return new TextResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
return new TextResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -82,11 +84,13 @@ return [
|
||||||
|
|
||||||
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
|
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
if ( false !== ( $currentBranch = file_get_contents( $gitdir . "HEAD") ) ) {
|
if ( file_exists($gitdir . "HEAD") ) {
|
||||||
$file = explode(": ", $currentBranch)[1];
|
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
|
||||||
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
|
$file = explode(": ", $currentBranch)[1];
|
||||||
|
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
|
||||||
|
|
||||||
return trim(file_get_contents( $path ), " \t\n\r");
|
return trim(file_get_contents($path), " \t\n\r");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "gitless-project";
|
return "gitless-project";
|
||||||
|
|
|
@ -32,14 +32,14 @@ return [
|
||||||
},
|
},
|
||||||
|
|
||||||
Compiler::class => function($c) {
|
Compiler::class => function($c) {
|
||||||
return new Compiler(new class(null, [
|
return new Compiler(new class(array_merge([
|
||||||
$c->get(LanguageExtension::class),
|
$c->get(LanguageExtension::class),
|
||||||
$c->get(TitleExtension::class),
|
$c->get(TitleExtension::class),
|
||||||
$c->get(UrlExtension::class),
|
$c->get(UrlExtension::class),
|
||||||
$c->get(Method\Form::class),
|
$c->get(Method\Form::class),
|
||||||
$c->get(Method\Pagination::class),
|
$c->get(Method\Pagination::class),
|
||||||
$c->get(Request::class),
|
$c->get(Request::class),
|
||||||
]) extends DefaultRegistrations {
|
], array_map(fn($class) => $c->get($class), $c->get(Lean\Lean::class)->getPiceaExtensions() ))) extends DefaultRegistrations {
|
||||||
|
|
||||||
public function registerAll(Compiler $compiler) : void
|
public function registerAll(Compiler $compiler) : void
|
||||||
{
|
{
|
||||||
|
@ -56,7 +56,7 @@ return [
|
||||||
|
|
||||||
Method\Pagination::class => autowire(Method\Pagination::class),
|
Method\Pagination::class => autowire(Method\Pagination::class),
|
||||||
|
|
||||||
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(Context::class), get(LanguageHandler::class)),
|
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(LanguageHandler::class)),
|
||||||
|
|
||||||
LanguageHandler::class => function($c) {
|
LanguageHandler::class => function($c) {
|
||||||
return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler {
|
return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"next": "Next >",
|
"next": ">",
|
||||||
"previous": "< Previous",
|
"previous": "<",
|
||||||
"shown": "elements shown"
|
"shown": "elements shown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"pagination": {
|
||||||
|
"next": ">",
|
||||||
|
"previous": "<",
|
||||||
|
"shown": "éléments affichés"
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ class Application
|
||||||
{
|
{
|
||||||
public string $piceaContext;
|
public string $piceaContext;
|
||||||
|
|
||||||
|
public array $piceaExtensions;
|
||||||
|
|
||||||
public array $views;
|
public array $views;
|
||||||
|
|
||||||
public array $routes;
|
public array $routes;
|
||||||
|
@ -25,6 +27,10 @@ class Application
|
||||||
$this->piceaContext = $picea['context'];
|
$this->piceaContext = $picea['context'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($picea['extensions'] ?? false ) {
|
||||||
|
$this->piceaExtensions = $picea['extensions'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($picea['view'] ?? false) {
|
if ($picea['view'] ?? false) {
|
||||||
$this->views = $picea['view'];
|
$this->views = $picea['view'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Lean;
|
namespace Lean;
|
||||||
|
|
||||||
|
use CSLSJ\Common\RequestResponse\DownloadResponse;
|
||||||
|
use CSLSJ\Common\RequestResponse\ImageResponse;
|
||||||
use Picea,
|
use Picea,
|
||||||
Picea\Ui\Method\FormContext;
|
Picea\Ui\Method\FormContext;
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ trait ControllerTrait {
|
||||||
public ? MailerInterface $mailer;
|
public ? MailerInterface $mailer;
|
||||||
|
|
||||||
public array $contextList = [];
|
public array $contextList = [];
|
||||||
#medias
|
|
||||||
public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface
|
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) {
|
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);
|
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)
|
public function fromResponse(ResponseInterface $response)
|
||||||
{
|
{
|
||||||
if ( $response->getStatusCode() === 200 ) {
|
if ( $response->getStatusCode() === 200 ) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ use League\Route\Strategy\ApplicationStrategy;
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
use Tell\I18n;
|
||||||
use Ulmus\Container\AdapterProxy;
|
use Ulmus\Container\AdapterProxy;
|
||||||
|
|
||||||
use Zend\Diactoros\ServerRequestFactory,
|
use Zend\Diactoros\ServerRequestFactory,
|
||||||
|
@ -82,7 +83,7 @@ class Kernel {
|
||||||
|
|
||||||
ini_set("log_errors", "1");
|
ini_set("log_errors", "1");
|
||||||
ini_set("error_log", $this->errorLogPath);
|
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);
|
error_reporting($this->errorReporting);
|
||||||
|
|
||||||
|
@ -95,8 +96,8 @@ class Kernel {
|
||||||
|
|
||||||
if (getenv("APP_ENV") === "prod") {
|
if (getenv("APP_ENV") === "prod") {
|
||||||
if (getenv("CACHE_PATH")) {
|
if (getenv("CACHE_PATH")) {
|
||||||
$containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/");
|
# $containerBuilder->enableCompilation(getenv("CACHE_PATH") . "/di/");
|
||||||
$containerBuilder->writeProxiesToFile(true);
|
# $containerBuilder->writeProxiesToFile(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +117,12 @@ class Kernel {
|
||||||
$this->container->has(AdapterProxy::class) and $this->container->get(AdapterProxy::class);
|
$this->container->has(AdapterProxy::class) and $this->container->get(AdapterProxy::class);
|
||||||
$this->container->has(Lean::class) and $this->container->get(Lean::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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/Lean.php
15
src/Lean.php
|
@ -28,7 +28,7 @@ class Lean
|
||||||
throw new \Exception("You must provide at least one application to autoload within your config file ( 'lean' => 'autoload' => [] )");
|
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) ) {
|
if ( $this->container->has($application) ) {
|
||||||
$this->applications[] = ( new Application() )->fromArray($this->container->get($application));
|
$this->applications[] = ( new Application() )->fromArray($this->container->get($application));
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,19 @@ class Lean
|
||||||
return static::DEFAULT_PICEA_CONTEXT;
|
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
|
public function getRoutable() : array
|
||||||
{
|
{
|
||||||
return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));
|
return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications));
|
||||||
|
|
|
@ -17,7 +17,8 @@ use Notes\Security\SecurityHandler;
|
||||||
|
|
||||||
use Notes\Tell\LanguageHandler;
|
use Notes\Tell\LanguageHandler;
|
||||||
|
|
||||||
use Picea\Extension\UrlExtension;
|
use Picea\Picea,
|
||||||
|
Picea\Extension\UrlExtension;
|
||||||
|
|
||||||
use Storage\Cookie,
|
use Storage\Cookie,
|
||||||
Storage\Session;
|
Storage\Session;
|
||||||
|
@ -75,8 +76,8 @@ class Routing {
|
||||||
|
|
||||||
# $container->set($class, autowire($class)->method($method, $request));
|
# $container->set($class, autowire($class)->method($method, $request));
|
||||||
|
|
||||||
if ( null !== ( $annotation = $this->language->verify($class) ) ) {
|
if ( null !== ( $languageAnnotation = $this->language->verify($class) ) ) {
|
||||||
if ( $annotation->key ) {
|
if ( $languageAnnotation->key ) {
|
||||||
# TODO !!! $language
|
# TODO !!! $language
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,10 +86,16 @@ class Routing {
|
||||||
|
|
||||||
# Checking if user needs to be logged
|
# Checking if user needs to be logged
|
||||||
if ( ! $object->user->logged && ( $redirect = $this->security->verify($class, $method) ) ) {
|
if ( ! $object->user->logged && ( $redirect = $this->security->verify($class, $method) ) ) {
|
||||||
|
$this->session->redirectedFrom = (string) $request->getUri();
|
||||||
|
|
||||||
return $redirect;
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,14 @@
|
||||||
|
|
||||||
<nav class="pagination-wrapper">
|
<nav class="pagination-wrapper">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
|
<li class="page-item {{ $page === 1 ? 'disabled' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $page - 1 ] + get() %}">{% lang "lean.widget.pagination.previous" %}</a></li>
|
||||||
|
|
||||||
<li class="page-item {{ $page === 1 ? 'active' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => 1 ] + get() %}">1</a></li>
|
<li class="page-item {{ $page === 1 ? 'active' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => 1 ] + get() %}">1</a></li>
|
||||||
|
|
||||||
{% foreach range(2, $pageCount < $maxPage ? $pageCount : $maxPage) as $pageIndex %}
|
{% foreach range(2, $pageCount < $maxPage ? $pageCount : $maxPage) as $pageIndex %}
|
||||||
<li class="page-item {{ $page === $pageIndex ? 'active' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $pageIndex ] + get() %}">{{ $pageIndex }}</a></li>
|
<li class="page-item {{ $page === $pageIndex ? 'active' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $pageIndex ] + get() %}">{{ $pageIndex }}</a></li>
|
||||||
{% endforeach %}
|
{% endforeach %}
|
||||||
|
|
||||||
<li class="page-item {{ $page === 1 ? 'disabled' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $page - 1 ] + get() %}">{% lang "lean.widget.pagination.previous" %}</a></li>
|
|
||||||
<li class="page-item {{ $page === $pageCount ? 'disabled' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $page + 1 ] + get() %}">{% lang "lean.widget.pagination.next" %}</a></li>
|
<li class="page-item {{ $page === $pageCount ? 'disabled' : '' }}"><a class="page-link" href="{% url.parameters $url, [ 'page' => $page + 1 ] + get() %}">{% lang "lean.widget.pagination.next" %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
Loading…
Reference in New Issue