- 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) {
|
||||
return function (ContainerInterface $container) {
|
||||
|
|
|
@ -29,6 +29,8 @@ return [
|
|||
'order' => 99,
|
||||
],
|
||||
],
|
||||
|
||||
'extensions' => [],
|
||||
],
|
||||
|
||||
'ulmus' => [],
|
||||
|
@ -60,7 +62,7 @@ return [
|
|||
Lean::class => autowire(Lean::class),
|
||||
|
||||
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')));
|
||||
});
|
||||
|
||||
|
@ -82,11 +84,13 @@ return [
|
|||
|
||||
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ( false !== ( $currentBranch = file_get_contents( $gitdir . "HEAD") ) ) {
|
||||
$file = explode(": ", $currentBranch)[1];
|
||||
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
|
||||
if ( file_exists($gitdir . "HEAD") ) {
|
||||
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
|
||||
$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";
|
||||
|
|
|
@ -32,14 +32,14 @@ return [
|
|||
},
|
||||
|
||||
Compiler::class => function($c) {
|
||||
return new Compiler(new class(null, [
|
||||
return new Compiler(new class(array_merge([
|
||||
$c->get(LanguageExtension::class),
|
||||
$c->get(TitleExtension::class),
|
||||
$c->get(UrlExtension::class),
|
||||
$c->get(Method\Form::class),
|
||||
$c->get(Method\Pagination::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
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ return [
|
|||
|
||||
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) {
|
||||
return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"pagination": {
|
||||
"next": "Next >",
|
||||
"previous": "< Previous",
|
||||
"next": ">",
|
||||
"previous": "<",
|
||||
"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 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'];
|
||||
}
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
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' => [] )");
|
||||
}
|
||||
|
||||
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));
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
<nav class="pagination-wrapper">
|
||||
<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>
|
||||
|
||||
{% 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>
|
||||
{% 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>
|
||||
</ul>
|
||||
</nav>
|
Loading…
Reference in New Issue