| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Give\Vendors\Nyholm\Psr7; |
| 6 |
|
| 7 |
use Give\Vendors\Psr\Http\Message\StreamInterface; |
| 8 |
use Symfony\Component\Debug\ErrorHandler as SymfonyLegacyErrorHandler; |
| 9 |
use Symfony\Component\ErrorHandler\ErrorHandler as SymfonyErrorHandler; |
| 10 |
|
| 11 |
if (\PHP_VERSION_ID >= 70400 || (new \ReflectionMethod(StreamInterface::class, '__toString'))->hasReturnType()) { |
| 12 |
/** |
| 13 |
* @internal |
| 14 |
*/ |
| 15 |
trait StreamTrait |
| 16 |
{ |
| 17 |
public function __toString(): string |
| 18 |
{ |
| 19 |
if ($this->isSeekable()) { |
| 20 |
$this->seek(0); |
| 21 |
} |
| 22 |
|
| 23 |
return $this->getContents(); |
| 24 |
} |
| 25 |
} |
| 26 |
} else { |
| 27 |
/** |
| 28 |
* @internal |
| 29 |
*/ |
| 30 |
trait StreamTrait |
| 31 |
{ |
| 32 |
/** |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public function __toString() |
| 36 |
{ |
| 37 |
try { |
| 38 |
if ($this->isSeekable()) { |
| 39 |
$this->seek(0); |
| 40 |
} |
| 41 |
|
| 42 |
return $this->getContents(); |
| 43 |
} catch (\Throwable $e) { |
| 44 |
if (\is_array($errorHandler = \set_error_handler('var_dump'))) { |
| 45 |
$errorHandler = $errorHandler[0] ?? null; |
| 46 |
} |
| 47 |
\restore_error_handler(); |
| 48 |
|
| 49 |
if ($e instanceof \Error || $errorHandler instanceof SymfonyErrorHandler || $errorHandler instanceof SymfonyLegacyErrorHandler) { |
| 50 |
return \trigger_error((string) $e, \E_USER_ERROR); |
| 51 |
} |
| 52 |
|
| 53 |
return ''; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|