Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Termwind\Repositories;
6
 
7
use Closure;
8
use Termwind\ValueObjects\Style;
9
use Termwind\ValueObjects\Styles as StylesValueObject;
10
 
11
/**
12
 * @internal
13
 */
14
final class Styles
15
{
16
    /**
17
     * @var array<string, Style>
18
     */
19
    private static array $storage = [];
20
 
21
    /**
22
     * Creates a new style from the given arguments.
23
     *
24
     * @param (Closure(StylesValueObject $element, string|int ...$arguments): StylesValueObject)|null $callback
25
     * @return Style
26
     */
27
    public static function create(string $name, Closure $callback = null): Style
28
    {
29
        self::$storage[$name] = $style = new Style(
30
            $callback ?? static fn (StylesValueObject $styles) => $styles
31
        );
32
 
33
        return $style;
34
    }
35
 
36
    /**
37
     * Removes all existing styles.
38
     */
39
    public static function flush(): void
40
    {
41
        self::$storage = [];
42
    }
43
 
44
    /**
45
     * Checks a style with the given name exists.
46
     */
47
    public static function has(string $name): bool
48
    {
49
        return array_key_exists($name, self::$storage);
50
    }
51
 
52
    /**
53
     * Gets the style with the given name.
54
     */
55
    public static function get(string $name): Style
56
    {
57
        return self::$storage[$name];
58
    }
59
}