forked from getsentry/sentry-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreadcrumbs.php
76 lines (68 loc) · 1.41 KB
/
Breadcrumbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of Raven.
*
* (c) Sentry Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Raven Breadcrumbs
*
* @package raven
*/
class Raven_Breadcrumbs
{
public $count;
public $pos;
public $size;
/**
* @var array[]
*/
public $buffer;
public function __construct($size = 100)
{
$this->size = $size;
$this->reset();
}
public function reset()
{
$this->count = 0;
$this->pos = 0;
$this->buffer = array();
}
public function record($crumb)
{
if (empty($crumb['timestamp'])) {
$crumb['timestamp'] = microtime(true);
}
$this->buffer[$this->pos] = $crumb;
$this->pos = ($this->pos + 1) % $this->size;
$this->count++;
}
/**
* @return array[]
*/
public function fetch()
{
$results = array();
for ($i = 0; $i <= ($this->size - 1); $i++) {
$idx = ($this->pos + $i) % $this->size;
if (isset($this->buffer[$idx])) {
$results[] = $this->buffer[$idx];
}
}
return $results;
}
public function is_empty()
{
return $this->count === 0;
}
public function to_json()
{
return array(
'values' => $this->fetch(),
);
}
}