1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCache package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\HttpCache\Exception; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A collection of exceptions that might occur during the flush operation of a |
16
|
|
|
* ProxyClientInterface implementation |
17
|
|
|
*/ |
18
|
|
|
class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheExceptionInterface |
19
|
|
|
{ |
20
|
|
|
private $exceptions = []; |
21
|
|
|
|
22
|
40 |
|
public function __construct(array $exceptions = []) |
23
|
|
|
{ |
24
|
40 |
|
foreach ($exceptions as $exception) { |
25
|
|
|
$this->add($exception); |
26
|
40 |
|
} |
27
|
40 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Add an exception to the collection |
31
|
|
|
* |
32
|
|
|
* @param \Exception $e |
33
|
|
|
* |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
3 |
|
public function add(\Exception $e) |
37
|
|
|
{ |
38
|
3 |
|
if (null == $this->message) { |
39
|
3 |
|
$this->message = $e->getMessage(); |
40
|
3 |
|
} |
41
|
|
|
|
42
|
3 |
|
$this->exceptions[] = $e; |
43
|
|
|
|
44
|
3 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get first exception in collection or null, if there is none. |
49
|
|
|
* |
50
|
|
|
* @return \Exception|null |
51
|
|
|
*/ |
52
|
2 |
|
public function getFirst() |
53
|
|
|
{ |
54
|
2 |
|
if ($this->count() > 0) { |
55
|
2 |
|
return $this->exceptions[0]; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get exception iterator |
63
|
|
|
* |
64
|
|
|
* @return \ArrayIterator |
65
|
|
|
*/ |
66
|
2 |
|
public function getIterator() |
67
|
|
|
{ |
68
|
2 |
|
return new \ArrayIterator($this->exceptions); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get number of exceptions in collection |
73
|
|
|
* |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
39 |
|
public function count() |
77
|
|
|
{ |
78
|
39 |
|
return count($this->exceptions); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|