Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
6
core/vendor/guzzlehttp/streams/.gitignore
vendored
Normal file
6
core/vendor/guzzlehttp/streams/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
.idea
|
||||
.DS_STORE
|
||||
coverage
|
||||
phpunit.xml
|
||||
composer.lock
|
||||
vendor/
|
17
core/vendor/guzzlehttp/streams/.travis.yml
vendored
Normal file
17
core/vendor/guzzlehttp/streams/.travis.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- composer self-update
|
||||
- composer install --no-interaction --prefer-source --dev
|
||||
|
||||
script: vendor/bin/phpunit
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
94
core/vendor/guzzlehttp/streams/CHANGELOG.rst
vendored
Normal file
94
core/vendor/guzzlehttp/streams/CHANGELOG.rst
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
=========
|
||||
Changelog
|
||||
=========
|
||||
|
||||
3.0.0 (2014-10-12)
|
||||
------------------
|
||||
|
||||
* Now supports creating streams from functions and iterators.
|
||||
* Supports creating buffered streams and asynchronous streams.
|
||||
* Removed ``functions.php``. Use the corresponding functions provided by
|
||||
``GuzzleHttp\Streams\Utils`` instead.
|
||||
* Moved ``GuzzleHttp\Stream\MetadataStreamInterface::getMetadata`` to
|
||||
``GuzzleHttp\Stream\StreamInterface``. MetadataStreamInterface is no longer
|
||||
used and is marked as deprecated.
|
||||
* Added ``attach()`` to ``GuzzleHttp\Stream\StreamInterface`` for PSR-7
|
||||
compatibility.
|
||||
* Removed ``flush()`` from StreamInterface.
|
||||
* Removed the ``$maxLength`` parameter from
|
||||
``GuzzleHttp\Stream\StreamInterface::getContents()``. This function now
|
||||
returns the entire remainder of the stream. If you want to limit the maximum
|
||||
amount of data read from the stream, use the
|
||||
``GuzzleHttp\Stream\Utils::copyToString()`` function.
|
||||
* Streams that return an empty string, ``''``, are no longer considered a
|
||||
failure. You MUST return ``false`` to mark the read as a failure, and ensure
|
||||
that any decorators you create properly return ``true`` in response to the
|
||||
``eof()`` method when the stream is consumed.
|
||||
* ``GuzzleHttp\Stream\Stream::__construct``,
|
||||
``GuzzleHttp\Stream\Stream::factory``, and
|
||||
``GuzzleHttp\Stream\Utils::create`` no longer accept a size in the second
|
||||
argument. They now accept an associative array of options, including the
|
||||
"size" key and "metadata" key which can be used to provide custom metadata.
|
||||
* Added ``GuzzleHttp\Stream\BufferStream`` to add support for buffering data,
|
||||
and when read, shifting data off of the buffer.
|
||||
* Added ``GuzzleHttp\Stream\NullBuffer`` which can be used as a buffer that
|
||||
does not actually store any data.
|
||||
* Added ``GuzzleHttp\Stream\AsyncStream`` to provide support for non-blocking
|
||||
streams that can be filled by a remote source (e.g., an event-loop). If a
|
||||
``drain`` option is provided, the stream can also act as if it is a blocking
|
||||
stream.
|
||||
|
||||
2.1.0 (2014-08-17)
|
||||
------------------
|
||||
|
||||
* Added an InflateStream to inflate gzipped or deflated content.
|
||||
* Added ``flush`` to stream wrapper.
|
||||
* Added the ability to easily register the GuzzleStreamWrapper if needed.
|
||||
|
||||
2.0.0 (2014-08-16)
|
||||
------------------
|
||||
|
||||
* Deprecated functions.php and moved all of those methods to
|
||||
``GuzzleHttp\Streams\Utils``. Use ``GuzzleHttp\Stream\Stream::factory()``
|
||||
instead of ``GuzzleHttp\Stream\create()`` to create new streams.
|
||||
* Added ``flush()`` to ``StreamInterface``. This method is used to flush any
|
||||
underlying stream write buffers.
|
||||
* Added ``FnStream`` to easily decorate stream behavior with callables.
|
||||
* ``Utils::hash`` now throws an exception when the stream cannot seek to 0.
|
||||
|
||||
1.5.1 (2014-09-10)
|
||||
------------------
|
||||
|
||||
* Stream metadata is grabbed from the underlying stream each time
|
||||
``getMetadata`` is called rather than returning a value from a cache.
|
||||
* Properly closing all underlying streams when AppendStream is closed.
|
||||
* Seek functions no longer throw exceptions.
|
||||
* LazyOpenStream now correctly returns the underlying stream resource when
|
||||
detached.
|
||||
|
||||
1.5.0 (2014-08-07)
|
||||
------------------
|
||||
|
||||
* Added ``Stream\safe_open`` to open stream resources and throw exceptions
|
||||
instead of raising errors.
|
||||
|
||||
1.4.0 (2014-07-19)
|
||||
------------------
|
||||
|
||||
* Added a LazyOpenStream
|
||||
|
||||
1.3.0 (2014-07-15)
|
||||
------------------
|
||||
|
||||
* Added an AppendStream to stream over multiple stream one after the other.
|
||||
|
||||
1.2.0 (2014-07-15)
|
||||
------------------
|
||||
|
||||
* Updated the ``detach()`` method to return the underlying stream resource or
|
||||
``null`` if it does not wrap a resource.
|
||||
* Multiple fixes for how streams behave when the underlying resource is
|
||||
detached
|
||||
* Do not clear statcache when a stream does not have a 'uri'
|
||||
* Added a fix to LimitStream
|
||||
* Added a condition to ensure that functions.php can be required multiple times
|
19
core/vendor/guzzlehttp/streams/LICENSE
vendored
Normal file
19
core/vendor/guzzlehttp/streams/LICENSE
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
19
core/vendor/guzzlehttp/streams/Makefile
vendored
Normal file
19
core/vendor/guzzlehttp/streams/Makefile
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
all: clean coverage
|
||||
|
||||
release: tag
|
||||
git push origin --tags
|
||||
|
||||
tag:
|
||||
chag tag --sign --debug CHANGELOG.rst
|
||||
|
||||
test:
|
||||
vendor/bin/phpunit
|
||||
|
||||
coverage:
|
||||
vendor/bin/phpunit --coverage-html=artifacts/coverage
|
||||
|
||||
view-coverage:
|
||||
open artifacts/coverage/index.html
|
||||
|
||||
clean:
|
||||
rm -rf artifacts/*
|
36
core/vendor/guzzlehttp/streams/README.rst
vendored
Normal file
36
core/vendor/guzzlehttp/streams/README.rst
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
==============
|
||||
Guzzle Streams
|
||||
==============
|
||||
|
||||
Provides a simple abstraction over streams of data.
|
||||
|
||||
This library is used in `Guzzle 5 <https://github.com/guzzle/guzzle>`_, and is
|
||||
(currently) compatible with the WIP PSR-7.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
This package can be installed easily using `Composer <http://getcomposer.org>`_.
|
||||
Simply add the following to the composer.json file at the root of your project:
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
{
|
||||
"require": {
|
||||
"guzzlehttp/streams": "~3.0"
|
||||
}
|
||||
}
|
||||
|
||||
Then install your dependencies using ``composer.phar install``.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
The documentation for this package can be found on the main Guzzle website at
|
||||
http://docs.guzzlephp.org/en/guzzle4/streams.html.
|
||||
|
||||
Testing
|
||||
=======
|
||||
|
||||
This library is tested using PHPUnit. You'll need to install the dependencies
|
||||
using `Composer <http://getcomposer.org>`_ then run ``make test``.
|
28
core/vendor/guzzlehttp/streams/composer.json
vendored
Normal file
28
core/vendor/guzzlehttp/streams/composer.json
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "guzzlehttp/streams",
|
||||
"description": "Provides a simple abstraction over streams of data",
|
||||
"homepage": "http://guzzlephp.org/",
|
||||
"keywords": ["stream", "guzzle"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "GuzzleHttp\\Stream\\": "src/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
17
core/vendor/guzzlehttp/streams/phpunit.xml.dist
vendored
Normal file
17
core/vendor/guzzlehttp/streams/phpunit.xml.dist
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="./vendor/autoload.php"
|
||||
colors="true">
|
||||
<testsuites>
|
||||
<testsuite>
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src</directory>
|
||||
<exclude>
|
||||
<file>src/functions.php</file>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
220
core/vendor/guzzlehttp/streams/src/AppendStream.php
vendored
Normal file
220
core/vendor/guzzlehttp/streams/src/AppendStream.php
vendored
Normal file
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\CannotAttachException;
|
||||
|
||||
/**
|
||||
* Reads from multiple streams, one after the other.
|
||||
*
|
||||
* This is a read-only stream decorator.
|
||||
*/
|
||||
class AppendStream implements StreamInterface
|
||||
{
|
||||
/** @var StreamInterface[] Streams being decorated */
|
||||
private $streams = [];
|
||||
|
||||
private $seekable = true;
|
||||
private $current = 0;
|
||||
private $pos = 0;
|
||||
private $detached = false;
|
||||
|
||||
/**
|
||||
* @param StreamInterface[] $streams Streams to decorate. Each stream must
|
||||
* be readable.
|
||||
*/
|
||||
public function __construct(array $streams = [])
|
||||
{
|
||||
foreach ($streams as $stream) {
|
||||
$this->addStream($stream);
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
try {
|
||||
$this->seek(0);
|
||||
return $this->getContents();
|
||||
} catch (\Exception $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a stream to the AppendStream
|
||||
*
|
||||
* @param StreamInterface $stream Stream to append. Must be readable.
|
||||
*
|
||||
* @throws \InvalidArgumentException if the stream is not readable
|
||||
*/
|
||||
public function addStream(StreamInterface $stream)
|
||||
{
|
||||
if (!$stream->isReadable()) {
|
||||
throw new \InvalidArgumentException('Each stream must be readable');
|
||||
}
|
||||
|
||||
// The stream is only seekable if all streams are seekable
|
||||
if (!$stream->isSeekable()) {
|
||||
$this->seekable = false;
|
||||
}
|
||||
|
||||
$this->streams[] = $stream;
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return Utils::copyToString($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes each attached stream.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->pos = $this->current = 0;
|
||||
|
||||
foreach ($this->streams as $stream) {
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
$this->streams = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches each attached stream
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function detach()
|
||||
{
|
||||
$this->close();
|
||||
$this->detached = true;
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
throw new CannotAttachException();
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return $this->pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to calculate the size by adding the size of each stream.
|
||||
*
|
||||
* If any of the streams do not return a valid number, then the size of the
|
||||
* append stream cannot be determined and null is returned.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
$size = 0;
|
||||
|
||||
foreach ($this->streams as $stream) {
|
||||
$s = $stream->getSize();
|
||||
if ($s === null) {
|
||||
return null;
|
||||
}
|
||||
$size += $s;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return !$this->streams ||
|
||||
($this->current >= count($this->streams) - 1 &&
|
||||
$this->streams[$this->current]->eof());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to seek to the given position. Only supports SEEK_SET.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
if (!$this->seekable || $whence !== SEEK_SET) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = true;
|
||||
$this->pos = $this->current = 0;
|
||||
|
||||
// Rewind each stream
|
||||
foreach ($this->streams as $stream) {
|
||||
if (!$stream->seek(0)) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Seek to the actual position by reading from each stream
|
||||
while ($this->pos < $offset && !$this->eof()) {
|
||||
$this->read(min(8096, $offset - $this->pos));
|
||||
}
|
||||
|
||||
return $this->pos == $offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads from all of the appended streams until the length is met or EOF.
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$buffer = '';
|
||||
$total = count($this->streams) - 1;
|
||||
$remaining = $length;
|
||||
|
||||
while ($remaining > 0) {
|
||||
// Progress to the next stream if needed.
|
||||
if ($this->streams[$this->current]->eof()) {
|
||||
if ($this->current == $total) {
|
||||
break;
|
||||
}
|
||||
$this->current++;
|
||||
}
|
||||
$buffer .= $this->streams[$this->current]->read($remaining);
|
||||
$remaining = $length - strlen($buffer);
|
||||
}
|
||||
|
||||
$this->pos += strlen($buffer);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return $this->seekable;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return $key ? null : [];
|
||||
}
|
||||
}
|
207
core/vendor/guzzlehttp/streams/src/AsyncReadStream.php
vendored
Normal file
207
core/vendor/guzzlehttp/streams/src/AsyncReadStream.php
vendored
Normal file
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Represents an asynchronous read-only stream that supports a drain event and
|
||||
* pumping data from a source stream.
|
||||
*
|
||||
* The AsyncReadStream can be used as a completely asynchronous stream, meaning
|
||||
* the data you can read from the stream will immediately return only
|
||||
* the data that is currently buffered.
|
||||
*
|
||||
* AsyncReadStream can also be used in a "blocking" manner if a "pump" function
|
||||
* is provided. When a caller requests more bytes than are available in the
|
||||
* buffer, then the pump function is used to block until the requested number
|
||||
* of bytes are available or the remote source stream has errored, closed, or
|
||||
* timed-out. This behavior isn't strictly "blocking" because the pump function
|
||||
* can send other transfers while waiting on the desired buffer size to be
|
||||
* ready for reading (e.g., continue to tick an event loop).
|
||||
*
|
||||
* @unstable This class is subject to change.
|
||||
*/
|
||||
class AsyncReadStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
/** @var callable|null Fn used to notify writers the buffer has drained */
|
||||
private $drain;
|
||||
|
||||
/** @var callable|null Fn used to block for more data */
|
||||
private $pump;
|
||||
|
||||
/** @var int|null Highwater mark of the underlying buffer */
|
||||
private $hwm;
|
||||
|
||||
/** @var bool Whether or not drain needs to be called at some point */
|
||||
private $needsDrain;
|
||||
|
||||
/** @var int The expected size of the remote source */
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* In order to utilize high water marks to tell writers to slow down, the
|
||||
* provided stream must answer to the "hwm" stream metadata variable,
|
||||
* providing the high water mark. If no "hwm" metadata value is available,
|
||||
* then the "drain" functionality is not utilized.
|
||||
*
|
||||
* This class accepts an associative array of configuration options.
|
||||
*
|
||||
* - drain: (callable) Function to invoke when the stream has drained,
|
||||
* meaning the buffer is now writable again because the size of the
|
||||
* buffer is at an acceptable level (e.g., below the high water mark).
|
||||
* The function accepts a single argument, the buffer stream object that
|
||||
* has drained.
|
||||
* - pump: (callable) A function that accepts the number of bytes to read
|
||||
* from the source stream. This function will block until all of the data
|
||||
* that was requested has been read, EOF of the source stream, or the
|
||||
* source stream is closed.
|
||||
* - size: (int) The expected size in bytes of the data that will be read
|
||||
* (if known up-front).
|
||||
*
|
||||
* @param StreamInterface $buffer Buffer that contains the data that has
|
||||
* been read by the event loop.
|
||||
* @param array $config Associative array of options.
|
||||
*
|
||||
* @throws \InvalidArgumentException if the buffer is not readable and
|
||||
* writable.
|
||||
*/
|
||||
public function __construct(
|
||||
StreamInterface $buffer,
|
||||
array $config = []
|
||||
) {
|
||||
if (!$buffer->isReadable() || !$buffer->isWritable()) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Buffer must be readable and writable'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($config['size'])) {
|
||||
$this->size = $config['size'];
|
||||
}
|
||||
|
||||
static $callables = ['pump', 'drain'];
|
||||
foreach ($callables as $check) {
|
||||
if (isset($config[$check])) {
|
||||
if (!is_callable($config[$check])) {
|
||||
throw new \InvalidArgumentException(
|
||||
$check . ' must be callable'
|
||||
);
|
||||
}
|
||||
$this->{$check} = $config[$check];
|
||||
}
|
||||
}
|
||||
|
||||
$this->hwm = $buffer->getMetadata('hwm');
|
||||
|
||||
// Cannot drain when there's no high water mark.
|
||||
if ($this->hwm === null) {
|
||||
$this->drain = null;
|
||||
}
|
||||
|
||||
$this->stream = $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method used to create new async stream and an underlying buffer
|
||||
* if no buffer is provided.
|
||||
*
|
||||
* This function accepts the same options as AsyncReadStream::__construct,
|
||||
* but added the following key value pairs:
|
||||
*
|
||||
* - buffer: (StreamInterface) Buffer used to buffer data. If none is
|
||||
* provided, a default buffer is created.
|
||||
* - hwm: (int) High water mark to use if a buffer is created on your
|
||||
* behalf.
|
||||
* - max_buffer: (int) If provided, wraps the utilized buffer in a
|
||||
* DroppingStream decorator to ensure that buffer does not exceed a given
|
||||
* length. When exceeded, the stream will begin dropping data. Set the
|
||||
* max_buffer to 0, to use a NullStream which does not store data.
|
||||
* - write: (callable) A function that is invoked when data is written
|
||||
* to the underlying buffer. The function accepts the buffer as the first
|
||||
* argument, and the data being written as the second. The function MUST
|
||||
* return the number of bytes that were written or false to let writers
|
||||
* know to slow down.
|
||||
* - drain: (callable) See constructor documentation.
|
||||
* - pump: (callable) See constructor documentation.
|
||||
*
|
||||
* @param array $options Associative array of options.
|
||||
*
|
||||
* @return array Returns an array containing the buffer used to buffer
|
||||
* data, followed by the ready to use AsyncReadStream object.
|
||||
*/
|
||||
public static function create(array $options = [])
|
||||
{
|
||||
$maxBuffer = isset($options['max_buffer'])
|
||||
? $options['max_buffer']
|
||||
: null;
|
||||
|
||||
if ($maxBuffer === 0) {
|
||||
$buffer = new NullStream();
|
||||
} elseif (isset($options['buffer'])) {
|
||||
$buffer = $options['buffer'];
|
||||
} else {
|
||||
$hwm = isset($options['hwm']) ? $options['hwm'] : 16384;
|
||||
$buffer = new BufferStream($hwm);
|
||||
}
|
||||
|
||||
if ($maxBuffer > 0) {
|
||||
$buffer = new DroppingStream($buffer, $options['max_buffer']);
|
||||
}
|
||||
|
||||
// Call the on_write callback if an on_write function was provided.
|
||||
if (isset($options['write'])) {
|
||||
$onWrite = $options['write'];
|
||||
$buffer = FnStream::decorate($buffer, [
|
||||
'write' => function ($string) use ($buffer, $onWrite) {
|
||||
$result = $buffer->write($string);
|
||||
$onWrite($buffer, $string);
|
||||
return $result;
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
return [$buffer, new self($buffer, $options)];
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
if (!$this->needsDrain && $this->drain) {
|
||||
$this->needsDrain = $this->stream->getSize() >= $this->hwm;
|
||||
}
|
||||
|
||||
$result = $this->stream->read($length);
|
||||
|
||||
// If we need to drain, then drain when the buffer is empty.
|
||||
if ($this->needsDrain && $this->stream->getSize() === 0) {
|
||||
$this->needsDrain = false;
|
||||
$drainFn = $this->drain;
|
||||
$drainFn($this->stream);
|
||||
}
|
||||
|
||||
$resultLen = strlen($result);
|
||||
|
||||
// If a pump was provided, the buffer is still open, and not enough
|
||||
// data was given, then block until the data is provided.
|
||||
if ($this->pump && $resultLen < $length) {
|
||||
$pumpFn = $this->pump;
|
||||
$result .= $pumpFn($length - $resultLen);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
138
core/vendor/guzzlehttp/streams/src/BufferStream.php
vendored
Normal file
138
core/vendor/guzzlehttp/streams/src/BufferStream.php
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\CannotAttachException;
|
||||
|
||||
/**
|
||||
* Provides a buffer stream that can be written to to fill a buffer, and read
|
||||
* from to remove bytes from the buffer.
|
||||
*
|
||||
* This stream returns a "hwm" metadata value that tells upstream consumers
|
||||
* what the configured high water mark of the stream is, or the maximum
|
||||
* preferred size of the buffer.
|
||||
*
|
||||
* @package GuzzleHttp\Stream
|
||||
*/
|
||||
class BufferStream implements StreamInterface
|
||||
{
|
||||
private $hwm;
|
||||
private $buffer = '';
|
||||
|
||||
/**
|
||||
* @param int $hwm High water mark, representing the preferred maximum
|
||||
* buffer size. If the size of the buffer exceeds the high
|
||||
* water mark, then calls to write will continue to succeed
|
||||
* but will return false to inform writers to slow down
|
||||
* until the buffer has been drained by reading from it.
|
||||
*/
|
||||
public function __construct($hwm = 16384)
|
||||
{
|
||||
$this->hwm = $hwm;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getContents();
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
$buffer = $this->buffer;
|
||||
$this->buffer = '';
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
$this->buffer = '';
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
throw new CannotAttachException();
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return strlen($this->buffer);
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return strlen($this->buffer) === 0;
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from the buffer.
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$currentLength = strlen($this->buffer);
|
||||
|
||||
if ($length >= $currentLength) {
|
||||
// No need to slice the buffer because we don't have enough data.
|
||||
$result = $this->buffer;
|
||||
$this->buffer = '';
|
||||
} else {
|
||||
// Slice up the result to provide a subset of the buffer.
|
||||
$result = substr($this->buffer, 0, $length);
|
||||
$this->buffer = substr($this->buffer, $length);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes data to the buffer.
|
||||
*/
|
||||
public function write($string)
|
||||
{
|
||||
$this->buffer .= $string;
|
||||
|
||||
if (strlen($this->buffer) >= $this->hwm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
if ($key == 'hwm') {
|
||||
return $this->hwm;
|
||||
}
|
||||
|
||||
return $key ? null : [];
|
||||
}
|
||||
}
|
122
core/vendor/guzzlehttp/streams/src/CachingStream.php
vendored
Normal file
122
core/vendor/guzzlehttp/streams/src/CachingStream.php
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\SeekException;
|
||||
|
||||
/**
|
||||
* Stream decorator that can cache previously read bytes from a sequentially
|
||||
* read stream.
|
||||
*/
|
||||
class CachingStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
/** @var StreamInterface Stream being wrapped */
|
||||
private $remoteStream;
|
||||
|
||||
/** @var int Number of bytes to skip reading due to a write on the buffer */
|
||||
private $skipReadBytes = 0;
|
||||
|
||||
/**
|
||||
* We will treat the buffer object as the body of the stream
|
||||
*
|
||||
* @param StreamInterface $stream Stream to cache
|
||||
* @param StreamInterface $target Optionally specify where data is cached
|
||||
*/
|
||||
public function __construct(
|
||||
StreamInterface $stream,
|
||||
StreamInterface $target = null
|
||||
) {
|
||||
$this->remoteStream = $stream;
|
||||
$this->stream = $target ?: new Stream(fopen('php://temp', 'r+'));
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return max($this->stream->getSize(), $this->remoteStream->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @throws SeekException When seeking with SEEK_END or when seeking
|
||||
* past the total size of the buffer stream
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
if ($whence == SEEK_SET) {
|
||||
$byte = $offset;
|
||||
} elseif ($whence == SEEK_CUR) {
|
||||
$byte = $offset + $this->tell();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// You cannot skip ahead past where you've read from the remote stream
|
||||
if ($byte > $this->stream->getSize()) {
|
||||
throw new SeekException(
|
||||
$this,
|
||||
$byte,
|
||||
sprintf('Cannot seek to byte %d when the buffered stream only'
|
||||
. ' contains %d bytes', $byte, $this->stream->getSize())
|
||||
);
|
||||
}
|
||||
|
||||
return $this->stream->seek($byte);
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
// Perform a regular read on any previously read data from the buffer
|
||||
$data = $this->stream->read($length);
|
||||
$remaining = $length - strlen($data);
|
||||
|
||||
// More data was requested so read from the remote stream
|
||||
if ($remaining) {
|
||||
// If data was written to the buffer in a position that would have
|
||||
// been filled from the remote stream, then we must skip bytes on
|
||||
// the remote stream to emulate overwriting bytes from that
|
||||
// position. This mimics the behavior of other PHP stream wrappers.
|
||||
$remoteData = $this->remoteStream->read(
|
||||
$remaining + $this->skipReadBytes
|
||||
);
|
||||
|
||||
if ($this->skipReadBytes) {
|
||||
$len = strlen($remoteData);
|
||||
$remoteData = substr($remoteData, $this->skipReadBytes);
|
||||
$this->skipReadBytes = max(0, $this->skipReadBytes - $len);
|
||||
}
|
||||
|
||||
$data .= $remoteData;
|
||||
$this->stream->write($remoteData);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
// When appending to the end of the currently read stream, you'll want
|
||||
// to skip bytes from being read from the remote stream to emulate
|
||||
// other stream wrappers. Basically replacing bytes of data of a fixed
|
||||
// length.
|
||||
$overflow = (strlen($string) + $this->tell()) - $this->remoteStream->tell();
|
||||
if ($overflow > 0) {
|
||||
$this->skipReadBytes += $overflow;
|
||||
}
|
||||
|
||||
return $this->stream->write($string);
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return $this->stream->eof() && $this->remoteStream->eof();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close both the remote stream and buffer stream
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->remoteStream->close() && $this->stream->close();
|
||||
}
|
||||
}
|
42
core/vendor/guzzlehttp/streams/src/DroppingStream.php
vendored
Normal file
42
core/vendor/guzzlehttp/streams/src/DroppingStream.php
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Stream decorator that begins dropping data once the size of the underlying
|
||||
* stream becomes too full.
|
||||
*/
|
||||
class DroppingStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
private $maxLength;
|
||||
|
||||
/**
|
||||
* @param StreamInterface $stream Underlying stream to decorate.
|
||||
* @param int $maxLength Maximum size before dropping data.
|
||||
*/
|
||||
public function __construct(StreamInterface $stream, $maxLength)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$this->maxLength = $maxLength;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
$diff = $this->maxLength - $this->stream->getSize();
|
||||
|
||||
// Begin returning false when the underlying stream is too large.
|
||||
if ($diff <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write the stream or a subset of the stream if needed.
|
||||
if (strlen($string) < $diff) {
|
||||
return $this->stream->write($string);
|
||||
}
|
||||
|
||||
$this->stream->write(substr($string, 0, $diff));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
4
core/vendor/guzzlehttp/streams/src/Exception/CannotAttachException.php
vendored
Normal file
4
core/vendor/guzzlehttp/streams/src/Exception/CannotAttachException.php
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream\Exception;
|
||||
|
||||
class CannotAttachException extends \RuntimeException {}
|
27
core/vendor/guzzlehttp/streams/src/Exception/SeekException.php
vendored
Normal file
27
core/vendor/guzzlehttp/streams/src/Exception/SeekException.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream\Exception;
|
||||
|
||||
use GuzzleHttp\Stream\StreamInterface;
|
||||
|
||||
/**
|
||||
* Exception thrown when a seek fails on a stream.
|
||||
*/
|
||||
class SeekException extends \RuntimeException
|
||||
{
|
||||
private $stream;
|
||||
|
||||
public function __construct(StreamInterface $stream, $pos = 0, $msg = '')
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$msg = $msg ?: 'Could not seek the stream to position ' . $pos;
|
||||
parent::__construct($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StreamInterface
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->stream;
|
||||
}
|
||||
}
|
147
core/vendor/guzzlehttp/streams/src/FnStream.php
vendored
Normal file
147
core/vendor/guzzlehttp/streams/src/FnStream.php
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Compose stream implementations based on a hash of functions.
|
||||
*
|
||||
* Allows for easy testing and extension of a provided stream without needing
|
||||
* to create a concrete class for a simple extension point.
|
||||
*/
|
||||
class FnStream implements StreamInterface
|
||||
{
|
||||
/** @var array */
|
||||
private $methods;
|
||||
|
||||
/** @var array Methods that must be implemented in the given array */
|
||||
private static $slots = ['__toString', 'close', 'detach', 'attach',
|
||||
'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
|
||||
'isReadable', 'read', 'getContents', 'getMetadata'];
|
||||
|
||||
/**
|
||||
* @param array $methods Hash of method name to a callable.
|
||||
*/
|
||||
public function __construct(array $methods)
|
||||
{
|
||||
$this->methods = $methods;
|
||||
|
||||
// Create the functions on the class
|
||||
foreach ($methods as $name => $fn) {
|
||||
$this->{'_fn_' . $name} = $fn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily determine which methods are not implemented.
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
throw new \BadMethodCallException(str_replace('_fn_', '', $name)
|
||||
. '() is not implemented in the FnStream');
|
||||
}
|
||||
|
||||
/**
|
||||
* The close method is called on the underlying stream only if possible.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (isset($this->_fn_close)) {
|
||||
call_user_func($this->_fn_close);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds custom functionality to an underlying stream by intercepting
|
||||
* specific method calls.
|
||||
*
|
||||
* @param StreamInterface $stream Stream to decorate
|
||||
* @param array $methods Hash of method name to a closure
|
||||
*
|
||||
* @return FnStream
|
||||
*/
|
||||
public static function decorate(StreamInterface $stream, array $methods)
|
||||
{
|
||||
// If any of the required methods were not provided, then simply
|
||||
// proxy to the decorated stream.
|
||||
foreach (array_diff(self::$slots, array_keys($methods)) as $diff) {
|
||||
$methods[$diff] = [$stream, $diff];
|
||||
}
|
||||
|
||||
return new self($methods);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return call_user_func($this->_fn___toString);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return call_user_func($this->_fn_close);
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
return call_user_func($this->_fn_detach);
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
return call_user_func($this->_fn_attach, $stream);
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return call_user_func($this->_fn_getSize);
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return call_user_func($this->_fn_tell);
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return call_user_func($this->_fn_eof);
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return call_user_func($this->_fn_isSeekable);
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return call_user_func($this->_fn_seek, $offset, $whence);
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return call_user_func($this->_fn_isWritable);
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return call_user_func($this->_fn_write, $string);
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return call_user_func($this->_fn_isReadable);
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
return call_user_func($this->_fn_read, $length);
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return call_user_func($this->_fn_getContents);
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return call_user_func($this->_fn_getMetadata, $key);
|
||||
}
|
||||
}
|
117
core/vendor/guzzlehttp/streams/src/GuzzleStreamWrapper.php
vendored
Normal file
117
core/vendor/guzzlehttp/streams/src/GuzzleStreamWrapper.php
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Converts Guzzle streams into PHP stream resources.
|
||||
*/
|
||||
class GuzzleStreamWrapper
|
||||
{
|
||||
/** @var resource */
|
||||
public $context;
|
||||
|
||||
/** @var StreamInterface */
|
||||
private $stream;
|
||||
|
||||
/** @var string r, r+, or w */
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* Returns a resource representing the stream.
|
||||
*
|
||||
* @param StreamInterface $stream The stream to get a resource for
|
||||
*
|
||||
* @return resource
|
||||
* @throws \InvalidArgumentException if stream is not readable or writable
|
||||
*/
|
||||
public static function getResource(StreamInterface $stream)
|
||||
{
|
||||
self::register();
|
||||
|
||||
if ($stream->isReadable()) {
|
||||
$mode = $stream->isWritable() ? 'r+' : 'r';
|
||||
} elseif ($stream->isWritable()) {
|
||||
$mode = 'w';
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The stream must be readable, '
|
||||
. 'writable, or both.');
|
||||
}
|
||||
|
||||
return fopen('guzzle://stream', $mode, null, stream_context_create([
|
||||
'guzzle' => ['stream' => $stream]
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the stream wrapper if needed
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
if (!in_array('guzzle', stream_get_wrappers())) {
|
||||
stream_wrapper_register('guzzle', __CLASS__);
|
||||
}
|
||||
}
|
||||
|
||||
public function stream_open($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
$options = stream_context_get_options($this->context);
|
||||
|
||||
if (!isset($options['guzzle']['stream'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->mode = $mode;
|
||||
$this->stream = $options['guzzle']['stream'];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function stream_read($count)
|
||||
{
|
||||
return $this->stream->read($count);
|
||||
}
|
||||
|
||||
public function stream_write($data)
|
||||
{
|
||||
return (int) $this->stream->write($data);
|
||||
}
|
||||
|
||||
public function stream_tell()
|
||||
{
|
||||
return $this->stream->tell();
|
||||
}
|
||||
|
||||
public function stream_eof()
|
||||
{
|
||||
return $this->stream->eof();
|
||||
}
|
||||
|
||||
public function stream_seek($offset, $whence)
|
||||
{
|
||||
return $this->stream->seek($offset, $whence);
|
||||
}
|
||||
|
||||
public function stream_stat()
|
||||
{
|
||||
static $modeMap = [
|
||||
'r' => 33060,
|
||||
'r+' => 33206,
|
||||
'w' => 33188
|
||||
];
|
||||
|
||||
return [
|
||||
'dev' => 0,
|
||||
'ino' => 0,
|
||||
'mode' => $modeMap[$this->mode],
|
||||
'nlink' => 0,
|
||||
'uid' => 0,
|
||||
'gid' => 0,
|
||||
'rdev' => 0,
|
||||
'size' => $this->stream->getSize() ?: 0,
|
||||
'atime' => 0,
|
||||
'mtime' => 0,
|
||||
'ctime' => 0,
|
||||
'blksize' => 0,
|
||||
'blocks' => 0
|
||||
];
|
||||
}
|
||||
}
|
27
core/vendor/guzzlehttp/streams/src/InflateStream.php
vendored
Normal file
27
core/vendor/guzzlehttp/streams/src/InflateStream.php
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.
|
||||
*
|
||||
* This stream decorator skips the first 10 bytes of the given stream to remove
|
||||
* the gzip header, converts the provided stream to a PHP stream resource,
|
||||
* then appends the zlib.inflate filter. The stream is then converted back
|
||||
* to a Guzzle stream resource to be used as a Guzzle stream.
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc1952
|
||||
* @link http://php.net/manual/en/filters.compression.php
|
||||
*/
|
||||
class InflateStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
public function __construct(StreamInterface $stream)
|
||||
{
|
||||
// Skip the first 10 bytes
|
||||
$stream = new LimitStream($stream, -1, 10);
|
||||
$resource = GuzzleStreamWrapper::getResource($stream);
|
||||
stream_filter_append($resource, 'zlib.inflate', STREAM_FILTER_READ);
|
||||
$this->stream = new Stream($resource);
|
||||
}
|
||||
}
|
37
core/vendor/guzzlehttp/streams/src/LazyOpenStream.php
vendored
Normal file
37
core/vendor/guzzlehttp/streams/src/LazyOpenStream.php
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Lazily reads or writes to a file that is opened only after an IO operation
|
||||
* take place on the stream.
|
||||
*/
|
||||
class LazyOpenStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
/** @var string File to open */
|
||||
private $filename;
|
||||
|
||||
/** @var string $mode */
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* @param string $filename File to lazily open
|
||||
* @param string $mode fopen mode to use when opening the stream
|
||||
*/
|
||||
public function __construct($filename, $mode)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the underlying stream lazily when required.
|
||||
*
|
||||
* @return StreamInterface
|
||||
*/
|
||||
protected function createStream()
|
||||
{
|
||||
return Stream::factory(Utils::open($this->filename, $this->mode));
|
||||
}
|
||||
}
|
161
core/vendor/guzzlehttp/streams/src/LimitStream.php
vendored
Normal file
161
core/vendor/guzzlehttp/streams/src/LimitStream.php
vendored
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\SeekException;
|
||||
|
||||
/**
|
||||
* Decorator used to return only a subset of a stream
|
||||
*/
|
||||
class LimitStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
/** @var int Offset to start reading from */
|
||||
private $offset;
|
||||
|
||||
/** @var int Limit the number of bytes that can be read */
|
||||
private $limit;
|
||||
|
||||
/**
|
||||
* @param StreamInterface $stream Stream to wrap
|
||||
* @param int $limit Total number of bytes to allow to be read
|
||||
* from the stream. Pass -1 for no limit.
|
||||
* @param int|null $offset Position to seek to before reading (only
|
||||
* works on seekable streams).
|
||||
*/
|
||||
public function __construct(
|
||||
StreamInterface $stream,
|
||||
$limit = -1,
|
||||
$offset = 0
|
||||
) {
|
||||
$this->stream = $stream;
|
||||
$this->setLimit($limit);
|
||||
$this->setOffset($offset);
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
// Always return true if the underlying stream is EOF
|
||||
if ($this->stream->eof()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// No limit and the underlying stream is not at EOF
|
||||
if ($this->limit == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tell = $this->stream->tell();
|
||||
if ($tell === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $tell >= $this->offset + $this->limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the limited subset of data
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
if (null === ($length = $this->stream->getSize())) {
|
||||
return null;
|
||||
} elseif ($this->limit == -1) {
|
||||
return $length - $this->offset;
|
||||
} else {
|
||||
return min($this->limit, $length - $this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow for a bounded seek on the read limited stream
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
if ($whence !== SEEK_SET || $offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$offset += $this->offset;
|
||||
|
||||
if ($this->limit !== -1) {
|
||||
if ($offset > $this->offset + $this->limit) {
|
||||
$offset = $this->offset + $this->limit;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->stream->seek($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give a relative tell()
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tell()
|
||||
{
|
||||
return $this->stream->tell() - $this->offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the offset to start limiting from
|
||||
*
|
||||
* @param int $offset Offset to seek to and begin byte limiting from
|
||||
*
|
||||
* @return self
|
||||
* @throws SeekException
|
||||
*/
|
||||
public function setOffset($offset)
|
||||
{
|
||||
$current = $this->stream->tell();
|
||||
|
||||
if ($current !== $offset) {
|
||||
// If the stream cannot seek to the offset position, then read to it
|
||||
if (!$this->stream->seek($offset)) {
|
||||
if ($current > $offset) {
|
||||
throw new SeekException($this, $offset);
|
||||
} else {
|
||||
$this->stream->read($offset - $current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->offset = $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the limit of bytes that the decorator allows to be read from the
|
||||
* stream.
|
||||
*
|
||||
* @param int $limit Number of bytes to allow to be read from the stream.
|
||||
* Use -1 for no limit.
|
||||
* @return self
|
||||
*/
|
||||
public function setLimit($limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->limit == -1) {
|
||||
return $this->stream->read($length);
|
||||
}
|
||||
|
||||
// Check if the current position is less than the total allowed
|
||||
// bytes + original offset
|
||||
$remaining = ($this->offset + $this->limit) - $this->stream->tell();
|
||||
if ($remaining > 0) {
|
||||
// Only return the amount of requested data, ensuring that the byte
|
||||
// limit is not exceeded
|
||||
return $this->stream->read(min($remaining, $length));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
core/vendor/guzzlehttp/streams/src/MetadataStreamInterface.php
vendored
Normal file
11
core/vendor/guzzlehttp/streams/src/MetadataStreamInterface.php
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* This interface is deprecated and should no longer be used. Just use
|
||||
* StreamInterface now that the getMetadata method has been added to
|
||||
* StreamInterface.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
interface MetadataStreamInterface extends StreamInterface {}
|
25
core/vendor/guzzlehttp/streams/src/NoSeekStream.php
vendored
Normal file
25
core/vendor/guzzlehttp/streams/src/NoSeekStream.php
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Stream decorator that prevents a stream from being seeked
|
||||
*/
|
||||
class NoSeekStream implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
$this->stream->attach($stream);
|
||||
}
|
||||
}
|
78
core/vendor/guzzlehttp/streams/src/NullStream.php
vendored
Normal file
78
core/vendor/guzzlehttp/streams/src/NullStream.php
vendored
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
use GuzzleHttp\Stream\Exception\CannotAttachException;
|
||||
|
||||
/**
|
||||
* Does not store any data written to it.
|
||||
*/
|
||||
class NullStream implements StreamInterface
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function close() {}
|
||||
|
||||
public function detach() {}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
throw new CannotAttachException();
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return $key ? null : [];
|
||||
}
|
||||
}
|
161
core/vendor/guzzlehttp/streams/src/PumpStream.php
vendored
Normal file
161
core/vendor/guzzlehttp/streams/src/PumpStream.php
vendored
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\CannotAttachException;
|
||||
|
||||
/**
|
||||
* Provides a read only stream that pumps data from a PHP callable.
|
||||
*
|
||||
* When invoking the provided callable, the PumpStream will pass the amount of
|
||||
* data requested to read to the callable. The callable can choose to ignore
|
||||
* this value and return fewer or more bytes than requested. Any extra data
|
||||
* returned by the provided callable is buffered internally until drained using
|
||||
* the read() function of the PumpStream. The provided callable MUST return
|
||||
* false when there is no more data to read.
|
||||
*/
|
||||
class PumpStream implements StreamInterface
|
||||
{
|
||||
/** @var callable */
|
||||
private $source;
|
||||
|
||||
/** @var int */
|
||||
private $size;
|
||||
|
||||
/** @var int */
|
||||
private $tellPos = 0;
|
||||
|
||||
/** @var array */
|
||||
private $metadata;
|
||||
|
||||
/** @var BufferStream */
|
||||
private $buffer;
|
||||
|
||||
/**
|
||||
* @param callable $source Source of the stream data. The callable MAY
|
||||
* accept an integer argument used to control the
|
||||
* amount of data to return. The callable MUST
|
||||
* return a string when called, or false on error
|
||||
* or EOF.
|
||||
* @param array $options Stream options:
|
||||
* - metadata: Hash of metadata to use with stream.
|
||||
* - size: Size of the stream, if known.
|
||||
*/
|
||||
public function __construct(callable $source, array $options = [])
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->size = isset($options['size']) ? $options['size'] : null;
|
||||
$this->metadata = isset($options['metadata']) ? $options['metadata'] : [];
|
||||
$this->buffer = new BufferStream();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return Utils::copyToString($this);
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
$this->detach();
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
$this->tellPos = false;
|
||||
$this->source = null;
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
throw new CannotAttachException();
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return $this->tellPos;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return !$this->source;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
$data = $this->buffer->read($length);
|
||||
$readLen = strlen($data);
|
||||
$this->tellPos += $readLen;
|
||||
$remaining = $length - $readLen;
|
||||
|
||||
if ($remaining) {
|
||||
$this->pump($remaining);
|
||||
$data .= $this->buffer->read($remaining);
|
||||
$this->tellPos += strlen($data) - $readLen;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
$result = '';
|
||||
while (!$this->eof()) {
|
||||
$result .= $this->read(1000000);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
if (!$key) {
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
return isset($this->metadata[$key]) ? $this->metadata[$key] : null;
|
||||
}
|
||||
|
||||
private function pump($length)
|
||||
{
|
||||
if ($this->source) {
|
||||
do {
|
||||
$data = call_user_func($this->source, $length);
|
||||
if ($data === false || $data === null) {
|
||||
$this->source = null;
|
||||
return;
|
||||
}
|
||||
$this->buffer->write($data);
|
||||
$length -= strlen($data);
|
||||
} while ($length > 0);
|
||||
}
|
||||
}
|
||||
}
|
261
core/vendor/guzzlehttp/streams/src/Stream.php
vendored
Normal file
261
core/vendor/guzzlehttp/streams/src/Stream.php
vendored
Normal file
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* PHP stream implementation
|
||||
*/
|
||||
class Stream implements StreamInterface
|
||||
{
|
||||
private $stream;
|
||||
private $size;
|
||||
private $seekable;
|
||||
private $readable;
|
||||
private $writable;
|
||||
private $uri;
|
||||
private $customMetadata;
|
||||
|
||||
/** @var array Hash of readable and writable stream types */
|
||||
private static $readWriteHash = [
|
||||
'read' => [
|
||||
'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
|
||||
'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
|
||||
'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
|
||||
'x+t' => true, 'c+t' => true, 'a+' => true
|
||||
],
|
||||
'write' => [
|
||||
'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
|
||||
'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true,
|
||||
'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
|
||||
'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new stream based on the input type.
|
||||
*
|
||||
* This factory accepts the same associative array of options as described
|
||||
* in the constructor.
|
||||
*
|
||||
* @param resource|string|StreamInterface $resource Entity body data
|
||||
* @param array $options Additional options
|
||||
*
|
||||
* @return Stream
|
||||
* @throws \InvalidArgumentException if the $resource arg is not valid.
|
||||
*/
|
||||
public static function factory($resource = '', array $options = [])
|
||||
{
|
||||
$type = gettype($resource);
|
||||
|
||||
if ($type == 'string') {
|
||||
$stream = fopen('php://temp', 'r+');
|
||||
if ($resource !== '') {
|
||||
fwrite($stream, $resource);
|
||||
fseek($stream, 0);
|
||||
}
|
||||
return new self($stream, $options);
|
||||
}
|
||||
|
||||
if ($type == 'resource') {
|
||||
return new self($resource, $options);
|
||||
}
|
||||
|
||||
if ($resource instanceof StreamInterface) {
|
||||
return $resource;
|
||||
}
|
||||
|
||||
if ($type == 'object' && method_exists($resource, '__toString')) {
|
||||
return self::factory((string) $resource, $options);
|
||||
}
|
||||
|
||||
if (is_callable($resource)) {
|
||||
return new PumpStream($resource, $options);
|
||||
}
|
||||
|
||||
if ($resource instanceof \Iterator) {
|
||||
return new PumpStream(function () use ($resource) {
|
||||
if (!$resource->valid()) {
|
||||
return false;
|
||||
}
|
||||
$result = $resource->current();
|
||||
$resource->next();
|
||||
return $result;
|
||||
}, $options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Invalid resource type: ' . $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor accepts an associative array of options.
|
||||
*
|
||||
* - size: (int) If a read stream would otherwise have an indeterminate
|
||||
* size, but the size is known due to foreknownledge, then you can
|
||||
* provide that size, in bytes.
|
||||
* - metadata: (array) Any additional metadata to return when the metadata
|
||||
* of the stream is accessed.
|
||||
*
|
||||
* @param resource $stream Stream resource to wrap.
|
||||
* @param array $options Associative array of options.
|
||||
*
|
||||
* @throws \InvalidArgumentException if the stream is not a stream resource
|
||||
*/
|
||||
public function __construct($stream, $options = [])
|
||||
{
|
||||
if (!is_resource($stream)) {
|
||||
throw new \InvalidArgumentException('Stream must be a resource');
|
||||
}
|
||||
|
||||
if (isset($options['size'])) {
|
||||
$this->size = $options['size'];
|
||||
}
|
||||
|
||||
$this->customMetadata = isset($options['metadata'])
|
||||
? $options['metadata']
|
||||
: [];
|
||||
|
||||
$this->attach($stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the stream when the destructed
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
if (!$this->stream) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$this->seek(0);
|
||||
|
||||
return (string) stream_get_contents($this->stream);
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return $this->stream ? stream_get_contents($this->stream) : '';
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if (is_resource($this->stream)) {
|
||||
fclose($this->stream);
|
||||
}
|
||||
|
||||
$this->detach();
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
$result = $this->stream;
|
||||
$this->stream = $this->size = $this->uri = null;
|
||||
$this->readable = $this->writable = $this->seekable = false;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$meta = stream_get_meta_data($this->stream);
|
||||
$this->seekable = $meta['seekable'];
|
||||
$this->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
|
||||
$this->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
|
||||
$this->uri = $this->getMetadata('uri');
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
if ($this->size !== null) {
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
if (!$this->stream) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Clear the stat cache if the stream has a URI
|
||||
if ($this->uri) {
|
||||
clearstatcache(true, $this->uri);
|
||||
}
|
||||
|
||||
$stats = fstat($this->stream);
|
||||
if (isset($stats['size'])) {
|
||||
$this->size = $stats['size'];
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return $this->readable;
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return $this->writable;
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return $this->seekable;
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return !$this->stream || feof($this->stream);
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return $this->stream ? ftell($this->stream) : false;
|
||||
}
|
||||
|
||||
public function setSize($size)
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return $this->seekable
|
||||
? fseek($this->stream, $offset, $whence) === 0
|
||||
: false;
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
return $this->readable ? fread($this->stream, $length) : false;
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
// We can't know the size after writing anything
|
||||
$this->size = null;
|
||||
|
||||
return $this->writable ? fwrite($this->stream, $string) : false;
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
if (!$this->stream) {
|
||||
return $key ? null : [];
|
||||
} elseif (!$key) {
|
||||
return $this->customMetadata + stream_get_meta_data($this->stream);
|
||||
} elseif (isset($this->customMetadata[$key])) {
|
||||
return $this->customMetadata[$key];
|
||||
}
|
||||
|
||||
$meta = stream_get_meta_data($this->stream);
|
||||
|
||||
return isset($meta[$key]) ? $meta[$key] : null;
|
||||
}
|
||||
}
|
143
core/vendor/guzzlehttp/streams/src/StreamDecoratorTrait.php
vendored
Normal file
143
core/vendor/guzzlehttp/streams/src/StreamDecoratorTrait.php
vendored
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
use GuzzleHttp\Stream\Exception\CannotAttachException;
|
||||
|
||||
/**
|
||||
* Stream decorator trait
|
||||
* @property StreamInterface stream
|
||||
*/
|
||||
trait StreamDecoratorTrait
|
||||
{
|
||||
/**
|
||||
* @param StreamInterface $stream Stream to decorate
|
||||
*/
|
||||
public function __construct(StreamInterface $stream)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method used to create a new stream if streams are not added in
|
||||
* the constructor of a decorator (e.g., LazyOpenStream).
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'stream') {
|
||||
$this->stream = $this->createStream();
|
||||
return $this->stream;
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException("$name not found on class");
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
try {
|
||||
$this->seek(0);
|
||||
return $this->getContents();
|
||||
} catch (\Exception $e) {
|
||||
// Really, PHP? https://bugs.php.net/bug.php?id=53648
|
||||
trigger_error('StreamDecorator::__toString exception: '
|
||||
. (string) $e, E_USER_ERROR);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return Utils::copyToString($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow decorators to implement custom methods
|
||||
*
|
||||
* @param string $method Missing method name
|
||||
* @param array $args Method arguments
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, array $args)
|
||||
{
|
||||
$result = call_user_func_array(array($this->stream, $method), $args);
|
||||
|
||||
// Always return the wrapped object if the result is a return $this
|
||||
return $result === $this->stream ? $this : $result;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
$this->stream->close();
|
||||
}
|
||||
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return $this->stream->getMetadata($key);
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
return $this->stream->detach();
|
||||
}
|
||||
|
||||
public function attach($stream)
|
||||
{
|
||||
throw new CannotAttachException();
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return $this->stream->getSize();
|
||||
}
|
||||
|
||||
public function eof()
|
||||
{
|
||||
return $this->stream->eof();
|
||||
}
|
||||
|
||||
public function tell()
|
||||
{
|
||||
return $this->stream->tell();
|
||||
}
|
||||
|
||||
public function isReadable()
|
||||
{
|
||||
return $this->stream->isReadable();
|
||||
}
|
||||
|
||||
public function isWritable()
|
||||
{
|
||||
return $this->stream->isWritable();
|
||||
}
|
||||
|
||||
public function isSeekable()
|
||||
{
|
||||
return $this->stream->isSeekable();
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = SEEK_SET)
|
||||
{
|
||||
return $this->stream->seek($offset, $whence);
|
||||
}
|
||||
|
||||
public function read($length)
|
||||
{
|
||||
return $this->stream->read($length);
|
||||
}
|
||||
|
||||
public function write($string)
|
||||
{
|
||||
return $this->stream->write($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement in subclasses to dynamically create streams when requested.
|
||||
*
|
||||
* @return StreamInterface
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
protected function createStream()
|
||||
{
|
||||
throw new \BadMethodCallException('createStream() not implemented in '
|
||||
. get_class($this));
|
||||
}
|
||||
}
|
159
core/vendor/guzzlehttp/streams/src/StreamInterface.php
vendored
Normal file
159
core/vendor/guzzlehttp/streams/src/StreamInterface.php
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
/**
|
||||
* Describes a stream instance.
|
||||
*/
|
||||
interface StreamInterface
|
||||
{
|
||||
/**
|
||||
* Attempts to seek to the beginning of the stream and reads all data into
|
||||
* a string until the end of the stream is reached.
|
||||
*
|
||||
* Warning: This could attempt to load a large amount of data into memory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
|
||||
/**
|
||||
* Closes the stream and any underlying resources.
|
||||
*/
|
||||
public function close();
|
||||
|
||||
/**
|
||||
* Separates any underlying resources from the stream.
|
||||
*
|
||||
* After the underlying resource has been detached, the stream object is in
|
||||
* an unusable state. If you wish to use a Stream object as a PHP stream
|
||||
* but keep the Stream object in a consistent state, use
|
||||
* {@see GuzzleHttp\Stream\GuzzleStreamWrapper::getResource}.
|
||||
*
|
||||
* @return resource|null Returns the underlying PHP stream resource or null
|
||||
* if the Stream object did not utilize an underlying
|
||||
* stream resource.
|
||||
*/
|
||||
public function detach();
|
||||
|
||||
/**
|
||||
* Replaces the underlying stream resource with the provided stream.
|
||||
*
|
||||
* Use this method to replace the underlying stream with another; as an
|
||||
* example, in server-side code, if you decide to return a file, you
|
||||
* would replace the original content-oriented stream with the file
|
||||
* stream.
|
||||
*
|
||||
* Any internal state such as caching of cursor position should be reset
|
||||
* when attach() is called, as the stream has changed.
|
||||
*
|
||||
* @param resource $stream
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function attach($stream);
|
||||
|
||||
/**
|
||||
* Get the size of the stream if known
|
||||
*
|
||||
* @return int|null Returns the size in bytes if known, or null if unknown
|
||||
*/
|
||||
public function getSize();
|
||||
|
||||
/**
|
||||
* Returns the current position of the file read/write pointer
|
||||
*
|
||||
* @return int|bool Returns the position of the file pointer or false on error
|
||||
*/
|
||||
public function tell();
|
||||
|
||||
/**
|
||||
* Returns true if the stream is at the end of the stream.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function eof();
|
||||
|
||||
/**
|
||||
* Returns whether or not the stream is seekable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSeekable();
|
||||
|
||||
/**
|
||||
* Seek to a position in the stream
|
||||
*
|
||||
* @param int $offset Stream offset
|
||||
* @param int $whence Specifies how the cursor position will be calculated
|
||||
* based on the seek offset. Valid values are identical
|
||||
* to the built-in PHP $whence values for `fseek()`.
|
||||
* SEEK_SET: Set position equal to offset bytes
|
||||
* SEEK_CUR: Set position to current location plus offset
|
||||
* SEEK_END: Set position to end-of-stream plus offset
|
||||
*
|
||||
* @return bool Returns true on success or false on failure
|
||||
* @link http://www.php.net/manual/en/function.fseek.php
|
||||
*/
|
||||
public function seek($offset, $whence = SEEK_SET);
|
||||
|
||||
/**
|
||||
* Returns whether or not the stream is writable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isWritable();
|
||||
|
||||
/**
|
||||
* Write data to the stream
|
||||
*
|
||||
* @param string $string The string that is to be written.
|
||||
*
|
||||
* @return int|bool Returns the number of bytes written to the stream on
|
||||
* success returns false on failure (e.g., broken pipe,
|
||||
* writer needs to slow down, buffer is full, etc.)
|
||||
*/
|
||||
public function write($string);
|
||||
|
||||
/**
|
||||
* Returns whether or not the stream is readable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadable();
|
||||
|
||||
/**
|
||||
* Read data from the stream
|
||||
*
|
||||
* @param int $length Read up to $length bytes from the object and return
|
||||
* them. Fewer than $length bytes may be returned if
|
||||
* underlying stream call returns fewer bytes.
|
||||
*
|
||||
* @return string Returns the data read from the stream.
|
||||
*/
|
||||
public function read($length);
|
||||
|
||||
/**
|
||||
* Returns the remaining contents of the stream as a string.
|
||||
*
|
||||
* Note: this could potentially load a large amount of data into memory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContents();
|
||||
|
||||
/**
|
||||
* Get stream metadata as an associative array or retrieve a specific key.
|
||||
*
|
||||
* The keys returned are identical to the keys returned from PHP's
|
||||
* stream_get_meta_data() function.
|
||||
*
|
||||
* @param string $key Specific metadata to retrieve.
|
||||
*
|
||||
* @return array|mixed|null Returns an associative array if no key is
|
||||
* no key is provided. Returns a specific key
|
||||
* value if a key is provided and the value is
|
||||
* found, or null if the key is not found.
|
||||
* @see http://php.net/manual/en/function.stream-get-meta-data.php
|
||||
*/
|
||||
public function getMetadata($key = null);
|
||||
}
|
196
core/vendor/guzzlehttp/streams/src/Utils.php
vendored
Normal file
196
core/vendor/guzzlehttp/streams/src/Utils.php
vendored
Normal file
|
@ -0,0 +1,196 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\SeekException;
|
||||
|
||||
/**
|
||||
* Static utility class because PHP's autoloaders don't support the concept
|
||||
* of namespaced function autoloading.
|
||||
*/
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* Safely opens a PHP stream resource using a filename.
|
||||
*
|
||||
* When fopen fails, PHP normally raises a warning. This function adds an
|
||||
* error handler that checks for errors and throws an exception instead.
|
||||
*
|
||||
* @param string $filename File to open
|
||||
* @param string $mode Mode used to open the file
|
||||
*
|
||||
* @return resource
|
||||
* @throws \RuntimeException if the file cannot be opened
|
||||
*/
|
||||
public static function open($filename, $mode)
|
||||
{
|
||||
$ex = null;
|
||||
set_error_handler(function () use ($filename, $mode, &$ex) {
|
||||
$ex = new \RuntimeException(sprintf(
|
||||
'Unable to open %s using mode %s: %s',
|
||||
$filename,
|
||||
$mode,
|
||||
func_get_args()[1]
|
||||
));
|
||||
});
|
||||
|
||||
$handle = fopen($filename, $mode);
|
||||
restore_error_handler();
|
||||
|
||||
if ($ex) {
|
||||
/** @var $ex \RuntimeException */
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the contents of a stream into a string until the given number of
|
||||
* bytes have been read.
|
||||
*
|
||||
* @param StreamInterface $stream Stream to read
|
||||
* @param int $maxLen Maximum number of bytes to read. Pass -1
|
||||
* to read the entire stream.
|
||||
* @return string
|
||||
*/
|
||||
public static function copyToString(StreamInterface $stream, $maxLen = -1)
|
||||
{
|
||||
$buffer = '';
|
||||
|
||||
if ($maxLen === -1) {
|
||||
while (!$stream->eof()) {
|
||||
$buf = $stream->read(1048576);
|
||||
if ($buf === false) {
|
||||
break;
|
||||
}
|
||||
$buffer .= $buf;
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$len = 0;
|
||||
while (!$stream->eof() && $len < $maxLen) {
|
||||
$buf = $stream->read($maxLen - $len);
|
||||
if ($buf === false) {
|
||||
break;
|
||||
}
|
||||
$buffer .= $buf;
|
||||
$len = strlen($buffer);
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the contents of a stream into another stream until the given number
|
||||
* of bytes have been read.
|
||||
*
|
||||
* @param StreamInterface $source Stream to read from
|
||||
* @param StreamInterface $dest Stream to write to
|
||||
* @param int $maxLen Maximum number of bytes to read. Pass -1
|
||||
* to read the entire stream.
|
||||
*/
|
||||
public static function copyToStream(
|
||||
StreamInterface $source,
|
||||
StreamInterface $dest,
|
||||
$maxLen = -1
|
||||
) {
|
||||
if ($maxLen === -1) {
|
||||
while (!$source->eof()) {
|
||||
if (!$dest->write($source->read(1048576))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$bytes = 0;
|
||||
while (!$source->eof()) {
|
||||
$buf = $source->read($maxLen - $bytes);
|
||||
if (!($len = strlen($buf))) {
|
||||
break;
|
||||
}
|
||||
$bytes += $len;
|
||||
$dest->write($buf);
|
||||
if ($bytes == $maxLen) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a hash of a Stream
|
||||
*
|
||||
* @param StreamInterface $stream Stream to calculate the hash for
|
||||
* @param string $algo Hash algorithm (e.g. md5, crc32, etc)
|
||||
* @param bool $rawOutput Whether or not to use raw output
|
||||
*
|
||||
* @return string Returns the hash of the stream
|
||||
* @throws SeekException
|
||||
*/
|
||||
public static function hash(
|
||||
StreamInterface $stream,
|
||||
$algo,
|
||||
$rawOutput = false
|
||||
) {
|
||||
$pos = $stream->tell();
|
||||
|
||||
if ($pos > 0 && !$stream->seek(0)) {
|
||||
throw new SeekException($stream);
|
||||
}
|
||||
|
||||
$ctx = hash_init($algo);
|
||||
while (!$stream->eof()) {
|
||||
hash_update($ctx, $stream->read(1048576));
|
||||
}
|
||||
|
||||
$out = hash_final($ctx, (bool) $rawOutput);
|
||||
$stream->seek($pos);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a line from the stream up to the maximum allowed buffer length
|
||||
*
|
||||
* @param StreamInterface $stream Stream to read from
|
||||
* @param int $maxLength Maximum buffer length
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function readline(StreamInterface $stream, $maxLength = null)
|
||||
{
|
||||
$buffer = '';
|
||||
$size = 0;
|
||||
|
||||
while (!$stream->eof()) {
|
||||
if (false === ($byte = $stream->read(1))) {
|
||||
return $buffer;
|
||||
}
|
||||
$buffer .= $byte;
|
||||
// Break when a new line is found or the max length - 1 is reached
|
||||
if ($byte == PHP_EOL || ++$size == $maxLength - 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of GuzzleHttp\Stream\Stream::factory.
|
||||
*
|
||||
* @param mixed $resource Resource to create
|
||||
* @param array $options Associative array of stream options defined in
|
||||
* {@see \GuzzleHttp\Stream\Stream::__construct}
|
||||
*
|
||||
* @return StreamInterface
|
||||
*
|
||||
* @see GuzzleHttp\Stream\Stream::factory
|
||||
* @see GuzzleHttp\Stream\Stream::__construct
|
||||
*/
|
||||
public static function create($resource, array $options = [])
|
||||
{
|
||||
return Stream::factory($resource, $options);
|
||||
}
|
||||
}
|
178
core/vendor/guzzlehttp/streams/tests/AppendStreamTest.php
vendored
Normal file
178
core/vendor/guzzlehttp/streams/tests/AppendStreamTest.php
vendored
Normal file
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\AppendStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
class AppendStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Each stream must be readable
|
||||
*/
|
||||
public function testValidatesStreamsAreReadable()
|
||||
{
|
||||
$a = new AppendStream();
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isReadable'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(false));
|
||||
$a->addStream($s);
|
||||
}
|
||||
|
||||
public function testValidatesSeekType()
|
||||
{
|
||||
$a = new AppendStream();
|
||||
$this->assertFalse($a->seek(100, SEEK_CUR));
|
||||
}
|
||||
|
||||
public function testTriesToRewindOnSeek()
|
||||
{
|
||||
$a = new AppendStream();
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isReadable', 'seek', 'isSeekable'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(true));
|
||||
$s->expects($this->once())
|
||||
->method('isSeekable')
|
||||
->will($this->returnValue(true));
|
||||
$s->expects($this->once())
|
||||
->method('seek')
|
||||
->will($this->returnValue(false));
|
||||
$a->addStream($s);
|
||||
$this->assertFalse($a->seek(10));
|
||||
}
|
||||
|
||||
public function testSeeksToPositionByReading()
|
||||
{
|
||||
$a = new AppendStream([
|
||||
Stream::factory('foo'),
|
||||
Stream::factory('bar'),
|
||||
Stream::factory('baz'),
|
||||
]);
|
||||
|
||||
$this->assertTrue($a->seek(3));
|
||||
$this->assertEquals(3, $a->tell());
|
||||
$this->assertEquals('bar', $a->read(3));
|
||||
$a->seek(6);
|
||||
$this->assertEquals(6, $a->tell());
|
||||
$this->assertEquals('baz', $a->read(3));
|
||||
}
|
||||
|
||||
public function testDetachesEachStream()
|
||||
{
|
||||
$s1 = Stream::factory('foo');
|
||||
$s2 = Stream::factory('foo');
|
||||
$a = new AppendStream([$s1, $s2]);
|
||||
$this->assertSame('foofoo', (string) $a);
|
||||
$a->detach();
|
||||
$this->assertSame('', (string) $a);
|
||||
$this->assertSame(0, $a->getSize());
|
||||
}
|
||||
|
||||
public function testClosesEachStream()
|
||||
{
|
||||
$s1 = Stream::factory('foo');
|
||||
$a = new AppendStream([$s1]);
|
||||
$a->close();
|
||||
$this->assertSame('', (string) $a);
|
||||
}
|
||||
|
||||
public function testIsNotWritable()
|
||||
{
|
||||
$a = new AppendStream([Stream::factory('foo')]);
|
||||
$this->assertFalse($a->isWritable());
|
||||
$this->assertTrue($a->isSeekable());
|
||||
$this->assertTrue($a->isReadable());
|
||||
$this->assertFalse($a->write('foo'));
|
||||
}
|
||||
|
||||
public function testDoesNotNeedStreams()
|
||||
{
|
||||
$a = new AppendStream();
|
||||
$this->assertEquals('', (string) $a);
|
||||
}
|
||||
|
||||
public function testCanReadFromMultipleStreams()
|
||||
{
|
||||
$a = new AppendStream([
|
||||
Stream::factory('foo'),
|
||||
Stream::factory('bar'),
|
||||
Stream::factory('baz'),
|
||||
]);
|
||||
$this->assertFalse($a->eof());
|
||||
$this->assertSame(0, $a->tell());
|
||||
$this->assertEquals('foo', $a->read(3));
|
||||
$this->assertEquals('bar', $a->read(3));
|
||||
$this->assertEquals('baz', $a->read(3));
|
||||
$this->assertTrue($a->eof());
|
||||
$this->assertSame(9, $a->tell());
|
||||
$this->assertEquals('foobarbaz', (string) $a);
|
||||
}
|
||||
|
||||
public function testCanDetermineSizeFromMultipleStreams()
|
||||
{
|
||||
$a = new AppendStream([
|
||||
Stream::factory('foo'),
|
||||
Stream::factory('bar')
|
||||
]);
|
||||
$this->assertEquals(6, $a->getSize());
|
||||
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isSeekable', 'isReadable'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->once())
|
||||
->method('isSeekable')
|
||||
->will($this->returnValue(null));
|
||||
$s->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(true));
|
||||
$a->addStream($s);
|
||||
$this->assertNull($a->getSize());
|
||||
}
|
||||
|
||||
public function testCatchesExceptionsWhenCastingToString()
|
||||
{
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['read', 'isReadable', 'eof'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new \RuntimeException('foo')));
|
||||
$s->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(true));
|
||||
$s->expects($this->any())
|
||||
->method('eof')
|
||||
->will($this->returnValue(false));
|
||||
$a = new AppendStream([$s]);
|
||||
$this->assertFalse($a->eof());
|
||||
$this->assertSame('', (string) $a);
|
||||
}
|
||||
|
||||
public function testCanDetach()
|
||||
{
|
||||
$s = new AppendStream();
|
||||
$s->detach();
|
||||
}
|
||||
|
||||
public function testReturnsEmptyMetadata()
|
||||
{
|
||||
$s = new AppendStream();
|
||||
$this->assertEquals([], $s->getMetadata());
|
||||
$this->assertNull($s->getMetadata('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
|
||||
*/
|
||||
public function testCannotAttach()
|
||||
{
|
||||
$p = new AppendStream();
|
||||
$p->attach('a');
|
||||
}
|
||||
}
|
186
core/vendor/guzzlehttp/streams/tests/AsyncReadStreamTest.php
vendored
Normal file
186
core/vendor/guzzlehttp/streams/tests/AsyncReadStreamTest.php
vendored
Normal file
|
@ -0,0 +1,186 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\AsyncReadStream;
|
||||
use GuzzleHttp\Stream\BufferStream;
|
||||
use GuzzleHttp\Stream\FnStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
class AsyncReadStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Buffer must be readable and writable
|
||||
*/
|
||||
public function testValidatesReadableBuffer()
|
||||
{
|
||||
new AsyncReadStream(FnStream::decorate(
|
||||
Stream::factory(),
|
||||
['isReadable' => function () { return false; }]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Buffer must be readable and writable
|
||||
*/
|
||||
public function testValidatesWritableBuffer()
|
||||
{
|
||||
new AsyncReadStream(FnStream::decorate(
|
||||
Stream::factory(),
|
||||
['isWritable' => function () { return false; }]
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidatesHwmMetadata()
|
||||
{
|
||||
$a = new AsyncReadStream(Stream::factory(), [
|
||||
'drain' => function() {}
|
||||
]);
|
||||
$this->assertNull($this->readAttribute($a, 'drain'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage pump must be callable
|
||||
*/
|
||||
public function testValidatesPumpIsCallable()
|
||||
{
|
||||
new AsyncReadStream(new BufferStream(), ['pump' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage drain must be callable
|
||||
*/
|
||||
public function testValidatesDrainIsCallable()
|
||||
{
|
||||
new AsyncReadStream(new BufferStream(), ['drain' => true]);
|
||||
}
|
||||
|
||||
public function testCanInitialize()
|
||||
{
|
||||
$buffer = new BufferStream();
|
||||
$a = new AsyncReadStream($buffer, [
|
||||
'size' => 10,
|
||||
'drain' => function () {},
|
||||
'pump' => function () {},
|
||||
]);
|
||||
$this->assertSame($buffer, $this->readAttribute($a, 'stream'));
|
||||
$this->assertTrue(is_callable($this->readAttribute($a, 'drain')));
|
||||
$this->assertTrue(is_callable($this->readAttribute($a, 'pump')));
|
||||
$this->assertTrue($a->isReadable());
|
||||
$this->assertFalse($a->isSeekable());
|
||||
$this->assertFalse($a->isWritable());
|
||||
$this->assertFalse($a->write('foo'));
|
||||
$this->assertEquals(10, $a->getSize());
|
||||
}
|
||||
|
||||
public function testReadsFromBufferWithNoDrainOrPump()
|
||||
{
|
||||
$buffer = new BufferStream();
|
||||
$a = new AsyncReadStream($buffer);
|
||||
$buffer->write('foo');
|
||||
$this->assertNull($a->getSize());
|
||||
$this->assertEquals('foo', $a->read(10));
|
||||
$this->assertEquals('', $a->read(10));
|
||||
}
|
||||
|
||||
public function testCallsPumpForMoreDataWhenRequested()
|
||||
{
|
||||
$called = 0;
|
||||
$buffer = new BufferStream();
|
||||
$a = new AsyncReadStream($buffer, [
|
||||
'pump' => function ($size) use (&$called) {
|
||||
$called++;
|
||||
return str_repeat('.', $size);
|
||||
}
|
||||
]);
|
||||
$buffer->write('foobar');
|
||||
$this->assertEquals('foo', $a->read(3));
|
||||
$this->assertEquals(0, $called);
|
||||
$this->assertEquals('bar.....', $a->read(8));
|
||||
$this->assertEquals(1, $called);
|
||||
$this->assertEquals('..', $a->read(2));
|
||||
$this->assertEquals(2, $called);
|
||||
}
|
||||
|
||||
public function testCallsDrainWhenNeeded()
|
||||
{
|
||||
$called = 0;
|
||||
$buffer = new BufferStream(5);
|
||||
$a = new AsyncReadStream($buffer, [
|
||||
'drain' => function (BufferStream $b) use (&$called, $buffer) {
|
||||
$this->assertSame($b, $buffer);
|
||||
$called++;
|
||||
}
|
||||
]);
|
||||
|
||||
$buffer->write('foobar');
|
||||
$this->assertEquals(6, $buffer->getSize());
|
||||
$this->assertEquals(0, $called);
|
||||
|
||||
$a->read(3);
|
||||
$this->assertTrue($this->readAttribute($a, 'needsDrain'));
|
||||
$this->assertEquals(3, $buffer->getSize());
|
||||
$this->assertEquals(0, $called);
|
||||
|
||||
$a->read(3);
|
||||
$this->assertEquals(0, $buffer->getSize());
|
||||
$this->assertFalse($this->readAttribute($a, 'needsDrain'));
|
||||
$this->assertEquals(1, $called);
|
||||
}
|
||||
|
||||
public function testCreatesBufferWithNoConfig()
|
||||
{
|
||||
list($buffer, $async) = AsyncReadStream::create();
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\BufferStream', $buffer);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\AsyncReadStream', $async);
|
||||
}
|
||||
|
||||
public function testCreatesBufferWithSpecifiedBuffer()
|
||||
{
|
||||
$buf = new BufferStream();
|
||||
list($buffer, $async) = AsyncReadStream::create(['buffer' => $buf]);
|
||||
$this->assertSame($buf, $buffer);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\AsyncReadStream', $async);
|
||||
}
|
||||
|
||||
public function testCreatesNullStream()
|
||||
{
|
||||
list($buffer, $async) = AsyncReadStream::create(['max_buffer' => 0]);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\NullStream', $buffer);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\AsyncReadStream', $async);
|
||||
}
|
||||
|
||||
public function testCreatesDroppingStream()
|
||||
{
|
||||
list($buffer, $async) = AsyncReadStream::create(['max_buffer' => 5]);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\DroppingStream', $buffer);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\AsyncReadStream', $async);
|
||||
$buffer->write('12345678910');
|
||||
$this->assertEquals(5, $buffer->getSize());
|
||||
}
|
||||
|
||||
public function testCreatesOnWriteStream()
|
||||
{
|
||||
$c = 0;
|
||||
$b = new BufferStream();
|
||||
list($buffer, $async) = AsyncReadStream::create([
|
||||
'buffer' => $b,
|
||||
'write' => function (BufferStream $buf, $data) use (&$c, $b) {
|
||||
$this->assertSame($buf, $b);
|
||||
$this->assertEquals('foo', $data);
|
||||
$c++;
|
||||
}
|
||||
]);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\FnStream', $buffer);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\AsyncReadStream', $async);
|
||||
$this->assertEquals(0, $c);
|
||||
$this->assertEquals(3, $buffer->write('foo'));
|
||||
$this->assertEquals(1, $c);
|
||||
$this->assertEquals(3, $buffer->write('foo'));
|
||||
$this->assertEquals(2, $c);
|
||||
$this->assertEquals('foofoo', (string) $buffer);
|
||||
}
|
||||
}
|
69
core/vendor/guzzlehttp/streams/tests/BufferStreamTest.php
vendored
Normal file
69
core/vendor/guzzlehttp/streams/tests/BufferStreamTest.php
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\BufferStream;
|
||||
|
||||
class BufferStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testHasMetadata()
|
||||
{
|
||||
$b = new BufferStream(10);
|
||||
$this->assertTrue($b->isReadable());
|
||||
$this->assertTrue($b->isWritable());
|
||||
$this->assertFalse($b->isSeekable());
|
||||
$this->assertEquals(null, $b->getMetadata('foo'));
|
||||
$this->assertEquals(10, $b->getMetadata('hwm'));
|
||||
$this->assertEquals([], $b->getMetadata());
|
||||
}
|
||||
|
||||
public function testRemovesReadDataFromBuffer()
|
||||
{
|
||||
$b = new BufferStream();
|
||||
$this->assertEquals(3, $b->write('foo'));
|
||||
$this->assertEquals(3, $b->getSize());
|
||||
$this->assertFalse($b->eof());
|
||||
$this->assertEquals('foo', $b->read(10));
|
||||
$this->assertTrue($b->eof());
|
||||
$this->assertEquals('', $b->read(10));
|
||||
}
|
||||
|
||||
public function testCanCastToStringOrGetContents()
|
||||
{
|
||||
$b = new BufferStream();
|
||||
$b->write('foo');
|
||||
$b->write('baz');
|
||||
$this->assertEquals('foo', $b->read(3));
|
||||
$b->write('bar');
|
||||
$this->assertEquals('bazbar', (string) $b);
|
||||
$this->assertFalse($b->tell());
|
||||
}
|
||||
|
||||
public function testDetachClearsBuffer()
|
||||
{
|
||||
$b = new BufferStream();
|
||||
$b->write('foo');
|
||||
$b->detach();
|
||||
$this->assertEquals(0, $b->tell());
|
||||
$this->assertTrue($b->eof());
|
||||
$this->assertEquals(3, $b->write('abc'));
|
||||
$this->assertEquals('abc', $b->read(10));
|
||||
}
|
||||
|
||||
public function testExceedingHighwaterMarkReturnsFalseButStillBuffers()
|
||||
{
|
||||
$b = new BufferStream(5);
|
||||
$this->assertEquals(3, $b->write('hi '));
|
||||
$this->assertFalse($b->write('hello'));
|
||||
$this->assertEquals('hi hello', (string) $b);
|
||||
$this->assertEquals(4, $b->write('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
|
||||
*/
|
||||
public function testCannotAttach()
|
||||
{
|
||||
$p = new BufferStream();
|
||||
$p->attach('a');
|
||||
}
|
||||
}
|
136
core/vendor/guzzlehttp/streams/tests/CachingStreamTest.php
vendored
Normal file
136
core/vendor/guzzlehttp/streams/tests/CachingStreamTest.php
vendored
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\CachingStream;
|
||||
use GuzzleHttp\Stream\Utils;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\CachingStream
|
||||
*/
|
||||
class CachingStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var CachingStream */
|
||||
protected $body;
|
||||
|
||||
/** @var Stream */
|
||||
protected $decorated;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->decorated = Stream::factory('testing');
|
||||
$this->body = new CachingStream($this->decorated);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->decorated->close();
|
||||
$this->body->close();
|
||||
}
|
||||
|
||||
public function testUsesRemoteSizeIfPossible()
|
||||
{
|
||||
$body = Stream::factory('test');
|
||||
$caching = new CachingStream($body);
|
||||
$this->assertEquals(4, $caching->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Cannot seek to byte 10
|
||||
*/
|
||||
public function testCannotSeekPastWhatHasBeenRead()
|
||||
{
|
||||
$this->body->seek(10);
|
||||
}
|
||||
|
||||
public function testCannotUseSeekEnd()
|
||||
{
|
||||
$this->assertFalse($this->body->seek(2, SEEK_END));
|
||||
}
|
||||
|
||||
public function testRewindUsesSeek()
|
||||
{
|
||||
$a = Stream::factory('foo');
|
||||
$d = $this->getMockBuilder('GuzzleHttp\Stream\CachingStream')
|
||||
->setMethods(array('seek'))
|
||||
->setConstructorArgs(array($a))
|
||||
->getMock();
|
||||
$d->expects($this->once())
|
||||
->method('seek')
|
||||
->with(0)
|
||||
->will($this->returnValue(true));
|
||||
$d->seek(0);
|
||||
}
|
||||
|
||||
public function testCanSeekToReadBytes()
|
||||
{
|
||||
$this->assertEquals('te', $this->body->read(2));
|
||||
$this->body->seek(0);
|
||||
$this->assertEquals('test', $this->body->read(4));
|
||||
$this->assertEquals(4, $this->body->tell());
|
||||
$this->body->seek(2);
|
||||
$this->assertEquals(2, $this->body->tell());
|
||||
$this->body->seek(2, SEEK_CUR);
|
||||
$this->assertEquals(4, $this->body->tell());
|
||||
$this->assertEquals('ing', $this->body->read(3));
|
||||
}
|
||||
|
||||
public function testWritesToBufferStream()
|
||||
{
|
||||
$this->body->read(2);
|
||||
$this->body->write('hi');
|
||||
$this->body->seek(0);
|
||||
$this->assertEquals('tehiing', (string) $this->body);
|
||||
}
|
||||
|
||||
public function testSkipsOverwrittenBytes()
|
||||
{
|
||||
$decorated = Stream::factory(
|
||||
implode("\n", array_map(function ($n) {
|
||||
return str_pad($n, 4, '0', STR_PAD_LEFT);
|
||||
}, range(0, 25)))
|
||||
);
|
||||
|
||||
$body = new CachingStream($decorated);
|
||||
|
||||
$this->assertEquals("0000\n", Utils::readline($body));
|
||||
$this->assertEquals("0001\n", Utils::readline($body));
|
||||
// Write over part of the body yet to be read, so skip some bytes
|
||||
$this->assertEquals(5, $body->write("TEST\n"));
|
||||
$this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes'));
|
||||
// Read, which skips bytes, then reads
|
||||
$this->assertEquals("0003\n", Utils::readline($body));
|
||||
$this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes'));
|
||||
$this->assertEquals("0004\n", Utils::readline($body));
|
||||
$this->assertEquals("0005\n", Utils::readline($body));
|
||||
|
||||
// Overwrite part of the cached body (so don't skip any bytes)
|
||||
$body->seek(5);
|
||||
$this->assertEquals(5, $body->write("ABCD\n"));
|
||||
$this->assertEquals(0, $this->readAttribute($body, 'skipReadBytes'));
|
||||
$this->assertEquals("TEST\n", Utils::readline($body));
|
||||
$this->assertEquals("0003\n", Utils::readline($body));
|
||||
$this->assertEquals("0004\n", Utils::readline($body));
|
||||
$this->assertEquals("0005\n", Utils::readline($body));
|
||||
$this->assertEquals("0006\n", Utils::readline($body));
|
||||
$this->assertEquals(5, $body->write("1234\n"));
|
||||
$this->assertEquals(5, $this->readAttribute($body, 'skipReadBytes'));
|
||||
|
||||
// Seek to 0 and ensure the overwritten bit is replaced
|
||||
$body->seek(0);
|
||||
$this->assertEquals("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", $body->read(50));
|
||||
|
||||
// Ensure that casting it to a string does not include the bit that was overwritten
|
||||
$this->assertContains("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (string) $body);
|
||||
}
|
||||
|
||||
public function testClosesBothStreams()
|
||||
{
|
||||
$s = fopen('php://temp', 'r');
|
||||
$a = Stream::factory($s);
|
||||
$d = new CachingStream($a);
|
||||
$d->close();
|
||||
$this->assertFalse(is_resource($s));
|
||||
}
|
||||
}
|
26
core/vendor/guzzlehttp/streams/tests/DroppingStreamTest.php
vendored
Normal file
26
core/vendor/guzzlehttp/streams/tests/DroppingStreamTest.php
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\BufferStream;
|
||||
use GuzzleHttp\Stream\DroppingStream;
|
||||
|
||||
class DroppingStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testBeginsDroppingWhenSizeExceeded()
|
||||
{
|
||||
$stream = new BufferStream();
|
||||
$drop = new DroppingStream($stream, 5);
|
||||
$this->assertEquals(3, $drop->write('hel'));
|
||||
$this->assertFalse($drop->write('lo'));
|
||||
$this->assertEquals(5, $drop->getSize());
|
||||
$this->assertEquals('hello', $drop->read(5));
|
||||
$this->assertEquals(0, $drop->getSize());
|
||||
$drop->write('12345678910');
|
||||
$this->assertEquals(5, $stream->getSize());
|
||||
$this->assertEquals(5, $drop->getSize());
|
||||
$this->assertEquals('12345', (string) $drop);
|
||||
$this->assertEquals(0, $drop->getSize());
|
||||
$drop->write('hello');
|
||||
$this->assertFalse($drop->write('test'));
|
||||
}
|
||||
}
|
16
core/vendor/guzzlehttp/streams/tests/Exception/SeekExceptionTest.php
vendored
Normal file
16
core/vendor/guzzlehttp/streams/tests/Exception/SeekExceptionTest.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream\Exception;
|
||||
|
||||
use GuzzleHttp\Stream\Exception\SeekException;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
class SeekExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testHasStream()
|
||||
{
|
||||
$s = Stream::factory('foo');
|
||||
$e = new SeekException($s, 10);
|
||||
$this->assertSame($s, $e->getStream());
|
||||
$this->assertContains('10', $e->getMessage());
|
||||
}
|
||||
}
|
89
core/vendor/guzzlehttp/streams/tests/FnStreamTest.php
vendored
Normal file
89
core/vendor/guzzlehttp/streams/tests/FnStreamTest.php
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\FnStream;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\FnStream
|
||||
*/
|
||||
class FnStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \BadMethodCallException
|
||||
* @expectedExceptionMessage seek() is not implemented in the FnStream
|
||||
*/
|
||||
public function testThrowsWhenNotImplemented()
|
||||
{
|
||||
(new FnStream([]))->seek(1);
|
||||
}
|
||||
|
||||
public function testProxiesToFunction()
|
||||
{
|
||||
$s = new FnStream([
|
||||
'read' => function ($len) {
|
||||
$this->assertEquals(3, $len);
|
||||
return 'foo';
|
||||
}
|
||||
]);
|
||||
|
||||
$this->assertEquals('foo', $s->read(3));
|
||||
}
|
||||
|
||||
public function testCanCloseOnDestruct()
|
||||
{
|
||||
$called = false;
|
||||
$s = new FnStream([
|
||||
'close' => function () use (&$called) {
|
||||
$called = true;
|
||||
}
|
||||
]);
|
||||
unset($s);
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
|
||||
public function testDoesNotRequireClose()
|
||||
{
|
||||
$s = new FnStream([]);
|
||||
unset($s);
|
||||
}
|
||||
|
||||
public function testDecoratesStream()
|
||||
{
|
||||
$a = Stream::factory('foo');
|
||||
$b = FnStream::decorate($a, []);
|
||||
$this->assertEquals(3, $b->getSize());
|
||||
$this->assertEquals($b->isWritable(), true);
|
||||
$this->assertEquals($b->isReadable(), true);
|
||||
$this->assertEquals($b->isSeekable(), true);
|
||||
$this->assertEquals($b->read(3), 'foo');
|
||||
$this->assertEquals($b->tell(), 3);
|
||||
$this->assertEquals($a->tell(), 3);
|
||||
$this->assertEquals($b->eof(), true);
|
||||
$this->assertEquals($a->eof(), true);
|
||||
$b->seek(0);
|
||||
$this->assertEquals('foo', (string) $b);
|
||||
$b->seek(0);
|
||||
$this->assertEquals('foo', $b->getContents());
|
||||
$this->assertEquals($a->getMetadata(), $b->getMetadata());
|
||||
$b->seek(0, SEEK_END);
|
||||
$b->write('bar');
|
||||
$this->assertEquals('foobar', (string) $b);
|
||||
$this->assertInternalType('resource', $b->detach());
|
||||
$b->close();
|
||||
}
|
||||
|
||||
public function testDecoratesWithCustomizations()
|
||||
{
|
||||
$called = false;
|
||||
$a = Stream::factory('foo');
|
||||
$b = FnStream::decorate($a, [
|
||||
'read' => function ($len) use (&$called, $a) {
|
||||
$called = true;
|
||||
return $a->read($len);
|
||||
}
|
||||
]);
|
||||
$this->assertEquals('foo', $b->read(3));
|
||||
$this->assertTrue($called);
|
||||
}
|
||||
}
|
99
core/vendor/guzzlehttp/streams/tests/GuzzleStreamWrapperTest.php
vendored
Normal file
99
core/vendor/guzzlehttp/streams/tests/GuzzleStreamWrapperTest.php
vendored
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\GuzzleStreamWrapper;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\GuzzleStreamWrapper
|
||||
*/
|
||||
class GuzzleStreamWrapperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testResource()
|
||||
{
|
||||
$stream = Stream::factory('foo');
|
||||
$handle = GuzzleStreamWrapper::getResource($stream);
|
||||
$this->assertSame('foo', fread($handle, 3));
|
||||
$this->assertSame(3, ftell($handle));
|
||||
$this->assertSame(3, fwrite($handle, 'bar'));
|
||||
$this->assertSame(0, fseek($handle, 0));
|
||||
$this->assertSame('foobar', fread($handle, 6));
|
||||
$this->assertTrue(feof($handle));
|
||||
|
||||
// This fails on HHVM for some reason
|
||||
if (!defined('HHVM_VERSION')) {
|
||||
$this->assertEquals([
|
||||
'dev' => 0,
|
||||
'ino' => 0,
|
||||
'mode' => 33206,
|
||||
'nlink' => 0,
|
||||
'uid' => 0,
|
||||
'gid' => 0,
|
||||
'rdev' => 0,
|
||||
'size' => 6,
|
||||
'atime' => 0,
|
||||
'mtime' => 0,
|
||||
'ctime' => 0,
|
||||
'blksize' => 0,
|
||||
'blocks' => 0,
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
2 => 33206,
|
||||
3 => 0,
|
||||
4 => 0,
|
||||
5 => 0,
|
||||
6 => 0,
|
||||
7 => 6,
|
||||
8 => 0,
|
||||
9 => 0,
|
||||
10 => 0,
|
||||
11 => 0,
|
||||
12 => 0,
|
||||
], fstat($handle));
|
||||
}
|
||||
|
||||
$this->assertTrue(fclose($handle));
|
||||
$this->assertSame('foobar', (string) $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testValidatesStream()
|
||||
{
|
||||
$stream = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isReadable', 'isWritable'])
|
||||
->getMockForAbstractClass();
|
||||
$stream->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(false));
|
||||
$stream->expects($this->once())
|
||||
->method('isWritable')
|
||||
->will($this->returnValue(false));
|
||||
GuzzleStreamWrapper::getResource($stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testReturnsFalseWhenStreamDoesNotExist()
|
||||
{
|
||||
fopen('guzzle://foo', 'r');
|
||||
}
|
||||
|
||||
public function testCanOpenReadonlyStream()
|
||||
{
|
||||
$stream = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isReadable', 'isWritable'])
|
||||
->getMockForAbstractClass();
|
||||
$stream->expects($this->once())
|
||||
->method('isReadable')
|
||||
->will($this->returnValue(false));
|
||||
$stream->expects($this->once())
|
||||
->method('isWritable')
|
||||
->will($this->returnValue(true));
|
||||
$r = GuzzleStreamWrapper::getResource($stream);
|
||||
$this->assertInternalType('resource', $r);
|
||||
fclose($r);
|
||||
}
|
||||
}
|
16
core/vendor/guzzlehttp/streams/tests/InflateStreamTest.php
vendored
Normal file
16
core/vendor/guzzlehttp/streams/tests/InflateStreamTest.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\InflateStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
class InflateStreamtest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testInflatesStreams()
|
||||
{
|
||||
$content = gzencode('test');
|
||||
$a = Stream::factory($content);
|
||||
$b = new InflateStream($a);
|
||||
$this->assertEquals('test', (string) $b);
|
||||
}
|
||||
}
|
64
core/vendor/guzzlehttp/streams/tests/LazyOpenStreamTest.php
vendored
Normal file
64
core/vendor/guzzlehttp/streams/tests/LazyOpenStreamTest.php
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\LazyOpenStream;
|
||||
|
||||
class LazyOpenStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $fname;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->fname = tempnam('/tmp', 'tfile');
|
||||
|
||||
if (file_exists($this->fname)) {
|
||||
unlink($this->fname);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
if (file_exists($this->fname)) {
|
||||
unlink($this->fname);
|
||||
}
|
||||
}
|
||||
|
||||
public function testOpensLazily()
|
||||
{
|
||||
$l = new LazyOpenStream($this->fname, 'w+');
|
||||
$l->write('foo');
|
||||
$this->assertInternalType('array', $l->getMetadata());
|
||||
$this->assertFileExists($this->fname);
|
||||
$this->assertEquals('foo', file_get_contents($this->fname));
|
||||
$this->assertEquals('foo', (string) $l);
|
||||
}
|
||||
|
||||
public function testProxiesToFile()
|
||||
{
|
||||
file_put_contents($this->fname, 'foo');
|
||||
$l = new LazyOpenStream($this->fname, 'r');
|
||||
$this->assertEquals('foo', $l->read(4));
|
||||
$this->assertTrue($l->eof());
|
||||
$this->assertEquals(3, $l->tell());
|
||||
$this->assertTrue($l->isReadable());
|
||||
$this->assertTrue($l->isSeekable());
|
||||
$this->assertFalse($l->isWritable());
|
||||
$l->seek(1);
|
||||
$this->assertEquals('oo', $l->getContents());
|
||||
$this->assertEquals('foo', (string) $l);
|
||||
$this->assertEquals(3, $l->getSize());
|
||||
$this->assertInternalType('array', $l->getMetadata());
|
||||
$l->close();
|
||||
}
|
||||
|
||||
public function testDetachesUnderlyingStream()
|
||||
{
|
||||
file_put_contents($this->fname, 'foo');
|
||||
$l = new LazyOpenStream($this->fname, 'r');
|
||||
$r = $l->detach();
|
||||
$this->assertInternalType('resource', $r);
|
||||
fseek($r, 0);
|
||||
$this->assertEquals('foo', stream_get_contents($r));
|
||||
fclose($r);
|
||||
}
|
||||
}
|
133
core/vendor/guzzlehttp/streams/tests/LimitStreamTest.php
vendored
Normal file
133
core/vendor/guzzlehttp/streams/tests/LimitStreamTest.php
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Http;
|
||||
|
||||
use GuzzleHttp\Stream\FnStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\LimitStream;
|
||||
use GuzzleHttp\Stream\NoSeekStream;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\LimitStream
|
||||
*/
|
||||
class LimitStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var LimitStream */
|
||||
protected $body;
|
||||
|
||||
/** @var Stream */
|
||||
protected $decorated;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->decorated = Stream::factory(fopen(__FILE__, 'r'));
|
||||
$this->body = new LimitStream($this->decorated, 10, 3);
|
||||
}
|
||||
|
||||
public function testReturnsSubset()
|
||||
{
|
||||
$body = new LimitStream(Stream::factory('foo'), -1, 1);
|
||||
$this->assertEquals('oo', (string) $body);
|
||||
$this->assertTrue($body->eof());
|
||||
$body->seek(0);
|
||||
$this->assertFalse($body->eof());
|
||||
$this->assertEquals('oo', $body->read(100));
|
||||
$this->assertTrue($body->eof());
|
||||
}
|
||||
|
||||
public function testReturnsSubsetWhenCastToString()
|
||||
{
|
||||
$body = Stream::factory('foo_baz_bar');
|
||||
$limited = new LimitStream($body, 3, 4);
|
||||
$this->assertEquals('baz', (string) $limited);
|
||||
}
|
||||
|
||||
public function testReturnsSubsetOfEmptyBodyWhenCastToString()
|
||||
{
|
||||
$body = Stream::factory('');
|
||||
$limited = new LimitStream($body, 0, 10);
|
||||
$this->assertEquals('', (string) $limited);
|
||||
}
|
||||
|
||||
public function testSeeksWhenConstructed()
|
||||
{
|
||||
$this->assertEquals(0, $this->body->tell());
|
||||
$this->assertEquals(3, $this->decorated->tell());
|
||||
}
|
||||
|
||||
public function testAllowsBoundedSeek()
|
||||
{
|
||||
$this->assertEquals(true, $this->body->seek(100));
|
||||
$this->assertEquals(10, $this->body->tell());
|
||||
$this->assertEquals(13, $this->decorated->tell());
|
||||
$this->assertEquals(true, $this->body->seek(0));
|
||||
$this->assertEquals(0, $this->body->tell());
|
||||
$this->assertEquals(3, $this->decorated->tell());
|
||||
$this->assertEquals(false, $this->body->seek(-10));
|
||||
$this->assertEquals(0, $this->body->tell());
|
||||
$this->assertEquals(3, $this->decorated->tell());
|
||||
$this->assertEquals(true, $this->body->seek(5));
|
||||
$this->assertEquals(5, $this->body->tell());
|
||||
$this->assertEquals(8, $this->decorated->tell());
|
||||
$this->assertEquals(false, $this->body->seek(1000, SEEK_END));
|
||||
}
|
||||
|
||||
public function testReadsOnlySubsetOfData()
|
||||
{
|
||||
$data = $this->body->read(100);
|
||||
$this->assertEquals(10, strlen($data));
|
||||
$this->assertFalse($this->body->read(1000));
|
||||
|
||||
$this->body->setOffset(10);
|
||||
$newData = $this->body->read(100);
|
||||
$this->assertEquals(10, strlen($newData));
|
||||
$this->assertNotSame($data, $newData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\SeekException
|
||||
* @expectedExceptionMessage Could not seek the stream to position 2
|
||||
*/
|
||||
public function testThrowsWhenCurrentGreaterThanOffsetSeek()
|
||||
{
|
||||
$a = Stream::factory('foo_bar');
|
||||
$b = new NoSeekStream($a);
|
||||
$c = new LimitStream($b);
|
||||
$a->getContents();
|
||||
$c->setOffset(2);
|
||||
}
|
||||
|
||||
public function testClaimsConsumedWhenReadLimitIsReached()
|
||||
{
|
||||
$this->assertFalse($this->body->eof());
|
||||
$this->body->read(1000);
|
||||
$this->assertTrue($this->body->eof());
|
||||
}
|
||||
|
||||
public function testContentLengthIsBounded()
|
||||
{
|
||||
$this->assertEquals(10, $this->body->getSize());
|
||||
}
|
||||
|
||||
public function testGetContentsIsBasedOnSubset()
|
||||
{
|
||||
$body = new LimitStream(Stream::factory('foobazbar'), 3, 3);
|
||||
$this->assertEquals('baz', $body->getContents());
|
||||
}
|
||||
|
||||
public function testReturnsNullIfSizeCannotBeDetermined()
|
||||
{
|
||||
$a = new FnStream([
|
||||
'getSize' => function () { return null; },
|
||||
'tell' => function () { return 0; },
|
||||
]);
|
||||
$b = new LimitStream($a);
|
||||
$this->assertNull($b->getSize());
|
||||
}
|
||||
|
||||
public function testLengthLessOffsetWhenNoLimitSize()
|
||||
{
|
||||
$a = Stream::factory('foo_bar');
|
||||
$b = new LimitStream($a, -1, 4);
|
||||
$this->assertEquals(3, $b->getSize());
|
||||
}
|
||||
}
|
41
core/vendor/guzzlehttp/streams/tests/NoSeekStreamTest.php
vendored
Normal file
41
core/vendor/guzzlehttp/streams/tests/NoSeekStreamTest.php
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\NoSeekStream;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\NoSeekStream
|
||||
* @covers GuzzleHttp\Stream\StreamDecoratorTrait
|
||||
*/
|
||||
class NoSeekStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCannotSeek()
|
||||
{
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['isSeekable', 'seek'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->never())->method('seek');
|
||||
$s->expects($this->never())->method('isSeekable');
|
||||
$wrapped = new NoSeekStream($s);
|
||||
$this->assertFalse($wrapped->isSeekable());
|
||||
$this->assertFalse($wrapped->seek(2));
|
||||
}
|
||||
|
||||
public function testHandlesClose()
|
||||
{
|
||||
$s = Stream::factory('foo');
|
||||
$wrapped = new NoSeekStream($s);
|
||||
$wrapped->close();
|
||||
$this->assertFalse($wrapped->write('foo'));
|
||||
}
|
||||
|
||||
public function testCanAttach()
|
||||
{
|
||||
$s1 = Stream::factory('foo');
|
||||
$s2 = Stream::factory('bar');
|
||||
$wrapped = new NoSeekStream($s1);
|
||||
$wrapped->attach($s2->detach());
|
||||
$this->assertEquals('bar', (string) $wrapped);
|
||||
}
|
||||
}
|
39
core/vendor/guzzlehttp/streams/tests/NullStreamTest.php
vendored
Normal file
39
core/vendor/guzzlehttp/streams/tests/NullStreamTest.php
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\NullStream;
|
||||
|
||||
class NullStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testDoesNothing()
|
||||
{
|
||||
$b = new NullStream();
|
||||
$this->assertEquals('', $b->read(10));
|
||||
$this->assertEquals(4, $b->write('test'));
|
||||
$this->assertEquals('', (string) $b);
|
||||
$this->assertNull($b->getMetadata('a'));
|
||||
$this->assertEquals([], $b->getMetadata());
|
||||
$this->assertEquals(0, $b->getSize());
|
||||
$this->assertEquals('', $b->getContents());
|
||||
$this->assertEquals(0, $b->tell());
|
||||
|
||||
$this->assertTrue($b->isReadable());
|
||||
$this->assertTrue($b->isWritable());
|
||||
$this->assertTrue($b->isSeekable());
|
||||
$this->assertFalse($b->seek(10));
|
||||
|
||||
$this->assertTrue($b->eof());
|
||||
$b->detach();
|
||||
$this->assertTrue($b->eof());
|
||||
$b->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
|
||||
*/
|
||||
public function testCannotAttach()
|
||||
{
|
||||
$p = new NullStream();
|
||||
$p->attach('a');
|
||||
}
|
||||
}
|
77
core/vendor/guzzlehttp/streams/tests/PumpStreamTest.php
vendored
Normal file
77
core/vendor/guzzlehttp/streams/tests/PumpStreamTest.php
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\LimitStream;
|
||||
use GuzzleHttp\Stream\PumpStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
class PumpStreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testHasMetadataAndSize()
|
||||
{
|
||||
$p = new PumpStream(function () {}, [
|
||||
'metadata' => ['foo' => 'bar'],
|
||||
'size' => 100
|
||||
]);
|
||||
|
||||
$this->assertEquals('bar', $p->getMetadata('foo'));
|
||||
$this->assertEquals(['foo' => 'bar'], $p->getMetadata());
|
||||
$this->assertEquals(100, $p->getSize());
|
||||
}
|
||||
|
||||
public function testCanReadFromCallable()
|
||||
{
|
||||
$p = Stream::factory(function ($size) {
|
||||
return 'a';
|
||||
});
|
||||
$this->assertEquals('a', $p->read(1));
|
||||
$this->assertEquals(1, $p->tell());
|
||||
$this->assertEquals('aaaaa', $p->read(5));
|
||||
$this->assertEquals(6, $p->tell());
|
||||
}
|
||||
|
||||
public function testStoresExcessDataInBuffer()
|
||||
{
|
||||
$called = [];
|
||||
$p = Stream::factory(function ($size) use (&$called) {
|
||||
$called[] = $size;
|
||||
return 'abcdef';
|
||||
});
|
||||
$this->assertEquals('a', $p->read(1));
|
||||
$this->assertEquals('b', $p->read(1));
|
||||
$this->assertEquals('cdef', $p->read(4));
|
||||
$this->assertEquals('abcdefabc', $p->read(9));
|
||||
$this->assertEquals([1, 9, 3], $called);
|
||||
}
|
||||
|
||||
public function testInifiniteStreamWrappedInLimitStream()
|
||||
{
|
||||
$p = Stream::factory(function () { return 'a'; });
|
||||
$s = new LimitStream($p, 5);
|
||||
$this->assertEquals('aaaaa', (string) $s);
|
||||
}
|
||||
|
||||
public function testDescribesCapabilities()
|
||||
{
|
||||
$p = Stream::factory(function () {});
|
||||
$this->assertTrue($p->isReadable());
|
||||
$this->assertFalse($p->isSeekable());
|
||||
$this->assertFalse($p->isWritable());
|
||||
$this->assertNull($p->getSize());
|
||||
$this->assertFalse($p->write('aa'));
|
||||
$this->assertEquals('', $p->getContents());
|
||||
$this->assertEquals('', (string) $p);
|
||||
$p->close();
|
||||
$this->assertEquals('', $p->read(10));
|
||||
$this->assertTrue($p->eof());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
|
||||
*/
|
||||
public function testCannotAttach()
|
||||
{
|
||||
$p = Stream::factory(function () {});
|
||||
$p->attach('a');
|
||||
}
|
||||
}
|
147
core/vendor/guzzlehttp/streams/tests/StreamDecoratorTraitTest.php
vendored
Normal file
147
core/vendor/guzzlehttp/streams/tests/StreamDecoratorTraitTest.php
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\StreamInterface;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\StreamDecoratorTrait;
|
||||
|
||||
class Str implements StreamInterface
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\StreamDecoratorTrait
|
||||
*/
|
||||
class StreamDecoratorTraitTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $a;
|
||||
private $b;
|
||||
private $c;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->c = fopen('php://temp', 'r+');
|
||||
fwrite($this->c, 'foo');
|
||||
fseek($this->c, 0);
|
||||
$this->a = Stream::factory($this->c);
|
||||
$this->b = new Str($this->a);
|
||||
}
|
||||
|
||||
public function testCatchesExceptionsWhenCastingToString()
|
||||
{
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface')
|
||||
->setMethods(['read'])
|
||||
->getMockForAbstractClass();
|
||||
$s->expects($this->once())
|
||||
->method('read')
|
||||
->will($this->throwException(new \Exception('foo')));
|
||||
$msg = '';
|
||||
set_error_handler(function ($errNo, $str) use (&$msg) { $msg = $str; });
|
||||
echo new Str($s);
|
||||
restore_error_handler();
|
||||
$this->assertContains('foo', $msg);
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertEquals('foo', (string) $this->b);
|
||||
}
|
||||
|
||||
public function testHasSize()
|
||||
{
|
||||
$this->assertEquals(3, $this->b->getSize());
|
||||
$this->assertSame($this->b, $this->b->setSize(2));
|
||||
$this->assertEquals(2, $this->b->getSize());
|
||||
}
|
||||
|
||||
public function testReads()
|
||||
{
|
||||
$this->assertEquals('foo', $this->b->read(10));
|
||||
}
|
||||
|
||||
public function testCheckMethods()
|
||||
{
|
||||
$this->assertEquals($this->a->isReadable(), $this->b->isReadable());
|
||||
$this->assertEquals($this->a->isWritable(), $this->b->isWritable());
|
||||
$this->assertEquals($this->a->isSeekable(), $this->b->isSeekable());
|
||||
}
|
||||
|
||||
public function testSeeksAndTells()
|
||||
{
|
||||
$this->assertTrue($this->b->seek(1));
|
||||
$this->assertEquals(1, $this->a->tell());
|
||||
$this->assertEquals(1, $this->b->tell());
|
||||
$this->assertTrue($this->b->seek(0));
|
||||
$this->assertEquals(0, $this->a->tell());
|
||||
$this->assertEquals(0, $this->b->tell());
|
||||
$this->assertTrue($this->b->seek(0, SEEK_END));
|
||||
$this->assertEquals(3, $this->a->tell());
|
||||
$this->assertEquals(3, $this->b->tell());
|
||||
}
|
||||
|
||||
public function testGetsContents()
|
||||
{
|
||||
$this->assertEquals('foo', $this->b->getContents());
|
||||
$this->assertEquals('', $this->b->getContents());
|
||||
$this->b->seek(1);
|
||||
$this->assertEquals('oo', $this->b->getContents(1));
|
||||
}
|
||||
|
||||
public function testCloses()
|
||||
{
|
||||
$this->b->close();
|
||||
$this->assertFalse(is_resource($this->c));
|
||||
}
|
||||
|
||||
public function testDetaches()
|
||||
{
|
||||
$this->b->detach();
|
||||
$this->assertFalse($this->b->isReadable());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException
|
||||
*/
|
||||
public function testCannotAttachByDefault()
|
||||
{
|
||||
$this->b->attach('a');
|
||||
}
|
||||
|
||||
public function testWrapsMetadata()
|
||||
{
|
||||
$this->assertSame($this->b->getMetadata(), $this->a->getMetadata());
|
||||
$this->assertSame($this->b->getMetadata('uri'), $this->a->getMetadata('uri'));
|
||||
}
|
||||
|
||||
public function testWrapsWrites()
|
||||
{
|
||||
$this->b->seek(0, SEEK_END);
|
||||
$this->b->write('foo');
|
||||
$this->assertEquals('foofoo', (string) $this->a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \UnexpectedValueException
|
||||
*/
|
||||
public function testThrowsWithInvalidGetter()
|
||||
{
|
||||
$this->b->foo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testThrowsWhenGetterNotImplemented()
|
||||
{
|
||||
$s = new BadStream();
|
||||
$s->stream;
|
||||
}
|
||||
}
|
||||
|
||||
class BadStream
|
||||
{
|
||||
use StreamDecoratorTrait;
|
||||
|
||||
public function __construct() {}
|
||||
}
|
252
core/vendor/guzzlehttp/streams/tests/StreamTest.php
vendored
Normal file
252
core/vendor/guzzlehttp/streams/tests/StreamTest.php
vendored
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
|
||||
/**
|
||||
* @covers GuzzleHttp\Stream\Stream
|
||||
*/
|
||||
class StreamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorThrowsExceptionOnInvalidArgument()
|
||||
{
|
||||
new Stream(true);
|
||||
}
|
||||
|
||||
public function testConstructorInitializesProperties()
|
||||
{
|
||||
$handle = fopen('php://temp', 'r+');
|
||||
fwrite($handle, 'data');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertTrue($stream->isReadable());
|
||||
$this->assertTrue($stream->isWritable());
|
||||
$this->assertTrue($stream->isSeekable());
|
||||
$this->assertEquals('php://temp', $stream->getMetadata('uri'));
|
||||
$this->assertInternalType('array', $stream->getMetadata());
|
||||
$this->assertEquals(4, $stream->getSize());
|
||||
$this->assertFalse($stream->eof());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testStreamClosesHandleOnDestruct()
|
||||
{
|
||||
$handle = fopen('php://temp', 'r');
|
||||
$stream = new Stream($handle);
|
||||
unset($stream);
|
||||
$this->assertFalse(is_resource($handle));
|
||||
}
|
||||
|
||||
public function testConvertsToString()
|
||||
{
|
||||
$handle = fopen('php://temp', 'w+');
|
||||
fwrite($handle, 'data');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertEquals('data', (string) $stream);
|
||||
$this->assertEquals('data', (string) $stream);
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testGetsContents()
|
||||
{
|
||||
$handle = fopen('php://temp', 'w+');
|
||||
fwrite($handle, 'data');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertEquals('', $stream->getContents());
|
||||
$stream->seek(0);
|
||||
$this->assertEquals('data', $stream->getContents());
|
||||
$this->assertEquals('', $stream->getContents());
|
||||
}
|
||||
|
||||
public function testChecksEof()
|
||||
{
|
||||
$handle = fopen('php://temp', 'w+');
|
||||
fwrite($handle, 'data');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertFalse($stream->eof());
|
||||
$stream->read(4);
|
||||
$this->assertTrue($stream->eof());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testAllowsSettingManualSize()
|
||||
{
|
||||
$handle = fopen('php://temp', 'w+');
|
||||
fwrite($handle, 'data');
|
||||
$stream = new Stream($handle);
|
||||
$stream->setSize(10);
|
||||
$this->assertEquals(10, $stream->getSize());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testGetSize()
|
||||
{
|
||||
$size = filesize(__FILE__);
|
||||
$handle = fopen(__FILE__, 'r');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertEquals($size, $stream->getSize());
|
||||
// Load from cache
|
||||
$this->assertEquals($size, $stream->getSize());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testEnsuresSizeIsConsistent()
|
||||
{
|
||||
$h = fopen('php://temp', 'w+');
|
||||
$this->assertEquals(3, fwrite($h, 'foo'));
|
||||
$stream = new Stream($h);
|
||||
$this->assertEquals(3, $stream->getSize());
|
||||
$this->assertEquals(4, $stream->write('test'));
|
||||
$this->assertEquals(7, $stream->getSize());
|
||||
$this->assertEquals(7, $stream->getSize());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testProvidesStreamPosition()
|
||||
{
|
||||
$handle = fopen('php://temp', 'w+');
|
||||
$stream = new Stream($handle);
|
||||
$this->assertEquals(0, $stream->tell());
|
||||
$stream->write('foo');
|
||||
$this->assertEquals(3, $stream->tell());
|
||||
$stream->seek(1);
|
||||
$this->assertEquals(1, $stream->tell());
|
||||
$this->assertSame(ftell($handle), $stream->tell());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testKeepsPositionOfResource()
|
||||
{
|
||||
$h = fopen(__FILE__, 'r');
|
||||
fseek($h, 10);
|
||||
$stream = Stream::factory($h);
|
||||
$this->assertEquals(10, $stream->tell());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testCanDetachAndAttachStream()
|
||||
{
|
||||
$r = fopen('php://temp', 'w+');
|
||||
$stream = new Stream($r);
|
||||
$stream->write('foo');
|
||||
$this->assertTrue($stream->isReadable());
|
||||
$this->assertSame($r, $stream->detach());
|
||||
$this->assertNull($stream->detach());
|
||||
|
||||
$this->assertFalse($stream->isReadable());
|
||||
$this->assertFalse($stream->read(10));
|
||||
$this->assertFalse($stream->isWritable());
|
||||
$this->assertFalse($stream->write('bar'));
|
||||
$this->assertFalse($stream->isSeekable());
|
||||
$this->assertFalse($stream->seek(10));
|
||||
$this->assertFalse($stream->tell());
|
||||
$this->assertTrue($stream->eof());
|
||||
$this->assertNull($stream->getSize());
|
||||
$this->assertSame('', (string) $stream);
|
||||
$this->assertSame('', $stream->getContents());
|
||||
|
||||
$stream->attach($r);
|
||||
$stream->seek(0);
|
||||
$this->assertEquals('foo', $stream->getContents());
|
||||
$this->assertTrue($stream->isReadable());
|
||||
$this->assertTrue($stream->isWritable());
|
||||
$this->assertTrue($stream->isSeekable());
|
||||
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testCloseClearProperties()
|
||||
{
|
||||
$handle = fopen('php://temp', 'r+');
|
||||
$stream = new Stream($handle);
|
||||
$stream->close();
|
||||
|
||||
$this->assertEmpty($stream->getMetadata());
|
||||
$this->assertFalse($stream->isSeekable());
|
||||
$this->assertFalse($stream->isReadable());
|
||||
$this->assertFalse($stream->isWritable());
|
||||
$this->assertNull($stream->getSize());
|
||||
}
|
||||
|
||||
public function testCreatesWithFactory()
|
||||
{
|
||||
$stream = Stream::factory('foo');
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\Stream', $stream);
|
||||
$this->assertEquals('foo', $stream->getContents());
|
||||
$stream->close();
|
||||
}
|
||||
|
||||
public function testFactoryCreatesFromEmptyString()
|
||||
{
|
||||
$s = Stream::factory();
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\Stream', $s);
|
||||
}
|
||||
|
||||
public function testFactoryCreatesFromResource()
|
||||
{
|
||||
$r = fopen(__FILE__, 'r');
|
||||
$s = Stream::factory($r);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\Stream', $s);
|
||||
$this->assertSame(file_get_contents(__FILE__), (string) $s);
|
||||
}
|
||||
|
||||
public function testFactoryCreatesFromObjectWithToString()
|
||||
{
|
||||
$r = new HasToString();
|
||||
$s = Stream::factory($r);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\Stream', $s);
|
||||
$this->assertEquals('foo', (string) $s);
|
||||
}
|
||||
|
||||
public function testCreatePassesThrough()
|
||||
{
|
||||
$s = Stream::factory('foo');
|
||||
$this->assertSame($s, Stream::factory($s));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testThrowsExceptionForUnknown()
|
||||
{
|
||||
Stream::factory(new \stdClass());
|
||||
}
|
||||
|
||||
public function testReturnsCustomMetadata()
|
||||
{
|
||||
$s = Stream::factory('foo', ['metadata' => ['hwm' => 3]]);
|
||||
$this->assertEquals(3, $s->getMetadata('hwm'));
|
||||
$this->assertArrayHasKey('hwm', $s->getMetadata());
|
||||
}
|
||||
|
||||
public function testCanSetSize()
|
||||
{
|
||||
$s = Stream::factory('', ['size' => 10]);
|
||||
$this->assertEquals(10, $s->getSize());
|
||||
}
|
||||
|
||||
public function testCanCreateIteratorBasedStream()
|
||||
{
|
||||
$a = new \ArrayIterator(['foo', 'bar', '123']);
|
||||
$p = Stream::factory($a);
|
||||
$this->assertInstanceOf('GuzzleHttp\Stream\PumpStream', $p);
|
||||
$this->assertEquals('foo', $p->read(3));
|
||||
$this->assertFalse($p->eof());
|
||||
$this->assertEquals('b', $p->read(1));
|
||||
$this->assertEquals('a', $p->read(1));
|
||||
$this->assertEquals('r12', $p->read(3));
|
||||
$this->assertFalse($p->eof());
|
||||
$this->assertEquals('3', $p->getContents());
|
||||
$this->assertTrue($p->eof());
|
||||
$this->assertEquals(9, $p->tell());
|
||||
}
|
||||
}
|
||||
|
||||
class HasToString
|
||||
{
|
||||
public function __toString() {
|
||||
return 'foo';
|
||||
}
|
||||
}
|
155
core/vendor/guzzlehttp/streams/tests/UtilsTest.php
vendored
Normal file
155
core/vendor/guzzlehttp/streams/tests/UtilsTest.php
vendored
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
namespace GuzzleHttp\Tests\Stream;
|
||||
|
||||
use GuzzleHttp\Stream\FnStream;
|
||||
use GuzzleHttp\Stream\NoSeekStream;
|
||||
use GuzzleHttp\Stream\Stream;
|
||||
use GuzzleHttp\Stream\Utils;
|
||||
|
||||
class UtilsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCopiesToString()
|
||||
{
|
||||
$s = Stream::factory('foobaz');
|
||||
$this->assertEquals('foobaz', Utils::copyToString($s));
|
||||
$s->seek(0);
|
||||
$this->assertEquals('foo', Utils::copyToString($s, 3));
|
||||
$this->assertEquals('baz', Utils::copyToString($s, 3));
|
||||
$this->assertEquals('', Utils::copyToString($s));
|
||||
}
|
||||
|
||||
public function testCopiesToStringStopsWhenReadFails()
|
||||
{
|
||||
$s1 = Stream::factory('foobaz');
|
||||
$s1 = FnStream::decorate($s1, [
|
||||
'read' => function () {
|
||||
return false;
|
||||
}
|
||||
]);
|
||||
$result = Utils::copyToString($s1);
|
||||
$this->assertEquals('', $result);
|
||||
}
|
||||
|
||||
public function testCopiesToStream()
|
||||
{
|
||||
$s1 = Stream::factory('foobaz');
|
||||
$s2 = Stream::factory('');
|
||||
Utils::copyToStream($s1, $s2);
|
||||
$this->assertEquals('foobaz', (string) $s2);
|
||||
$s2 = Stream::factory('');
|
||||
$s1->seek(0);
|
||||
Utils::copyToStream($s1, $s2, 3);
|
||||
$this->assertEquals('foo', (string) $s2);
|
||||
Utils::copyToStream($s1, $s2, 3);
|
||||
$this->assertEquals('foobaz', (string) $s2);
|
||||
}
|
||||
|
||||
public function testStopsCopyToStreamWhenWriteFails()
|
||||
{
|
||||
$s1 = Stream::factory('foobaz');
|
||||
$s2 = Stream::factory('');
|
||||
$s2 = FnStream::decorate($s2, ['write' => function () { return 0; }]);
|
||||
Utils::copyToStream($s1, $s2);
|
||||
$this->assertEquals('', (string) $s2);
|
||||
}
|
||||
|
||||
public function testStopsCopyToSteamWhenWriteFailsWithMaxLen()
|
||||
{
|
||||
$s1 = Stream::factory('foobaz');
|
||||
$s2 = Stream::factory('');
|
||||
$s2 = FnStream::decorate($s2, ['write' => function () { return 0; }]);
|
||||
Utils::copyToStream($s1, $s2, 10);
|
||||
$this->assertEquals('', (string) $s2);
|
||||
}
|
||||
|
||||
public function testStopsCopyToSteamWhenReadFailsWithMaxLen()
|
||||
{
|
||||
$s1 = Stream::factory('foobaz');
|
||||
$s1 = FnStream::decorate($s1, ['read' => function () { return ''; }]);
|
||||
$s2 = Stream::factory('');
|
||||
Utils::copyToStream($s1, $s2, 10);
|
||||
$this->assertEquals('', (string) $s2);
|
||||
}
|
||||
|
||||
public function testReadsLines()
|
||||
{
|
||||
$s = Stream::factory("foo\nbaz\nbar");
|
||||
$this->assertEquals("foo\n", Utils::readline($s));
|
||||
$this->assertEquals("baz\n", Utils::readline($s));
|
||||
$this->assertEquals("bar", Utils::readline($s));
|
||||
}
|
||||
|
||||
public function testReadsLinesUpToMaxLength()
|
||||
{
|
||||
$s = Stream::factory("12345\n");
|
||||
$this->assertEquals("123", Utils::readline($s, 4));
|
||||
$this->assertEquals("45\n", Utils::readline($s));
|
||||
}
|
||||
|
||||
public function testReadsLineUntilFalseReturnedFromRead()
|
||||
{
|
||||
$s = $this->getMockBuilder('GuzzleHttp\Stream\Stream')
|
||||
->setMethods(['read', 'eof'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$s->expects($this->exactly(2))
|
||||
->method('read')
|
||||
->will($this->returnCallback(function () {
|
||||
static $c = false;
|
||||
if ($c) {
|
||||
return false;
|
||||
}
|
||||
$c = true;
|
||||
return 'h';
|
||||
}));
|
||||
$s->expects($this->exactly(2))
|
||||
->method('eof')
|
||||
->will($this->returnValue(false));
|
||||
$this->assertEquals("h", Utils::readline($s));
|
||||
}
|
||||
|
||||
public function testCalculatesHash()
|
||||
{
|
||||
$s = Stream::factory('foobazbar');
|
||||
$this->assertEquals(md5('foobazbar'), Utils::hash($s, 'md5'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Stream\Exception\SeekException
|
||||
*/
|
||||
public function testCalculatesHashThrowsWhenSeekFails()
|
||||
{
|
||||
$s = new NoSeekStream(Stream::factory('foobazbar'));
|
||||
$s->read(2);
|
||||
Utils::hash($s, 'md5');
|
||||
}
|
||||
|
||||
public function testCalculatesHashSeeksToOriginalPosition()
|
||||
{
|
||||
$s = Stream::factory('foobazbar');
|
||||
$s->seek(4);
|
||||
$this->assertEquals(md5('foobazbar'), Utils::hash($s, 'md5'));
|
||||
$this->assertEquals(4, $s->tell());
|
||||
}
|
||||
|
||||
public function testOpensFilesSuccessfully()
|
||||
{
|
||||
$r = Utils::open(__FILE__, 'r');
|
||||
$this->assertInternalType('resource', $r);
|
||||
fclose($r);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Unable to open /path/to/does/not/exist using mode r
|
||||
*/
|
||||
public function testThrowsExceptionNotWarning()
|
||||
{
|
||||
Utils::open('/path/to/does/not/exist', 'r');
|
||||
}
|
||||
|
||||
public function testProxiesToFactory()
|
||||
{
|
||||
$this->assertEquals('foo', (string) Utils::create('foo'));
|
||||
}
|
||||
}
|
Reference in a new issue