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>
120 lines
3.3 KiB
PHP
120 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace GuzzleHttp\Promise;
|
|
|
|
/**
|
|
* A promise that has been rejected.
|
|
*
|
|
* Thenning off of this promise will invoke the onRejected callback
|
|
* immediately and ignore other callbacks.
|
|
*
|
|
* @template TValue = never
|
|
* @template TReason = mixed
|
|
*
|
|
* @implements PromiseInterface<TValue, TReason>
|
|
*
|
|
* @final
|
|
*/
|
|
class RejectedPromise implements PromiseInterface
|
|
{
|
|
/** @var TReason */
|
|
private $reason;
|
|
|
|
/**
|
|
* @param TReason $reason
|
|
*/
|
|
public function __construct($reason)
|
|
{
|
|
if (is_object($reason) && method_exists($reason, 'then')) {
|
|
throw new \InvalidArgumentException(
|
|
'You cannot create a RejectedPromise with a promise.'
|
|
);
|
|
}
|
|
|
|
$this->reason = $reason;
|
|
}
|
|
|
|
/**
|
|
* @template TFulfilledValue = never
|
|
* @template TFulfilledReason = never
|
|
* @template TRejectedValue = never
|
|
* @template TRejectedReason = never
|
|
*
|
|
* @param (callable(TValue): (TFulfilledValue|PromiseInterface<TFulfilledValue, TFulfilledReason>))|null $onFulfilled Invoked when the promise fulfills.
|
|
* @param (callable(TReason): (TRejectedValue|PromiseInterface<TRejectedValue, TRejectedReason>))|null $onRejected Invoked when the promise is rejected.
|
|
*
|
|
* @return ($onRejected is null ? self<TValue, TReason> : PromiseInterface<TRejectedValue, TRejectedReason|\Throwable>)
|
|
*/
|
|
public function then(
|
|
?callable $onFulfilled = null,
|
|
?callable $onRejected = null
|
|
): PromiseInterface {
|
|
// If there's no onRejected callback then just return self.
|
|
if (!$onRejected) {
|
|
return $this;
|
|
}
|
|
|
|
$queue = Utils::queue();
|
|
$reason = $this->reason;
|
|
$p = new Promise([$queue, 'run']);
|
|
$queue->add(static function () use ($p, $reason, $onRejected): void {
|
|
if (Is::pending($p)) {
|
|
try {
|
|
// Return a resolved promise if onRejected does not throw.
|
|
$p->resolve($onRejected($reason));
|
|
} catch (\Throwable $e) {
|
|
// onRejected threw, so return a rejected promise.
|
|
$p->reject($e);
|
|
}
|
|
}
|
|
});
|
|
|
|
return $p;
|
|
}
|
|
|
|
/**
|
|
* @template TRejectedValue = never
|
|
* @template TRejectedReason = never
|
|
*
|
|
* @param callable(TReason): (TRejectedValue|PromiseInterface<TRejectedValue, TRejectedReason>) $onRejected Invoked when the promise is rejected.
|
|
*
|
|
* @return PromiseInterface<TRejectedValue, TRejectedReason|\Throwable>
|
|
*/
|
|
public function otherwise(callable $onRejected): PromiseInterface
|
|
{
|
|
return $this->then(null, $onRejected);
|
|
}
|
|
|
|
public function wait(bool $unwrap = true)
|
|
{
|
|
if ($unwrap) {
|
|
throw Create::exceptionFor($this->reason);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getState(): string
|
|
{
|
|
return self::REJECTED;
|
|
}
|
|
|
|
public function resolve($value = null): void
|
|
{
|
|
throw new \LogicException('Cannot resolve a rejected promise');
|
|
}
|
|
|
|
public function reject($reason): void
|
|
{
|
|
if ($reason !== $this->reason) {
|
|
throw new \LogicException('Cannot reject a rejected promise');
|
|
}
|
|
}
|
|
|
|
public function cancel(): void
|
|
{
|
|
// pass
|
|
}
|
|
}
|