- Added the application feature - a big reason why Lean was created in the first place.
- Began moving some repetitive parts from projects to projects into lean
This commit is contained in:
1 parent
4bd68a74f8
commit
bdb9f7f732
13 files changed
+571
-2
No files matched your search
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use Zend\Diactoros\ServerRequestFactory;
|
||||
use Zend\HttpHandlerRunner\Emitter\EmitterInterface,
|
||||
Zend\HttpHandlerRunner\Emitter\SapiEmitter;
|
||||
|
||||
return [
|
||||
ServerRequestInterface::class => function ($c) {
|
||||
return ServerRequestFactory::fromGlobals(
|
||||
$_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
|
||||
);
|
||||
},
|
||||
|
||||
EmitterInterface::class => create(SapiEmitter::class),
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Notes\Tell\LanguageHandler;
|
||||
|
||||
return [
|
||||
Tell\I18n::class => create( Tell\I18n::class ) ->constructor(
|
||||
get(Tell\Reader\JsonReader::class),
|
||||
get(Tell\Reader\PhpReader::class),
|
||||
getenv("DEBUG") ? create(Tell\PrintMissingKey::class) : get('tell.fallback')
|
||||
),
|
||||
|
||||
'tell.fallback' => function($c) {
|
||||
$tell = new Tell\I18n( $c->get(Tell\Reader\PhpReader::class) );
|
||||
$tell->locale = "en_US";
|
||||
|
||||
return $tell;
|
||||
},
|
||||
|
||||
# TODO -- accept folders from Lean Apps
|
||||
Tell\Reader\PhpReader::class => function($c) {
|
||||
return new Tell\Reader\PhpReader($c->get(Lean\Lean::class)->getI18n('php'), true);
|
||||
},
|
||||
|
||||
Tell\Reader\JsonReader::class => function($c) {
|
||||
return new Tell\Reader\JsonReader($c->get(Lean\Lean::class)->getI18n('json'), true);
|
||||
},
|
||||
|
||||
LanguageHandler::class => autowire(LanguageHandler::class),
|
||||
];
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use League\Route\Strategy\ApplicationStrategy,
|
||||
League\Route\Http\Exception\NotFoundException,
|
||||
League\Route\Router;
|
||||
|
||||
use Psr\Http\Message\ResponseFactoryInterface,
|
||||
Psr\Container\ContainerInterface,
|
||||
Psr\Http\Message\ResponseInterface,
|
||||
Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Server\MiddlewareInterface,
|
||||
Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
use TheBugs\JavascriptMiddleware;
|
||||
|
||||
use Cronard\CronardMiddleware;
|
||||
|
||||
use Tuupola\Middleware\HttpBasicAuthentication;
|
||||
|
||||
use Notes\Route\RouteFetcher;
|
||||
|
||||
use Storage\SessionMiddleware;
|
||||
|
||||
return [
|
||||
Lean\Routing::class => autowire(Lean\Routing::class),
|
||||
|
||||
RouteFetcher::class => function($c) {
|
||||
$fetcher = new RouteFetcher();
|
||||
|
||||
$fetcher->setFolderList(array_map(function($item) {
|
||||
return getenv("PROJECT_PATH") . $item;
|
||||
}, $c->get(Lean\Lean::class)->getRoutable()));
|
||||
|
||||
return $fetcher;
|
||||
},
|
||||
|
||||
ApplicationStrategy::class => function($c) {
|
||||
return new class($c->get(Picea\Picea::class)) extends ApplicationStrategy {
|
||||
|
||||
public Picea\Picea $picea;
|
||||
|
||||
public function __construct(Picea\Picea $picea) {
|
||||
$this->picea = $picea;
|
||||
}
|
||||
|
||||
public function getNotFoundDecorator(NotFoundException $exception): MiddlewareInterface
|
||||
{
|
||||
return new class($this->picea) implements MiddlewareInterface {
|
||||
|
||||
protected Picea\Picea $picea;
|
||||
|
||||
public function __construct(Picea\Picea $picea) {
|
||||
$this->picea = $picea;
|
||||
}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
return new Zend\Diactoros\Response\HtmlResponse($this->picea->renderHtml("lean/error/404", [], $this), 404);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
'routes.list' => function($c) {
|
||||
return function (ContainerInterface $container) {
|
||||
$router = $container->get(Router::class);
|
||||
|
||||
foreach([ "errorHandler", "dump", SessionMiddleware::class, CronardMiddleware::class, HttpBasicAuthentication::class, JavascriptMiddleware::class ] as $middleware) {
|
||||
if ( $container->has($middleware) ) {
|
||||
$router->middleware($container->get($middleware));
|
||||
}
|
||||
}
|
||||
|
||||
$routing = $container->get(Lean\Routing::class);
|
||||
|
||||
$routing->registerRoute($container, getenv('URL_BASE'));
|
||||
|
||||
return $router;
|
||||
};
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
use TheBugs\JavascriptMiddleware;
|
||||
|
||||
use Cronard\CronardMiddleware;
|
||||
|
||||
use Lean\Lean;
|
||||
|
||||
use Storage\Cookie,
|
||||
Storage\Session,
|
||||
Storage\SessionMiddleware;
|
||||
|
||||
return [
|
||||
'lean.default' => [
|
||||
'picea' => [
|
||||
'context' => "Lean\\View",
|
||||
|
||||
'view' => [
|
||||
[
|
||||
'path' => getenv("VIEW_PATH"),
|
||||
'order' => 10,
|
||||
],
|
||||
[
|
||||
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean/view/",
|
||||
'order' => 99,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'ulmus' => [
|
||||
'entities' => [ 'Growlogs\\Entity' ]
|
||||
],
|
||||
|
||||
'tell' => [
|
||||
'json' => [
|
||||
[
|
||||
'path' => getenv("META_PATH") . "/i18n",
|
||||
'order' => 10,
|
||||
],
|
||||
|
||||
[
|
||||
'path' => getenv("PROJECT_PATH") . "/vendor/mcnd/lean/meta/i18n",
|
||||
'order' => 99,
|
||||
],
|
||||
],
|
||||
|
||||
'php' => [
|
||||
[
|
||||
'path' => getenv("CACHE_PATH")."/i18n",
|
||||
'order' => 0,
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
'routes' => [
|
||||
'Growlogs\\Api' => '/src/Api/',
|
||||
'Growlogs\\Dev' => '/src/Dev/',
|
||||
'Growlogs\\Web' => '/src/Web/',
|
||||
],
|
||||
],
|
||||
|
||||
Lean::class => autowire(Lean::class),
|
||||
|
||||
CronardMiddleware::class => function($c) {
|
||||
$cronardMiddleware = new CronardMiddleware(getenv('CRON_KEY'), function() : ResponseInterface {
|
||||
return new TextResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
|
||||
});
|
||||
|
||||
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php");
|
||||
},
|
||||
|
||||
JavascriptMiddleware::class => create(JavascriptMiddleware::class),
|
||||
|
||||
Cookie::class => create(Cookie::class)->constructor([ 'secure' => true, 'samesite' => 'Strict' ], getenv("LEAN_RANDOM")),
|
||||
|
||||
Session::class => create(Session::class),
|
||||
|
||||
SessionMiddleware::class => create(SessionMiddleware::class)->constructor(get(Cookie::class), [ 'name' => "lean_sess_" . substr(md5(getenv("LEAN_RANDOM")), 0, 12) ]),
|
||||
|
||||
'git.commit' => function($c) {
|
||||
if ( getenv("DEBUG") ) {
|
||||
return uniqid("debug_");
|
||||
}
|
||||
|
||||
$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"));
|
||||
|
||||
return trim(file_get_contents( $path ), " \t\n\r");
|
||||
}
|
||||
|
||||
return "gitless-project";
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
use function DI\autowire, DI\create, DI\get;
|
||||
|
||||
use Zend\Diactoros\Response\HtmlResponse;
|
||||
|
||||
use Picea\Picea,
|
||||
Picea\Caching\Cache,
|
||||
Picea\Caching\Opcache,
|
||||
Picea\Compiler,
|
||||
Picea\Compiler\Context,
|
||||
Picea\Compiler\BaseContext,
|
||||
Picea\Extension\LanguageHandler,
|
||||
Picea\Extension\LanguageExtension,
|
||||
Picea\Extension\TitleExtension,
|
||||
Picea\Extension\UrlExtension,
|
||||
Picea\FileFetcher,
|
||||
Picea\Language\DefaultRegistrations,
|
||||
Picea\Method\Request,
|
||||
Picea\Ui\Method,
|
||||
Picea\Ui\Ui;
|
||||
|
||||
return [
|
||||
Picea::class => function($c) {
|
||||
return new Picea(function($html) {
|
||||
return new HtmlResponse( $html );
|
||||
}, $c->get(Context::class), $c->get(Cache::class), $c->get(Compiler::class), null, $c->get(FileFetcher::class), null, getenv("DEBUG"));
|
||||
},
|
||||
|
||||
Context::class => function($c) {
|
||||
return new BaseContext( $c->get(Lean\Lean::class)->getPiceaContext() );
|
||||
},
|
||||
|
||||
Compiler::class => function($c) {
|
||||
return new Compiler(new class(null, [
|
||||
$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 {
|
||||
|
||||
public function registerAll(Compiler $compiler) : void
|
||||
{
|
||||
parent::registerAll($compiler);
|
||||
( new Ui() )->registerFormExtension($compiler);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
Request::class => autowire(Request::class),
|
||||
|
||||
Method\Form::class => autowire(Method\Form::class),
|
||||
|
||||
Method\Pagination::class => autowire(Method\Pagination::class),
|
||||
|
||||
LanguageExtension::class => create(LanguageExtension::class)->constructor(get(Context::class), get(LanguageHandler::class)),
|
||||
|
||||
LanguageHandler::class => function($c) {
|
||||
return new class( $c->get(Tell\I18n::class) ) implements LanguageHandler {
|
||||
|
||||
public Tell\I18n $tell;
|
||||
|
||||
public function __construct(Tell\I18n $tell) {
|
||||
$this->tell = $tell;
|
||||
}
|
||||
|
||||
public function languageFromKey(string $key, array $variables = []) #: array|string
|
||||
{
|
||||
return $this->tell->fromKey($key, $variables) ?: "";
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
TitleExtension::class => autowire(TitleExtension::class),
|
||||
|
||||
UrlExtension::class => create(UrlExtension::class)->constructor(get(Context::class), getenv("URL_BASE"), get('git.commit')),
|
||||
|
||||
Cache::class => create(Opcache::class)->constructor(getenv("CACHE_PATH"), get(Context::class)),
|
||||
|
||||
FileFetcher::class => function($c) {
|
||||
return new FileFetcher($c->get(Lean\Lean::class)->getViewPaths());
|
||||
},
|
||||
];
|
||||
Reference in new issue
Block a user