[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 namespace GuzzleHttp\Stream; 3 use GuzzleHttp\Stream\Exception\CannotAttachException; 4 5 /** 6 * Stream decorator trait 7 * @property StreamInterface stream 8 */ 9 trait StreamDecoratorTrait 10 { 11 /** 12 * @param StreamInterface $stream Stream to decorate 13 */ 14 public function __construct(StreamInterface $stream) 15 { 16 $this->stream = $stream; 17 } 18 19 /** 20 * Magic method used to create a new stream if streams are not added in 21 * the constructor of a decorator (e.g., LazyOpenStream). 22 */ 23 public function __get($name) 24 { 25 if ($name == 'stream') { 26 $this->stream = $this->createStream(); 27 return $this->stream; 28 } 29 30 throw new \UnexpectedValueException("$name not found on class"); 31 } 32 33 public function __toString() 34 { 35 try { 36 $this->seek(0); 37 return $this->getContents(); 38 } catch (\Exception $e) { 39 // Really, PHP? https://bugs.php.net/bug.php?id=53648 40 trigger_error('StreamDecorator::__toString exception: ' 41 . (string) $e, E_USER_ERROR); 42 return ''; 43 } 44 } 45 46 public function getContents() 47 { 48 return Utils::copyToString($this); 49 } 50 51 /** 52 * Allow decorators to implement custom methods 53 * 54 * @param string $method Missing method name 55 * @param array $args Method arguments 56 * 57 * @return mixed 58 */ 59 public function __call($method, array $args) 60 { 61 $result = call_user_func_array(array($this->stream, $method), $args); 62 63 // Always return the wrapped object if the result is a return $this 64 return $result === $this->stream ? $this : $result; 65 } 66 67 public function close() 68 { 69 $this->stream->close(); 70 } 71 72 public function getMetadata($key = null) 73 { 74 return $this->stream->getMetadata($key); 75 } 76 77 public function detach() 78 { 79 return $this->stream->detach(); 80 } 81 82 public function attach($stream) 83 { 84 throw new CannotAttachException(); 85 } 86 87 public function getSize() 88 { 89 return $this->stream->getSize(); 90 } 91 92 public function eof() 93 { 94 return $this->stream->eof(); 95 } 96 97 public function tell() 98 { 99 return $this->stream->tell(); 100 } 101 102 public function isReadable() 103 { 104 return $this->stream->isReadable(); 105 } 106 107 public function isWritable() 108 { 109 return $this->stream->isWritable(); 110 } 111 112 public function isSeekable() 113 { 114 return $this->stream->isSeekable(); 115 } 116 117 public function seek($offset, $whence = SEEK_SET) 118 { 119 return $this->stream->seek($offset, $whence); 120 } 121 122 public function read($length) 123 { 124 return $this->stream->read($length); 125 } 126 127 public function write($string) 128 { 129 return $this->stream->write($string); 130 } 131 132 /** 133 * Implement in subclasses to dynamically create streams when requested. 134 * 135 * @return StreamInterface 136 * @throws \BadMethodCallException 137 */ 138 protected function createStream() 139 { 140 throw new \BadMethodCallException('createStream() not implemented in ' 141 . get_class($this)); 142 } 143 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |