Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Spatie\FlareClient\Concerns;
4
 
5
trait HasContext
6
{
7
    protected ?string $messageLevel = null;
8
 
9
    protected ?string $stage = null;
10
 
11
    /**
12
     * @var array<string, mixed>
13
     */
14
    protected array $userProvidedContext = [];
15
 
16
    public function stage(?string $stage): self
17
    {
18
        $this->stage = $stage;
19
 
20
        return $this;
21
    }
22
 
23
    public function messageLevel(?string $messageLevel): self
24
    {
25
        $this->messageLevel = $messageLevel;
26
 
27
        return $this;
28
    }
29
 
30
    /**
31
     * @param string $groupName
32
     * @param mixed $default
33
     *
34
     * @return array<int, mixed>
35
     */
36
    public function getGroup(string $groupName = 'context', $default = []): array
37
    {
38
        return $this->userProvidedContext[$groupName] ?? $default;
39
    }
40
 
41
    public function context(string $key, mixed $value): self
42
    {
43
        return $this->group('context', [$key => $value]);
44
    }
45
 
46
    /**
47
     * @param string $groupName
48
     * @param array<string, mixed> $properties
49
     *
50
     * @return $this
51
     */
52
    public function group(string $groupName, array $properties): self
53
    {
54
        $group = $this->userProvidedContext[$groupName] ?? [];
55
 
56
        $this->userProvidedContext[$groupName] = array_merge_recursive_distinct(
57
            $group,
58
            $properties
59
        );
60
 
61
        return $this;
62
    }
63
}