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
- 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>
249 lines
5.4 KiB
PHP
249 lines
5.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace GuzzleHttp\Psr7;
|
|
|
|
use Psr\Http\Message\StreamInterface;
|
|
|
|
/**
|
|
* Converts Guzzle streams into PHP stream resources.
|
|
*
|
|
* @see https://www.php.net/streamwrapper
|
|
*/
|
|
final class StreamWrapper
|
|
{
|
|
/** @var resource */
|
|
public $context;
|
|
|
|
private StreamInterface $stream;
|
|
|
|
/** @var string r, r+, or w */
|
|
private string $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.');
|
|
}
|
|
|
|
$resource = @fopen('guzzle://stream', $mode, false, self::createStreamContext($stream));
|
|
|
|
if ($resource === false) {
|
|
throw new \RuntimeException('Unable to create stream resource');
|
|
}
|
|
|
|
return $resource;
|
|
}
|
|
|
|
/**
|
|
* Creates a stream context that can be used to open a stream as a php stream resource.
|
|
*
|
|
* @return resource
|
|
*/
|
|
public static function createStreamContext(StreamInterface $stream)
|
|
{
|
|
return stream_context_create([
|
|
'guzzle' => ['stream' => $stream],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Registers the stream wrapper if needed
|
|
*/
|
|
public static function register(): void
|
|
{
|
|
if (!in_array('guzzle', stream_get_wrappers())) {
|
|
stream_wrapper_register('guzzle', __CLASS__);
|
|
}
|
|
}
|
|
|
|
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path = null): bool
|
|
{
|
|
$options = stream_context_get_options($this->context);
|
|
$stream = $options['guzzle']['stream'] ?? null;
|
|
|
|
if (!$stream instanceof StreamInterface) {
|
|
return false;
|
|
}
|
|
|
|
$this->mode = $mode;
|
|
$this->stream = $stream;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return string|false
|
|
*/
|
|
public function stream_read(int $count)
|
|
{
|
|
try {
|
|
return $this->stream->read($count);
|
|
} catch (\RuntimeException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function stream_write(string $data): int
|
|
{
|
|
try {
|
|
return $this->stream->write($data);
|
|
} catch (\RuntimeException $e) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return int|false
|
|
*/
|
|
public function stream_tell()
|
|
{
|
|
try {
|
|
return $this->stream->tell();
|
|
} catch (\RuntimeException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function stream_eof(): bool
|
|
{
|
|
try {
|
|
return $this->stream->eof();
|
|
} catch (\RuntimeException $e) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public function stream_seek(int $offset, int $whence): bool
|
|
{
|
|
try {
|
|
$this->stream->seek($offset, $whence);
|
|
} catch (\RuntimeException $e) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return resource|false
|
|
*/
|
|
public function stream_cast(int $cast_as)
|
|
{
|
|
try {
|
|
$stream = clone $this->stream;
|
|
$resource = $stream->detach();
|
|
} catch (\RuntimeException $e) {
|
|
return false;
|
|
}
|
|
|
|
return $resource ?? false;
|
|
}
|
|
|
|
/**
|
|
* @return array{
|
|
* dev: int,
|
|
* ino: int,
|
|
* mode: int,
|
|
* nlink: int,
|
|
* uid: int,
|
|
* gid: int,
|
|
* rdev: int,
|
|
* size: int,
|
|
* atime: int,
|
|
* mtime: int,
|
|
* ctime: int,
|
|
* blksize: int,
|
|
* blocks: int
|
|
* }|false
|
|
*/
|
|
public function stream_stat()
|
|
{
|
|
try {
|
|
$size = $this->stream->getSize();
|
|
} catch (\RuntimeException $e) {
|
|
return false;
|
|
}
|
|
|
|
if ($size === null) {
|
|
return false;
|
|
}
|
|
|
|
static $modeMap = [
|
|
'r' => 33060,
|
|
'rb' => 33060,
|
|
'r+' => 33206,
|
|
'w' => 33188,
|
|
'wb' => 33188,
|
|
];
|
|
|
|
return [
|
|
'dev' => 0,
|
|
'ino' => 0,
|
|
'mode' => $modeMap[$this->mode] ?? 0,
|
|
'nlink' => 0,
|
|
'uid' => 0,
|
|
'gid' => 0,
|
|
'rdev' => 0,
|
|
'size' => $size,
|
|
'atime' => 0,
|
|
'mtime' => 0,
|
|
'ctime' => 0,
|
|
'blksize' => 0,
|
|
'blocks' => 0,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{
|
|
* dev: int,
|
|
* ino: int,
|
|
* mode: int,
|
|
* nlink: int,
|
|
* uid: int,
|
|
* gid: int,
|
|
* rdev: int,
|
|
* size: int,
|
|
* atime: int,
|
|
* mtime: int,
|
|
* ctime: int,
|
|
* blksize: int,
|
|
* blocks: int
|
|
* }
|
|
*/
|
|
public function url_stat(string $path, int $flags): array
|
|
{
|
|
return [
|
|
'dev' => 0,
|
|
'ino' => 0,
|
|
'mode' => 0,
|
|
'nlink' => 0,
|
|
'uid' => 0,
|
|
'gid' => 0,
|
|
'rdev' => 0,
|
|
'size' => 0,
|
|
'atime' => 0,
|
|
'mtime' => 0,
|
|
'ctime' => 0,
|
|
'blksize' => 0,
|
|
'blocks' => 0,
|
|
];
|
|
}
|
|
}
|