From 07f5140771388c9e0c8a99b0dd2e5d950bdb173b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 14 Oct 2021 15:16:42 +1100 Subject: moving h-source subdir out. --- .../ByteStream/AbstractFilterableInputStream.php | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100755 External/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php (limited to 'External/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php') diff --git a/External/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php b/External/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php new file mode 100755 index 0000000..71bc3f1 --- /dev/null +++ b/External/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php @@ -0,0 +1,178 @@ +_filters[$key] = $filter; + } + + /** + * Remove an already present StreamFilter based on its $key. + * @param string $key + */ + public function removeFilter($key) + { + unset($this->_filters[$key]); + } + + /** + * Writes $bytes to the end of the stream. + * @param string $bytes + * @throws Swift_IoException + */ + public function write($bytes) + { + $this->_writeBuffer .= $bytes; + foreach ($this->_filters as $filter) + { + if ($filter->shouldBuffer($this->_writeBuffer)) + { + return; + } + } + $this->_doWrite($this->_writeBuffer); + return ++$this->_sequence; + } + + /** + * For any bytes that are currently buffered inside the stream, force them + * off the buffer. + * + * @throws Swift_IoException + */ + public function commit() + { + $this->_doWrite($this->_writeBuffer); + } + + /** + * Attach $is to this stream. + * The stream acts as an observer, receiving all data that is written. + * All {@link write()} and {@link flushBuffers()} operations will be mirrored. + * + * @param Swift_InputByteStream $is + */ + public function bind(Swift_InputByteStream $is) + { + $this->_mirrors[] = $is; + } + + /** + * Remove an already bound stream. + * If $is is not bound, no errors will be raised. + * If the stream currently has any buffered data it will be written to $is + * before unbinding occurs. + * + * @param Swift_InputByteStream $is + */ + public function unbind(Swift_InputByteStream $is) + { + foreach ($this->_mirrors as $k => $stream) + { + if ($is === $stream) + { + if ($this->_writeBuffer !== '') + { + $stream->write($this->_filter($this->_writeBuffer)); + } + unset($this->_mirrors[$k]); + } + } + } + + /** + * Flush the contents of the stream (empty it) and set the internal pointer + * to the beginning. + * @throws Swift_IoException + */ + public function flushBuffers() + { + if ($this->_writeBuffer !== '') + { + $this->_doWrite($this->_writeBuffer); + } + $this->_flush(); + + foreach ($this->_mirrors as $stream) + { + $stream->flushBuffers(); + } + } + + // -- Private methods + + /** Run $bytes through all filters */ + private function _filter($bytes) + { + foreach ($this->_filters as $filter) + { + $bytes = $filter->filter($bytes); + } + return $bytes; + } + + /** Just write the bytes to the stream */ + private function _doWrite($bytes) + { + $this->_commit($this->_filter($bytes)); + + foreach ($this->_mirrors as $stream) + { + $stream->write($bytes); + } + + $this->_writeBuffer = ''; + } + +} -- cgit v1.2.3