ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FrameCollection.php
Go to the documentation of this file.
1<?php
7namespace Whoops\Exception;
8
9use ArrayAccess;
10use ArrayIterator;
11use Countable;
12use IteratorAggregate;
13use Serializable;
14use UnexpectedValueException;
15
20class FrameCollection implements ArrayAccess, IteratorAggregate, Serializable, Countable
21{
25 private $frames;
26
30 public function __construct(array $frames)
31 {
32 $this->frames = array_map(function ($frame) {
33 return new Frame($frame);
34 }, $frames);
35 }
36
43 public function filter($callable)
44 {
45 $this->frames = array_values(array_filter($this->frames, $callable));
46 return $this;
47 }
48
55 public function map($callable)
56 {
57 // Contain the map within a higher-order callable
58 // that enforces type-correctness for the $callable
59 $this->frames = array_map(function ($frame) use ($callable) {
60 $frame = call_user_func($callable, $frame);
61
62 if (!$frame instanceof Frame) {
63 throw new UnexpectedValueException(
64 "Callable to " . __METHOD__ . " must return a Frame object"
65 );
66 }
67
68 return $frame;
69 }, $this->frames);
70
71 return $this;
72 }
73
83 public function getArray()
84 {
85 return $this->frames;
86 }
87
92 public function getIterator()
93 {
94 return new ArrayIterator($this->frames);
95 }
96
101 public function offsetExists($offset)
102 {
103 return isset($this->frames[$offset]);
104 }
105
110 public function offsetGet($offset)
111 {
112 return $this->frames[$offset];
113 }
114
119 public function offsetSet($offset, $value)
120 {
121 throw new \Exception(__CLASS__ . ' is read only');
122 }
123
128 public function offsetUnset($offset)
129 {
130 throw new \Exception(__CLASS__ . ' is read only');
131 }
132
137 public function count()
138 {
139 return count($this->frames);
140 }
141
147 public function countIsApplication()
148 {
149 return count(array_filter($this->frames, function (Frame $f) {
150 return $f->isApplication();
151 }));
152 }
153
158 public function serialize()
159 {
160 return serialize($this->frames);
161 }
162
167 public function unserialize($serializedFrames)
168 {
169 $this->frames = unserialize($serializedFrames);
170 }
171
175 public function prependFrames(array $frames)
176 {
177 $this->frames = array_merge($frames, $this->frames);
178 }
179
186 public function topDiff(FrameCollection $parentFrames)
187 {
188 $diff = $this->frames;
189
190 $parentFrames = $parentFrames->getArray();
191 $p = count($parentFrames)-1;
192
193 for ($i = count($diff)-1; $i >= 0 && $p >= 0; $i--) {
195 $tailFrame = $diff[$i];
196 if ($tailFrame->equals($parentFrames[$p])) {
197 unset($diff[$i]);
198 }
199 $p--;
200 }
201 return $diff;
202 }
203}
An exception for terminatinating execution or to throw for unit testing.
Exposes a fluent interface for dealing with an ordered list of stack-trace frames.
countIsApplication()
Count the frames that belongs to the application.
getArray()
Returns an array with all frames, does not affect the internal array.
filter($callable)
Filters frames using a callable, returns the same FrameCollection.
map($callable)
Map the collection of frames.
$i
Definition: disco.tpl.php:19
Whoops - php errors for cool kids.