| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Data\Type; |
| 6: | |
| 7: | class LocalObjectHandle |
| 8: | { |
| 9: | private int $localUid; |
| 10: | |
| 11: | |
| 12: | private \WeakReference $weakValue; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | private \Closure $destructFx; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | public function __construct(int $localUid, object $value, \Closure $destructFx) |
| 23: | { |
| 24: | $this->localUid = $localUid; |
| 25: | $this->weakValue = \WeakReference::create($value); |
| 26: | $this->destructFx = $destructFx; |
| 27: | } |
| 28: | |
| 29: | public function __destruct() |
| 30: | { |
| 31: | ($this->destructFx)($this); |
| 32: | } |
| 33: | |
| 34: | public function getLocalUid(): int |
| 35: | { |
| 36: | return $this->localUid; |
| 37: | } |
| 38: | |
| 39: | public function getValue(): ?object |
| 40: | { |
| 41: | return $this->weakValue->get(); |
| 42: | } |
| 43: | } |
| 44: | |