| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | use Atk4\Core\AppScopeTrait; |
| 8: | use Atk4\Core\ContainerTrait; |
| 9: | use Atk4\Core\InitializerTrait; |
| 10: | use Atk4\Core\NameTrait; |
| 11: | use Atk4\Core\StaticAddToTrait; |
| 12: | use Atk4\Core\TrackableTrait; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | abstract class AbstractView |
| 22: | { |
| 23: | use AppScopeTrait; |
| 24: | use ContainerTrait { |
| 25: | add as private _add; |
| 26: | } |
| 27: | use InitializerTrait { |
| 28: | init as private _init; |
| 29: | } |
| 30: | use NameTrait; |
| 31: | use StaticAddToTrait; |
| 32: | use TrackableTrait; |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | protected ?array $_addLater = []; |
| 43: | |
| 44: | |
| 45: | protected bool $_rendered = false; |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | protected function init(): void |
| 52: | { |
| 53: | if ($this->name === null) { |
| 54: | $this->name = 'atk'; |
| 55: | } |
| 56: | |
| 57: | $this->_init(); |
| 58: | |
| 59: | if ($this->_addLater !== null) { |
| 60: | foreach ($this->_addLater as [$object, $args]) { |
| 61: | $this->add($object, $args); |
| 62: | } |
| 63: | $this->_addLater = null; |
| 64: | } |
| 65: | } |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | public function add(self $object, array $args = []): self |
| 71: | { |
| 72: | if ($this->_rendered) { |
| 73: | throw new Exception('You cannot add anything into the view after it was rendered'); |
| 74: | } |
| 75: | |
| 76: | if (!$this->issetApp()) { |
| 77: | $this->_addLater[] = [$object, $args]; |
| 78: | |
| 79: | return $object; |
| 80: | } |
| 81: | |
| 82: | |
| 83: | $this->_add($object, $args); |
| 84: | |
| 85: | return $object; |
| 86: | } |
| 87: | } |
| 88: | |