| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Core; |
| 6: | |
| 7: | /** |
| 8: | * Object wrapper with __debugInfo() method mapped to __debugInfoQuiet(). |
| 9: | * |
| 10: | * @template-covariant T of object |
| 11: | */ |
| 12: | class QuietObjectWrapper |
| 13: | { |
| 14: | /** @var T */ |
| 15: | private object $obj; |
| 16: | |
| 17: | /** |
| 18: | * @param T $obj |
| 19: | */ |
| 20: | public function __construct(object $obj) |
| 21: | { |
| 22: | $this->obj = $obj; |
| 23: | } |
| 24: | |
| 25: | private function __clone() |
| 26: | { |
| 27: | // prevent cloning |
| 28: | } |
| 29: | |
| 30: | public function __sleep(): array |
| 31: | { |
| 32: | throw new Exception('Serialization is not supported'); |
| 33: | } |
| 34: | |
| 35: | /** |
| 36: | * @return T |
| 37: | */ |
| 38: | public function get(): object |
| 39: | { |
| 40: | return $this->obj; |
| 41: | } |
| 42: | |
| 43: | /** |
| 44: | * @return array<string, mixed> |
| 45: | */ |
| 46: | public function __debugInfo(): array |
| 47: | { |
| 48: | $obj = $this->obj; |
| 49: | |
| 50: | $res = ['wrappedClass' => get_debug_type($obj)]; |
| 51: | if (method_exists($obj, '__debugInfoQuiet')) { |
| 52: | $res = array_merge($res, $obj->__debugInfoQuiet()); |
| 53: | } |
| 54: | |
| 55: | return $res; |
| 56: | } |
| 57: | } |
| 58: |