36 lines
991 B
PHP
36 lines
991 B
PHP
<?php
|
|
|
|
namespace App\Exceptions\Offer;
|
|
|
|
use App\Models\Offer;
|
|
use DomainException;
|
|
|
|
/**
|
|
* Geworfen, wenn eine Aktion den Offer in einem Status verlangt, in dem er
|
|
* gerade nicht ist (z. B. accept auf einem Draft, convertToBooking auf nicht-accepted).
|
|
*/
|
|
class InvalidOfferStatusException extends DomainException
|
|
{
|
|
public readonly int $offerId;
|
|
public readonly string $currentStatus;
|
|
/** @var string[] */
|
|
public readonly array $expectedStatuses;
|
|
|
|
/**
|
|
* @param string[] $expected
|
|
*/
|
|
public function __construct(Offer $offer, array $expected, string $action)
|
|
{
|
|
$this->offerId = $offer->id;
|
|
$this->currentStatus = $offer->status;
|
|
$this->expectedStatuses = $expected;
|
|
|
|
parent::__construct(sprintf(
|
|
'Offer #%d hat status=%s, Aktion „%s" erfordert status ∈ {%s}.',
|
|
$offer->id,
|
|
$offer->status,
|
|
$action,
|
|
implode(', ', $expected)
|
|
));
|
|
}
|
|
}
|