AbstractFactory.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Analyst\Core; |
| 4 | |
| 5 | abstract class AbstractFactory |
| 6 | { |
| 7 | /** |
| 8 | * Unserialize to static::class instance |
| 9 | * |
| 10 | * @param $raw |
| 11 | * @return static |
| 12 | */ |
| 13 | protected static function unserialize($raw) |
| 14 | { |
| 15 | $instance = maybe_unserialize($raw); |
| 16 | |
| 17 | $isProperObject = is_object($instance) && $instance instanceof static; |
| 18 | |
| 19 | // In case for some reason unserialized object is not |
| 20 | // static::class we make sure it is static::class |
| 21 | if (!$isProperObject) { |
| 22 | $instance = new static(); |
| 23 | } |
| 24 | |
| 25 | return $instance; |
| 26 | } |
| 27 | } |
| 28 |