ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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_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
146 public function serialize()
147 {
148 return serialize($this->frames);
149 }
150
155 public function unserialize($serializedFrames)
156 {
157 $this->frames = unserialize($serializedFrames);
158 }
159
163 public function prependFrames(array $frames)
164 {
165 $this->frames = array_merge($frames, $this->frames);
166 }
167
174 public function topDiff(FrameCollection $parentFrames)
175 {
176 $diff = $this->frames;
177
178 $parentFrames = $parentFrames->getArray();
179 $p = count($parentFrames)-1;
180
181 for ($i = count($diff)-1; $i >= 0 && $p >= 0; $i--) {
183 $tailFrame = $diff[$i];
184 if ($tailFrame->equals($parentFrames[$p])) {
185 unset($diff[$i]);
186 }
187 $p--;
188 }
189 return $diff;
190 }
191}
Exposes a fluent interface for dealing with an ordered list of stack-trace frames.
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.
Whoops - php errors for cool kids.