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\Stream\StreamBase;
19:
20: /**
21: * TokenReflection exception raised when working with a token stream.
22: */
23: class StreamException extends BaseException
24: {
25: /**
26: * The property/element does not exist.
27: *
28: * @var integer
29: */
30: const NOT_READABLE = 1001;
31:
32: /**
33: * A required PHP extension is missing.
34: *
35: * @var integer
36: */
37: const READ_BEYOND_EOS = 1002;
38:
39: /**
40: * There was an error when (de)serializing the token stream.
41: *
42: * @var integer
43: */
44: const SERIALIZATION_ERROR = 1003;
45:
46: /**
47: * The token stream that caused this exception to be raised.
48: *
49: * @var \TokenReflection\Stream\StreamBase
50: */
51: private $stream;
52:
53: /**
54: * Constructor.
55: *
56: * @param \TokenReflection\Stream\StreamBase $stream Reflection element
57: * @param string $message Exception message
58: * @param integer $code Exception code
59: */
60: public function __construct(StreamBase $stream, $message, $code)
61: {
62: parent::__construct($message, $code);
63:
64: $this->stream = $stream;
65: }
66:
67: /**
68: * Returns the reflection element that caused the exception to be raised.
69: *
70: * @return \TokenReflection\Stream\StreamBase
71: */
72: public function getStream()
73: {
74: return $this->stream;
75: }
76:
77: /**
78: * Returns the processed file name.
79: *
80: * @return string
81: */
82: public function getFileName()
83: {
84: return $this->stream->getFileName();
85: }
86:
87: /**
88: * Returns an exception description detail.
89: *
90: * @return string
91: */
92: public function getDetail()
93: {
94: return sprintf('Thrown when working with file "%s" token stream.', $this->getFileName());
95: }
96: }
97: