37 lines
983 B
PHP
37 lines
983 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Support\Publishing;
|
||
|
|
|
||
|
|
final class PublishResult
|
||
|
|
{
|
||
|
|
private function __construct(
|
||
|
|
public readonly bool $success,
|
||
|
|
public readonly bool $attempted,
|
||
|
|
public readonly ?string $url = null,
|
||
|
|
public readonly ?string $error = null,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
public static function success(string $url): self
|
||
|
|
{
|
||
|
|
return new self(success: true, attempted: true, url: $url);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The publish attempt itself failed (network, API error, etc).
|
||
|
|
*/
|
||
|
|
public static function failed(string $error): self
|
||
|
|
{
|
||
|
|
return new self(success: false, attempted: true, error: $error);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* A precondition wasn't met — no attempt was made (bad data, missing
|
||
|
|
* credentials, wrong type). Callers should not treat this the same as
|
||
|
|
* a failed attempt.
|
||
|
|
*/
|
||
|
|
public static function rejected(string $error): self
|
||
|
|
{
|
||
|
|
return new self(success: false, attempted: false, error: $error);
|
||
|
|
}
|
||
|
|
}
|