Loheide-eu-mitarbeiterplatt.../vendor/guzzlehttp/psr7/src/FnStream.php
Friederich Loheide 9c0f8de791
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Phase 0: Fundament für Inhaus
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 20:35:30 +00:00

250 lines
5.6 KiB
PHP

<?php
declare(strict_types=1);
namespace GuzzleHttp\Psr7;
use Psr\Http\Message\StreamInterface;
/**
* Compose stream implementations based on a hash of callables.
*
* Allows for easy testing and extension of a provided stream without needing
* to create a concrete class for a simple extension point.
*/
#[\AllowDynamicProperties]
final class FnStream implements StreamInterface
{
use NonSerializableStreamTrait;
private const SLOTS = [
'__toString', 'close', 'detach', 'rewind',
'getSize', 'tell', 'eof', 'isSeekable', 'seek', 'isWritable', 'write',
'isReadable', 'read', 'getContents', 'getMetadata',
];
/** @var array<string, callable> */
private array $methods;
private bool $detached = false;
/**
* @param array<string, callable> $methods Hash of method name to a callable.
*/
public function __construct(array $methods)
{
$this->methods = $methods;
// Create the callables on the class
foreach ($methods as $name => $fn) {
$this->{'_fn_'.$name} = $fn;
}
}
/**
* Lazily determine which methods are not implemented.
*
* @throws \BadMethodCallException
*/
public function __get(string $name): void
{
throw new \BadMethodCallException(\sprintf('%s() is not implemented in the FnStream', DiagnosticValue::escape(str_replace('_fn_', '', $name))));
}
/**
* The close method is called on the underlying stream only if possible.
*/
public function __destruct()
{
if ($this->detached || !isset($this->_fn_close)) {
return;
}
try {
$this->close();
} catch (\Throwable $e) {
// Destructors must not surface cleanup failures.
}
}
/**
* An unserialize would allow the __destruct to run when the unserialized value goes out of scope.
*
* @throws \LogicException
*/
public function __wakeup(): void
{
$this->methods = [];
$this->detached = true;
throw new \LogicException(static::class.' should never be unserialized');
}
public function __unserialize(array $data): void
{
$this->methods = [];
$this->detached = true;
throw new \LogicException(static::class.' should never be unserialized');
}
/**
* Adds custom functionality to an underlying stream by intercepting
* specific method calls.
*
* @param StreamInterface $stream Stream to decorate
* @param array<string, callable> $methods Hash of method name to a callable
*/
public static function decorate(StreamInterface $stream, array $methods): self
{
// 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) {
/** @var callable $callable */
$callable = [$stream, $diff];
$methods[$diff] = $callable;
}
return new self($methods);
}
public function __toString(): string
{
$this->assertAttached();
/** @var string */
return ($this->_fn___toString)();
}
public function close(): void
{
if ($this->detached) {
return;
}
$close = $this->_fn_close;
$this->detached = true;
$close();
}
public function detach()
{
if ($this->detached) {
return null;
}
$detach = $this->_fn_detach;
$result = $detach();
$this->detached = true;
return $result;
}
public function getSize(): ?int
{
if ($this->detached) {
return null;
}
return ($this->_fn_getSize)();
}
public function tell(): int
{
$this->assertAttached();
return ($this->_fn_tell)();
}
public function eof(): bool
{
$this->assertAttached();
return ($this->_fn_eof)();
}
public function isSeekable(): bool
{
if ($this->detached) {
return false;
}
return ($this->_fn_isSeekable)();
}
public function rewind(): void
{
$this->assertAttached();
($this->_fn_rewind)();
}
public function seek(int $offset, int $whence = SEEK_SET): void
{
$this->assertAttached();
($this->_fn_seek)($offset, $whence);
}
public function isWritable(): bool
{
if ($this->detached) {
return false;
}
return ($this->_fn_isWritable)();
}
public function write(string $string): int
{
$this->assertAttached();
return ($this->_fn_write)($string);
}
public function isReadable(): bool
{
if ($this->detached) {
return false;
}
return ($this->_fn_isReadable)();
}
public function read(int $length): string
{
$this->assertAttached();
if ($length < 0) {
throw new \RuntimeException('Length parameter cannot be negative');
}
return ($this->_fn_read)($length);
}
public function getContents(): string
{
$this->assertAttached();
return ($this->_fn_getContents)();
}
/**
* @return mixed
*/
public function getMetadata(?string $key = null)
{
if ($this->detached) {
return $key === null ? [] : null;
}
return ($this->_fn_getMetadata)($key);
}
private function assertAttached(): void
{
if ($this->detached) {
throw new \RuntimeException('Stream is detached');
}
}
}