39 lines
858 B
PHP
39 lines
858 B
PHP
<?php
|
|
|
|
namespace Domains\Platform\Exceptions;
|
|
|
|
use Domains\Platform\Enums\PlatformEnum;
|
|
use Domains\Article\Models\Article;
|
|
use Exception;
|
|
use Throwable;
|
|
|
|
class PublishException extends Exception
|
|
{
|
|
public function __construct(
|
|
private readonly Article $article,
|
|
private readonly PlatformEnum|null $platform,
|
|
?Throwable $previous = null
|
|
) {
|
|
$message = "Failed to publish article #$article->id";
|
|
|
|
if ($this->platform) {
|
|
$message .= " to $platform->value";
|
|
}
|
|
|
|
if ($previous) {
|
|
$message .= ": {$previous->getMessage()}";
|
|
}
|
|
|
|
parent::__construct($message, 0, $previous);
|
|
}
|
|
|
|
public function getArticle(): Article
|
|
{
|
|
return $this->article;
|
|
}
|
|
|
|
public function getPlatform(): ?PlatformEnum
|
|
{
|
|
return $this->platform;
|
|
}
|
|
}
|