1KA_F2F/vendor/guzzlehttp/psr7/src/AppendStream.php
pero1203 4cec48f127 Merge branch 'master' into release/produkcija
# Conflicts:
#	.gitignore
#	vendor/autoload.php
#	vendor/composer/ClassLoader.php
#	vendor/composer/LICENSE
#	vendor/composer/autoload_classmap.php
#	vendor/composer/autoload_files.php
#	vendor/composer/autoload_psr4.php
#	vendor/composer/autoload_real.php
#	vendor/composer/autoload_static.php
#	vendor/composer/installed.json
#	vendor/fgrosse/phpasn1/CHANGELOG.md
#	vendor/fgrosse/phpasn1/composer.json
#	vendor/fgrosse/phpasn1/lib/Utility/BigInteger.php
#	vendor/geoip2/geoip2/CHANGELOG.md
#	vendor/geoip2/geoip2/composer.json
#	vendor/geoip2/geoip2/src/Database/Reader.php
#	vendor/geoip2/geoip2/src/Exception/AddressNotFoundException.php
#	vendor/geoip2/geoip2/src/Exception/AuthenticationException.php
#	vendor/geoip2/geoip2/src/Exception/GeoIp2Exception.php
#	vendor/geoip2/geoip2/src/Exception/HttpException.php
#	vendor/geoip2/geoip2/src/Exception/InvalidRequestException.php
#	vendor/geoip2/geoip2/src/Exception/OutOfQueriesException.php
#	vendor/geoip2/geoip2/src/Model/AbstractModel.php
#	vendor/geoip2/geoip2/src/Model/AnonymousIp.php
#	vendor/geoip2/geoip2/src/Model/Asn.php
#	vendor/geoip2/geoip2/src/Model/City.php
#	vendor/geoip2/geoip2/src/Model/ConnectionType.php
#	vendor/geoip2/geoip2/src/Model/Country.php
#	vendor/geoip2/geoip2/src/Model/Domain.php
#	vendor/geoip2/geoip2/src/Model/Enterprise.php
#	vendor/geoip2/geoip2/src/Model/Insights.php
#	vendor/geoip2/geoip2/src/Model/Isp.php
#	vendor/geoip2/geoip2/src/ProviderInterface.php
#	vendor/geoip2/geoip2/src/Record/AbstractPlaceRecord.php
#	vendor/geoip2/geoip2/src/Record/AbstractRecord.php
#	vendor/geoip2/geoip2/src/Record/City.php
#	vendor/geoip2/geoip2/src/Record/Continent.php
#	vendor/geoip2/geoip2/src/Record/Country.php
#	vendor/geoip2/geoip2/src/Record/Location.php
#	vendor/geoip2/geoip2/src/Record/MaxMind.php
#	vendor/geoip2/geoip2/src/Record/Postal.php
#	vendor/geoip2/geoip2/src/Record/RepresentedCountry.php
#	vendor/geoip2/geoip2/src/Record/Subdivision.php
#	vendor/geoip2/geoip2/src/Record/Traits.php
#	vendor/geoip2/geoip2/src/Util.php
#	vendor/geoip2/geoip2/src/WebService/Client.php
#	vendor/guzzlehttp/promises/CHANGELOG.md
#	vendor/guzzlehttp/promises/README.md
#	vendor/guzzlehttp/promises/composer.json
#	vendor/guzzlehttp/promises/src/AggregateException.php
#	vendor/guzzlehttp/promises/src/CancellationException.php
#	vendor/guzzlehttp/promises/src/Coroutine.php
#	vendor/guzzlehttp/promises/src/EachPromise.php
#	vendor/guzzlehttp/promises/src/FulfilledPromise.php
#	vendor/guzzlehttp/promises/src/Promise.php
#	vendor/guzzlehttp/promises/src/PromiseInterface.php
#	vendor/guzzlehttp/promises/src/PromisorInterface.php
#	vendor/guzzlehttp/promises/src/RejectedPromise.php
#	vendor/guzzlehttp/promises/src/RejectionException.php
#	vendor/guzzlehttp/promises/src/TaskQueue.php
#	vendor/guzzlehttp/promises/src/TaskQueueInterface.php
#	vendor/guzzlehttp/promises/src/functions.php
#	vendor/guzzlehttp/psr7/CHANGELOG.md
#	vendor/guzzlehttp/psr7/README.md
#	vendor/guzzlehttp/psr7/composer.json
#	vendor/guzzlehttp/psr7/src/AppendStream.php
#	vendor/guzzlehttp/psr7/src/BufferStream.php
#	vendor/guzzlehttp/psr7/src/CachingStream.php
#	vendor/guzzlehttp/psr7/src/DroppingStream.php
#	vendor/guzzlehttp/psr7/src/FnStream.php
#	vendor/guzzlehttp/psr7/src/InflateStream.php
#	vendor/guzzlehttp/psr7/src/LazyOpenStream.php
#	vendor/guzzlehttp/psr7/src/LimitStream.php
#	vendor/guzzlehttp/psr7/src/MessageTrait.php
#	vendor/guzzlehttp/psr7/src/MultipartStream.php
#	vendor/guzzlehttp/psr7/src/NoSeekStream.php
#	vendor/guzzlehttp/psr7/src/PumpStream.php
#	vendor/guzzlehttp/psr7/src/Request.php
#	vendor/guzzlehttp/psr7/src/Response.php
#	vendor/guzzlehttp/psr7/src/ServerRequest.php
#	vendor/guzzlehttp/psr7/src/Stream.php
#	vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php
#	vendor/guzzlehttp/psr7/src/StreamWrapper.php
#	vendor/guzzlehttp/psr7/src/UploadedFile.php
#	vendor/guzzlehttp/psr7/src/Uri.php
#	vendor/guzzlehttp/psr7/src/UriNormalizer.php
#	vendor/guzzlehttp/psr7/src/UriResolver.php
#	vendor/guzzlehttp/psr7/src/functions.php
#	vendor/maxmind-db/reader/CHANGELOG.md
#	vendor/maxmind-db/reader/composer.json
#	vendor/maxmind-db/reader/ext/maxminddb.c
#	vendor/maxmind-db/reader/ext/php_maxminddb.h
#	vendor/maxmind-db/reader/package.xml
#	vendor/maxmind/web-service-common/CHANGELOG.md
#	vendor/maxmind/web-service-common/README.md
#	vendor/maxmind/web-service-common/composer.json
#	vendor/maxmind/web-service-common/src/Exception/AuthenticationException.php
#	vendor/maxmind/web-service-common/src/Exception/HttpException.php
#	vendor/maxmind/web-service-common/src/Exception/InsufficientFundsException.php
#	vendor/maxmind/web-service-common/src/Exception/InvalidInputException.php
#	vendor/maxmind/web-service-common/src/Exception/InvalidRequestException.php
#	vendor/maxmind/web-service-common/src/Exception/IpAddressNotFoundException.php
#	vendor/maxmind/web-service-common/src/Exception/PermissionRequiredException.php
#	vendor/maxmind/web-service-common/src/Exception/WebServiceException.php
#	vendor/maxmind/web-service-common/src/WebService/Client.php
#	vendor/maxmind/web-service-common/src/WebService/Http/CurlRequest.php
#	vendor/maxmind/web-service-common/src/WebService/Http/Request.php
#	vendor/maxmind/web-service-common/src/WebService/Http/RequestFactory.php
#	vendor/paragonie/random_compat/composer.json
#	vendor/paragonie/sodium_compat/.gitignore
#	vendor/paragonie/sodium_compat/composer.json
#	vendor/paragonie/sodium_compat/psalm-above-3.xml
#	vendor/paragonie/sodium_compat/src/Core/Ed25519.php
#	vendor/paragonie/sodium_compat/src/Core/SipHash.php
#	vendor/paragonie/sodium_compat/src/Core/Util.php
#	vendor/paragonie/sodium_compat/src/Core32/Ed25519.php
#	vendor/paragonie/sodium_compat/src/File.php
#	vendor/paragonie/sodium_compat/src/PHP52/SplFixedArray.php
#	vendor/phpmailer/phpmailer/README.md
#	vendor/phpmailer/phpmailer/VERSION
#	vendor/phpmailer/phpmailer/composer.json
#	vendor/phpmailer/phpmailer/get_oauth_token.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-af.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ar.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-az.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ba.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-be.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-bg.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ca.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ch.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-cs.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-da.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-de.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-el.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-eo.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-es.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-et.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-fa.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-fi.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-fo.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-fr.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-gl.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-he.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-hi.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-hr.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-hu.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-hy.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-id.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-it.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ja.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ka.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ko.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-lt.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-lv.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-mg.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ms.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-nb.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-nl.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-pl.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-pt.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-pt_br.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ro.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-ru.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-sk.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-sl.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-sr.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-sv.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-tl.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-tr.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-uk.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-vi.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-zh.php
#	vendor/phpmailer/phpmailer/language/phpmailer.lang-zh_cn.php
#	vendor/phpmailer/phpmailer/src/Exception.php
#	vendor/phpmailer/phpmailer/src/OAuth.php
#	vendor/phpmailer/phpmailer/src/PHPMailer.php
#	vendor/phpmailer/phpmailer/src/POP3.php
#	vendor/phpmailer/phpmailer/src/SMTP.php
#	vendor/spomky-labs/base64url/composer.json
#	vendor/stripe/stripe-php/CHANGELOG.md
#	vendor/stripe/stripe-php/VERSION
#	vendor/stripe/stripe-php/composer.json
#	vendor/stripe/stripe-php/init.php
#	vendor/stripe/stripe-php/lib/Account.php
#	vendor/stripe/stripe-php/lib/ApiRequestor.php
#	vendor/stripe/stripe-php/lib/ApplicationFeeRefund.php
#	vendor/stripe/stripe-php/lib/Balance.php
#	vendor/stripe/stripe-php/lib/BalanceTransaction.php
#	vendor/stripe/stripe-php/lib/BaseStripeClient.php
#	vendor/stripe/stripe-php/lib/BitcoinReceiver.php
#	vendor/stripe/stripe-php/lib/Card.php
#	vendor/stripe/stripe-php/lib/Charge.php
#	vendor/stripe/stripe-php/lib/Checkout/Session.php
#	vendor/stripe/stripe-php/lib/Coupon.php
#	vendor/stripe/stripe-php/lib/CreditNote.php
#	vendor/stripe/stripe-php/lib/CreditNoteLineItem.php
#	vendor/stripe/stripe-php/lib/Customer.php
#	vendor/stripe/stripe-php/lib/ErrorObject.php
#	vendor/stripe/stripe-php/lib/Event.php
#	vendor/stripe/stripe-php/lib/HttpClient/CurlClient.php
#	vendor/stripe/stripe-php/lib/Invoice.php
#	vendor/stripe/stripe-php/lib/InvoiceItem.php
#	vendor/stripe/stripe-php/lib/InvoiceLineItem.php
#	vendor/stripe/stripe-php/lib/Order.php
#	vendor/stripe/stripe-php/lib/PaymentIntent.php
#	vendor/stripe/stripe-php/lib/PaymentMethod.php
#	vendor/stripe/stripe-php/lib/Payout.php
#	vendor/stripe/stripe-php/lib/Plan.php
#	vendor/stripe/stripe-php/lib/PromotionCode.php
#	vendor/stripe/stripe-php/lib/Refund.php
#	vendor/stripe/stripe-php/lib/Service/CoreServiceFactory.php
#	vendor/stripe/stripe-php/lib/Service/CustomerService.php
#	vendor/stripe/stripe-php/lib/Service/InvoiceService.php
#	vendor/stripe/stripe-php/lib/Service/PayoutService.php
#	vendor/stripe/stripe-php/lib/Service/SubscriptionScheduleService.php
#	vendor/stripe/stripe-php/lib/Service/SubscriptionService.php
#	vendor/stripe/stripe-php/lib/SetupIntent.php
#	vendor/stripe/stripe-php/lib/Source.php
#	vendor/stripe/stripe-php/lib/Stripe.php
#	vendor/stripe/stripe-php/lib/StripeClient.php
#	vendor/stripe/stripe-php/lib/StripeObject.php
#	vendor/stripe/stripe-php/lib/Subscription.php
#	vendor/stripe/stripe-php/lib/TaxId.php
#	vendor/stripe/stripe-php/lib/TaxRate.php
#	vendor/stripe/stripe-php/lib/TransferReversal.php
#	vendor/stripe/stripe-php/lib/Util/ObjectTypes.php
#	vendor/stripe/stripe-php/lib/Util/Util.php
#	vendor/symfony/polyfill-intl-idn/Idn.php
#	vendor/symfony/polyfill-intl-idn/composer.json
#	vendor/symfony/polyfill-intl-normalizer/bootstrap.php
#	vendor/symfony/polyfill-intl-normalizer/composer.json
#	vendor/symfony/polyfill-php72/Php72.php
#	vendor/symfony/polyfill-php72/bootstrap.php
#	vendor/symfony/polyfill-php72/composer.json
2020-12-05 13:00:23 +01:00

255 lines
5.8 KiB
PHP

<?php
<<<<<<< HEAD
=======
>>>>>>> master
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
/**
* 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;
/**
* @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->rewind();
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()
{
<<<<<<< HEAD
return copy_to_string($this);
=======
return Utils::copyToString($this);
>>>>>>> master
}
/**
* Closes each attached stream.
*
* {@inheritdoc}
*/
public function close()
{
$this->pos = $this->current = 0;
$this->seekable = true;
foreach ($this->streams as $stream) {
$stream->close();
}
$this->streams = [];
}
/**
* Detaches each attached stream.
*
* Returns null as it's not clear which underlying stream resource to return.
*
* {@inheritdoc}
*/
public function detach()
{
$this->pos = $this->current = 0;
$this->seekable = true;
foreach ($this->streams as $stream) {
$stream->detach();
}
$this->streams = [];
<<<<<<< HEAD
=======
return null;
>>>>>>> master
}
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());
}
public function rewind()
{
$this->seek(0);
}
/**
* Attempts to seek to the given position. Only supports SEEK_SET.
*
* {@inheritdoc}
*/
public function seek($offset, $whence = SEEK_SET)
{
if (!$this->seekable) {
throw new \RuntimeException('This AppendStream is not seekable');
} elseif ($whence !== SEEK_SET) {
throw new \RuntimeException('The AppendStream can only seek with SEEK_SET');
}
$this->pos = $this->current = 0;
// Rewind each stream
foreach ($this->streams as $i => $stream) {
try {
$stream->rewind();
} catch (\Exception $e) {
throw new \RuntimeException('Unable to seek stream '
. $i . ' of the AppendStream', 0, $e);
}
}
// Seek to the actual position by reading from each stream
while ($this->pos < $offset && !$this->eof()) {
$result = $this->read(min(8096, $offset - $this->pos));
if ($result === '') {
break;
}
}
}
/**
* 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;
$progressToNext = false;
while ($remaining > 0) {
// Progress to the next stream if needed.
if ($progressToNext || $this->streams[$this->current]->eof()) {
$progressToNext = false;
if ($this->current === $total) {
break;
}
$this->current++;
}
$result = $this->streams[$this->current]->read($remaining);
// Using a loose comparison here to match on '', false, and null
if ($result == null) {
$progressToNext = true;
continue;
}
$buffer .= $result;
$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)
{
throw new \RuntimeException('Cannot write to an AppendStream');
}
public function getMetadata($key = null)
{
return $key ? null : [];
}
}