-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c455a
commit 6a31c27
Showing
11 changed files
with
142 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nyholm\Psr7; | ||
|
||
use Psr\Http\Message\StreamInterface; | ||
use Symfony\Component\Debug\ErrorHandler as SymfonyLegacyErrorHandler; | ||
use Symfony\Component\ErrorHandler\ErrorHandler as SymfonyErrorHandler; | ||
|
||
if (\PHP_VERSION_ID >= 70400 || (new \ReflectionMethod(StreamInterface::class, '__toString'))->hasReturnType()) { | ||
/** | ||
* @internal | ||
*/ | ||
trait StreamTrait | ||
{ | ||
public function __toString(): string | ||
{ | ||
if ($this->isSeekable()) { | ||
$this->seek(0); | ||
} | ||
|
||
return $this->getContents(); | ||
} | ||
} | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait StreamTrait | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
try { | ||
if ($this->isSeekable()) { | ||
$this->seek(0); | ||
} | ||
|
||
return $this->getContents(); | ||
} catch (\Throwable $e) { | ||
if (\is_array($errorHandler = \set_error_handler('var_dump'))) { | ||
$errorHandler = $errorHandler[0] ?? null; | ||
} | ||
\restore_error_handler(); | ||
|
||
if ($e instanceof \Error || $errorHandler instanceof SymfonyErrorHandler || $errorHandler instanceof SymfonyLegacyErrorHandler) { | ||
return \trigger_error((string) $e, \E_USER_ERROR); | ||
} | ||
|
||
return ''; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.