bnomei/kirby3-lapse

View on GitHub
classes/LapseStatic.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Bnomei;

use Closure;
use Kirby\Toolkit\A;

class LapseStatic
{
    public static array $cache = [];

    public static function getOrSet($key, Closure $closure)
    {
        $key = Lapse::singleton()->keyFromObject($key);

        if ($value = A::get(static::$cache, $key, null)) {
            return $value;
        }

        if (!is_string($closure) && is_callable($closure)) {
            static::$cache[$key] = $closure();
        }

        return static::$cache[$key];
    }
}