• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeqvip / php-apollo / 21240851070

22 Jan 2026 08:08AM UTC coverage: 47.727% (-4.2%) from 51.887%
21240851070

push

github

leeqvip
feat: add clearCache

3 of 22 new or added lines in 3 files covered. (13.64%)

11 existing lines in 2 files now uncovered.

105 of 220 relevant lines covered (47.73%)

5.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.97
/src/Config.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Leeqvip\Apollo;
6

7
/**
8
 * Configuration management class
9
 */
10
class Config
11
{
12
    /**
13
     * Configuration data
14
     * @var array<string, array<string, mixed>>
15
     */
16
    protected array $configs = [];
17

18
    /**
19
     * Configuration change callbacks
20
     * @var array<string, array<callable>>
21
     */
22
    protected array $callbacks = [];
23

24
    /**
25
     * Get configuration value
26
     * 
27
     * @param string $key Configuration key
28
     * @param mixed $default Default value
29
     * @param string $namespace Namespace
30
     * @return mixed
31
     */
32
    public function get(string $key, mixed $default = null, string $namespace = 'application'): mixed
33
    {
34
        if (!isset($this->configs[$namespace])) {
24✔
UNCOV
35
            return $default;
×
36
        }
37

38
        if (isset($this->configs[$namespace][$key])) {
24✔
39
            return $this->configs[$namespace][$key];
18✔
40
        }
41

42
        // Support dot-separated keys, such as database.host
43
        $keys = explode('.', $key);
12✔
44
        $value = $this->configs[$namespace];
12✔
45

46
        foreach ($keys as $k) {
12✔
47
            if (!isset($value[$k])) {
12✔
48
                return $default;
12✔
49
            }
50
            $value = $value[$k];
×
51
        }
52

53
        return $value;
×
54
    }
55

56
    /**
57
     * Set configuration value
58
     * 
59
     * @param string $key Configuration key
60
     * @param mixed $value Configuration value
61
     * @param string $namespace Namespace
62
     * @return void
63
     */
64
    public function set(string $key, mixed $value, string $namespace = 'application'): void
65
    {
66
        if (!isset($this->configs[$namespace])) {
12✔
67
            $this->configs[$namespace] = [];
12✔
68
        }
69

70
        $this->configs[$namespace][$key] = $value;
12✔
71
    }
72

73
    /**
74
     * Batch set configurations
75
     * 
76
     * @param array<string, mixed> $configs Configuration array
77
     * @param string $namespace Namespace
78
     * @return void
79
     */
80
    public function setBatch(array $configs, string $namespace = 'application'): void
81
    {
82
        $this->configs[$namespace] = $configs;
12✔
83
        $this->triggerCallbacks($namespace);
12✔
84
    }
85

86
    /**
87
     * Get all configurations
88
     * 
89
     * @param string $namespace Namespace
90
     * @return array<string, mixed>
91
     */
92
    public function all(string $namespace = 'application'): array
93
    {
94
        return $this->configs[$namespace] ?? [];
×
95
    }
96

97
    /**
98
     * Register configuration change callback
99
     * 
100
     * @param callable $callback Callback function
101
     * @param string $namespace Namespace
102
     * @return void
103
     */
104
    public function registerCallback(callable $callback, string $namespace = '*'): void
105
    {
106
        if (!isset($this->callbacks[$namespace])) {
6✔
107
            $this->callbacks[$namespace] = [];
6✔
108
        }
109

110
        $this->callbacks[$namespace][] = $callback;
6✔
111
    }
112

113
    /**
114
     * Trigger configuration change callbacks
115
     * 
116
     * @param string $namespace Namespace
117
     * @return void
118
     */
119
    protected function triggerCallbacks(string $namespace): void
120
    {
121
        // Trigger callbacks for specific namespace
122
        if (isset($this->callbacks[$namespace])) {
12✔
123
            foreach ($this->callbacks[$namespace] as $callback) {
×
124
                call_user_func($callback, $this->configs[$namespace]);
×
125
            }
126
        }
127

128
        // Trigger global callbacks
129
        if (isset($this->callbacks['*'])) {
12✔
130
            foreach ($this->callbacks['*'] as $callback) {
6✔
131
                call_user_func($callback, $this->configs[$namespace], $namespace);
6✔
132
            }
133
        }
134
    }
135

136
    /**
137
     * Clear configurations
138
     * 
139
     * @param string|null $namespace Namespace
140
     * @return void
141
     */
142
    public function clear(?string $namespace = null): void
143
    {
144
        if ($namespace === null) {
×
145
            $this->configs = [];
×
146
        } else {
147
            unset($this->configs[$namespace]);
×
148
        }
149
    }
150
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc