1 | <?php |
||
14 | trait StreamDecoratorTrait |
||
15 | { |
||
16 | /** |
||
17 | * @param StreamInterface $stream Stream to decorate |
||
18 | */ |
||
19 | 18 | public function __construct(StreamInterface $stream) |
|
23 | |||
24 | /** |
||
25 | * Magic method used to create a new stream if streams are not added in |
||
26 | * the constructor of a decorator (e.g., LazyOpenStream). |
||
27 | * |
||
28 | * @param string $name Name of the property (allows "stream" only). |
||
29 | * |
||
30 | * @return StreamInterface |
||
31 | */ |
||
32 | 9 | public function __get($name) |
|
42 | |||
43 | 19 | public function __toString() |
|
58 | |||
59 | 23 | public function getContents() |
|
63 | |||
64 | /** |
||
65 | * Allow decorators to implement custom methods |
||
66 | * |
||
67 | * @param string $method Missing method name |
||
68 | * @param array $args Method arguments |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | public function __call($method, array $args) |
||
79 | |||
80 | 3 | public function close() |
|
84 | |||
85 | 3 | public function getMetadata($key = null) |
|
89 | |||
90 | 2 | public function detach() |
|
94 | |||
95 | 4 | public function getSize() |
|
99 | |||
100 | 15 | public function eof() : bool |
|
104 | |||
105 | 8 | public function tell() : int |
|
109 | |||
110 | 4 | public function isReadable() : bool |
|
114 | |||
115 | 3 | public function isWritable() : bool |
|
119 | |||
120 | 19 | public function isSeekable() : bool |
|
124 | |||
125 | public function rewind() |
||
129 | |||
130 | 12 | public function seek($offset, $whence = SEEK_SET) |
|
134 | |||
135 | 16 | public function read($length) |
|
139 | |||
140 | 6 | public function write($string) |
|
144 | |||
145 | /** |
||
146 | * Implement in subclasses to dynamically create streams when requested. |
||
147 | * |
||
148 | * @return StreamInterface |
||
149 | * @throws \BadMethodCallException |
||
150 | */ |
||
151 | 1 | protected function createStream() |
|
155 | } |
||
156 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: