lean/meta/definitions/software.php

114 lines
3.2 KiB
PHP
Raw Normal View History

<?php
use function DI\autowire, DI\create, DI\get;
2022-01-31 00:05:27 +00:00
use Zend\Diactoros\Response\HtmlResponse;
use TheBugs\JavascriptMiddleware;
use Cronard\CronardMiddleware,
Notes\Cronard\TaskFetcher;
use Lean\Lean;
use Psr\Http\Message\ResponseInterface;
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,
],
],
'extensions' => [],
],
'ulmus' => [],
'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' => [],
'cronard' => [],
],
Lean::class => autowire(Lean::class),
CronardMiddleware::class => function($c) {
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
2022-01-31 00:05:27 +00:00
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
}, [], $c->get(TaskFetcher::class));
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));
},
TaskFetcher::class => function($c) {
$fetcher = new TaskFetcher();
$fetcher->setFolderList(array_map(function($item) {
return $item;
}, $c->get(Lean::class)->getCronard()));
return $fetcher;
},
JavascriptMiddleware::class => create(JavascriptMiddleware::class),
2022-05-11 15:21:51 +00:00
Cookie::class => create(Cookie::class)->constructor([ 'secure' => true, 'path' => getenv('URL_BASE') ?: '/', ], getenv("LEAN_RANDOM")),
2022-05-11 15:21:51 +00:00
Session::class => create(Session::class)->constructor(get(Cookie::class), [ 'path' => getenv('URL_BASE') ?: '/', ]),
SessionMiddleware::class => create(SessionMiddleware::class)->constructor(get(Cookie::class), [ 'name' => "lean_sess_" . substr(md5(getenv("LEAN_RANDOM")), 0, 12), 'path' => getenv('URL_BASE') ?: '/' ]),
'git.commit' => function($c) {
if ( getenv("DEBUG") ) {
return uniqid("debug_");
}
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
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 "gitless-project";
},
];