1: <?php
2: /**
3: * PHP Token Reflection
4: *
5: * Version 1.3.1
6: *
7: * LICENSE
8: *
9: * This source file is subject to the new BSD license that is bundled
10: * with this library in the file LICENSE.
11: *
12: * @author Ondřej Nešpor
13: * @author Jaroslav Hanslík
14: */
15:
16: namespace TokenReflection\Exception;
17:
18: use TokenReflection\ReflectionFile;
19:
20: /**
21: * Processing exception thrown by the library if a file could not be processed.
22: */
23: final class FileProcessingException extends RuntimeException
24: {
25: /**
26: * Resons why the file could not be processed.
27: *
28: * @var array
29: */
30: private $reasons = array();
31:
32: /**
33: * Constructor.
34: *
35: * @param array $reasons Resons why the file could not be processed
36: * @param \TokenReflection\ReflectionFile $sender Reflection file
37: */
38: public function __construct(array $reasons, ReflectionFile $sender = null)
39: {
40: parent::__construct(
41: null === $sender ? 'There was an error processing the file.' : sprintf('There was an error processing the file %s.', $sender->getName()),
42: 0,
43: $sender
44: );
45:
46: $this->reasons = $reasons;
47: }
48:
49: /**
50: * Returns a list of reasons why the file could not be processed.
51: *
52: * @return array
53: */
54: public function getReasons()
55: {
56: return $this->reasons;
57: }
58:
59: /**
60: * Returns an exception description detail.
61: *
62: * @return string
63: */
64: public function getDetail()
65: {
66: if (!empty($this->reasons)) {
67: $reasons = array_map(function(BaseException $reason) {
68: if ($reason instanceof ParseException) {
69: return $reason->getDetail();
70: } else {
71: return $reason->getMessage();
72: }
73: }, $this->reasons);
74:
75: return "There were following reasons for this exception:\n" . implode("\n", $reasons);
76: }
77:
78: return '';
79: }
80: }
81: