Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Symfony\Component\HttpKernel\Profiler;
13
 
14
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
15
 
16
/**
17
 * Profile.
18
 *
19
 * @author Fabien Potencier <fabien@symfony.com>
20
 */
21
class Profile
22
{
23
    private string $token;
24
 
25
    /**
26
     * @var DataCollectorInterface[]
27
     */
28
    private array $collectors = [];
29
 
30
    private ?string $ip = null;
31
    private ?string $method = null;
32
    private ?string $url = null;
33
    private ?int $time = null;
34
    private ?int $statusCode = null;
35
    private ?self $parent = null;
36
 
37
    /**
38
     * @var Profile[]
39
     */
40
    private array $children = [];
41
 
42
    public function __construct(string $token)
43
    {
44
        $this->token = $token;
45
    }
46
 
47
    public function setToken(string $token)
48
    {
49
        $this->token = $token;
50
    }
51
 
52
    /**
53
     * Gets the token.
54
     */
55
    public function getToken(): string
56
    {
57
        return $this->token;
58
    }
59
 
60
    /**
61
     * Sets the parent token.
62
     */
63
    public function setParent(self $parent)
64
    {
65
        $this->parent = $parent;
66
    }
67
 
68
    /**
69
     * Returns the parent profile.
70
     */
71
    public function getParent(): ?self
72
    {
73
        return $this->parent;
74
    }
75
 
76
    /**
77
     * Returns the parent token.
78
     */
79
    public function getParentToken(): ?string
80
    {
81
        return $this->parent?->getToken();
82
    }
83
 
84
    /**
85
     * Returns the IP.
86
     */
87
    public function getIp(): ?string
88
    {
89
        return $this->ip;
90
    }
91
 
92
    public function setIp(?string $ip)
93
    {
94
        $this->ip = $ip;
95
    }
96
 
97
    /**
98
     * Returns the request method.
99
     */
100
    public function getMethod(): ?string
101
    {
102
        return $this->method;
103
    }
104
 
105
    public function setMethod(string $method)
106
    {
107
        $this->method = $method;
108
    }
109
 
110
    /**
111
     * Returns the URL.
112
     */
113
    public function getUrl(): ?string
114
    {
115
        return $this->url;
116
    }
117
 
118
    public function setUrl(?string $url)
119
    {
120
        $this->url = $url;
121
    }
122
 
123
    public function getTime(): int
124
    {
125
        return $this->time ?? 0;
126
    }
127
 
128
    public function setTime(int $time)
129
    {
130
        $this->time = $time;
131
    }
132
 
133
    public function setStatusCode(int $statusCode)
134
    {
135
        $this->statusCode = $statusCode;
136
    }
137
 
138
    public function getStatusCode(): ?int
139
    {
140
        return $this->statusCode;
141
    }
142
 
143
    /**
144
     * Finds children profilers.
145
     *
146
     * @return self[]
147
     */
148
    public function getChildren(): array
149
    {
150
        return $this->children;
151
    }
152
 
153
    /**
154
     * Sets children profiler.
155
     *
156
     * @param Profile[] $children
157
     */
158
    public function setChildren(array $children)
159
    {
160
        $this->children = [];
161
        foreach ($children as $child) {
162
            $this->addChild($child);
163
        }
164
    }
165
 
166
    /**
167
     * Adds the child token.
168
     */
169
    public function addChild(self $child)
170
    {
171
        $this->children[] = $child;
172
        $child->setParent($this);
173
    }
174
 
175
    public function getChildByToken(string $token): ?self
176
    {
177
        foreach ($this->children as $child) {
178
            if ($token === $child->getToken()) {
179
                return $child;
180
            }
181
        }
182
 
183
        return null;
184
    }
185
 
186
    /**
187
     * Gets a Collector by name.
188
     *
189
     * @throws \InvalidArgumentException if the collector does not exist
190
     */
191
    public function getCollector(string $name): DataCollectorInterface
192
    {
193
        if (!isset($this->collectors[$name])) {
194
            throw new \InvalidArgumentException(sprintf('Collector "%s" does not exist.', $name));
195
        }
196
 
197
        return $this->collectors[$name];
198
    }
199
 
200
    /**
201
     * Gets the Collectors associated with this profile.
202
     *
203
     * @return DataCollectorInterface[]
204
     */
205
    public function getCollectors(): array
206
    {
207
        return $this->collectors;
208
    }
209
 
210
    /**
211
     * Sets the Collectors associated with this profile.
212
     *
213
     * @param DataCollectorInterface[] $collectors
214
     */
215
    public function setCollectors(array $collectors)
216
    {
217
        $this->collectors = [];
218
        foreach ($collectors as $collector) {
219
            $this->addCollector($collector);
220
        }
221
    }
222
 
223
    /**
224
     * Adds a Collector.
225
     */
226
    public function addCollector(DataCollectorInterface $collector)
227
    {
228
        $this->collectors[$collector->getName()] = $collector;
229
    }
230
 
231
    public function hasCollector(string $name): bool
232
    {
233
        return isset($this->collectors[$name]);
234
    }
235
 
236
    public function __sleep(): array
237
    {
238
        return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode'];
239
    }
240
}