-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCursorIsInvalid.php
More file actions
38 lines (31 loc) · 1.35 KB
/
Copy pathCursorIsInvalid.php
File metadata and controls
38 lines (31 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace TinyBlocks\HttpQuery\Exceptions;
use InvalidArgumentException;
use Throwable;
/**
* Raised when an opaque cursor token cannot be decoded back into its ordering key values.
*
* A cursor token is produced by the library and must round-trip through its codec. A token that
* was truncated, tampered with, or generated elsewhere fails to decode.
*/
final class CursorIsInvalid extends InvalidArgumentException implements HttpQueryException
{
private const string REASON_TEMPLATE = 'Cursor token <%s> is invalid and could not be decoded.';
private function __construct(string $token, ?Throwable $previous)
{
$template = CursorIsInvalid::REASON_TEMPLATE;
parent::__construct(message: sprintf($template, $token), previous: $previous);
}
/**
* Creates a CursorIsInvalid from the offending token and the optional underlying cause.
*
* @param string $token The opaque cursor token that could not be decoded.
* @param Throwable|null $previous The underlying decoding failure preserved in the chain, if any.
* @return CursorIsInvalid The composed exception describing the invalid cursor token.
*/
public static function from(string $token, ?Throwable $previous = null): CursorIsInvalid
{
return new CursorIsInvalid(token: $token, previous: $previous);
}
}