-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
60 lines (53 loc) · 1.77 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
@include_once __DIR__.'/vendor/autoload.php';
if (! class_exists('Bnomei\Lapse')) {
require_once __DIR__.'/classes/Lapse.php';
require_once __DIR__.'/classes/LapseStatic.php';
}
if (! function_exists('lapse')) {
function lapse(mixed $key, mixed $value = null, ?int $expires = null): mixed
{
if ($value) {
return \Bnomei\Lapse::singleton()->set($key, $value, $expires);
}
return \Bnomei\Lapse::singleton()->get($key);
}
}
if (! function_exists('lapseStatic')) {
function lapseStatic(mixed $key, Closure $closure, ?int $expires = null): mixed
{
// NOTE: $expires is kept as param to make swapping between lapse and lapseStatic more easily
return \Bnomei\LapseStatic::getOrSet($key, $closure);
}
}
Kirby::plugin('bnomei/lapse', [
'options' => [
'cache' => true,
'expires' => 0,
'indexLimit' => null,
],
'commands' => [ // https://github.com/getkirby/cli
'lapse:prune' => [
'description' => 'Prune cache Lapse plugin',
'args' => [],
'command' => static function ($cli) {
return \Bnomei\Lapse::singleton()->prune();
},
],
'lapse:flush' => [
'description' => 'Flush cache of Lapse plugin',
'args' => [],
'command' => static function ($cli) {
return \Bnomei\Lapse::singleton()->flush();
},
],
],
'siteMethods' => [
'modifiedTimestamp' => function (): int {
// TODO
// $time = filemtime(site()->storage()->contentFiles(site()->storage()->defaultVersion())[0]);
$time = time();
return $time !== false ? $time : time(); // @phpstan-ignore-line
},
],
]);