1 | <?php |
||
9 | class NonDeserialisableObject extends LogicException implements ExceptionInterface |
||
10 | { |
||
11 | private const ERROR_TEMPLATE = <<<'ERROR' |
||
|
|||
12 | The given object %s#%s is not designed to be deserialised, yet deserialisation was attempted. |
||
13 | |||
14 | This error is raised because the author of %s didn't design it to be deserialisable, nor can |
||
15 | guarantee that it will function correctly after deserialisation, nor can guarantee that all |
||
16 | its internal components are deserialisable. |
||
17 | |||
18 | Please do not use unserialize() to produce %s instances. |
||
19 | ERROR; |
||
20 | |||
21 | public static function fromAttemptedDeSerialisation($object) : self |
||
22 | { |
||
23 | if (! is_object($object)) { |
||
24 | throw TypeError::fromNonObject($object); |
||
25 | } |
||
26 | |||
27 | $className = get_class($object); |
||
28 | |||
29 | return new self(sprintf( |
||
30 | self::ERROR_TEMPLATE, |
||
31 | $className, |
||
32 | spl_object_hash($object), |
||
33 | $className, |
||
34 | $className |
||
35 | )); |
||
36 | } |
||
37 | } |
||
38 |