| 1: | <?php |
| 2: | /* |
| 3: | * SimpleID |
| 4: | * |
| 5: | * Copyright (C) Kelvin Mo 2021-2025 |
| 6: | * |
| 7: | * This program is free software; you can redistribute it and/or |
| 8: | * modify it under the terms of the GNU General Public |
| 9: | * License as published by the Free Software Foundation; either |
| 10: | * version 2 of the License, or (at your option) any later version. |
| 11: | * |
| 12: | * This program is distributed in the hope that it will be useful, |
| 13: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15: | * General Public License for more details. |
| 16: | * |
| 17: | * You should have received a copy of the GNU General Public |
| 18: | * License along with this program; if not, write to the Free |
| 19: | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20: | * |
| 21: | */ |
| 22: | |
| 23: | namespace SimpleID\Util\Events; |
| 24: | |
| 25: | use SimpleID\Util\UI\AttachmentManagerInterface; |
| 26: | use SimpleID\Util\UI\UIBuilder; |
| 27: | use SimpleID\Util\UI\UIBuilderInterface; |
| 28: | |
| 29: | /** |
| 30: | * A generic event used to build user interfaces. |
| 31: | * |
| 32: | * This event is created along with a UIBuilder. The methods from the |
| 33: | * UIBuilderInterface are delegated to the attached UIBuilder. |
| 34: | * |
| 35: | * @see SimpleID\Util\UI\UIBuilder |
| 36: | */ |
| 37: | class UIBuildEvent extends BaseEvent implements \GenericEventInterface, UIBuilderInterface { |
| 38: | use GenericEventTrait; |
| 39: | |
| 40: | /** @var \SimpleID\Util\UI\UIBuilder */ |
| 41: | protected $builder; |
| 42: | |
| 43: | /** |
| 44: | * Creates a UI build event |
| 45: | * |
| 46: | * @param string $eventName the name of the event, or the name |
| 47: | */ |
| 48: | public function __construct($eventName = null) { |
| 49: | $this->setEventName($eventName); |
| 50: | $this->builder = new UIBuilder(); |
| 51: | } |
| 52: | |
| 53: | /** |
| 54: | * Returns the UIBuilder for this event |
| 55: | * |
| 56: | * @return \SimpleID\Util\UI\UIBuilder |
| 57: | */ |
| 58: | public function getUIBuilder() { |
| 59: | return $this->builder; |
| 60: | } |
| 61: | |
| 62: | /** |
| 63: | * {@inheritdoc} |
| 64: | */ |
| 65: | public function addBlock(string $id, string $content, int $weight = 0, array $additional = []): UIBuildEvent { |
| 66: | $this->builder->addBlock($id, $content, $weight, $additional); |
| 67: | return $this; |
| 68: | } |
| 69: | |
| 70: | /** |
| 71: | * {@inheritdoc} |
| 72: | */ |
| 73: | public function merge(UIBuilderInterface $builder) { |
| 74: | return $this->builder->merge($builder); |
| 75: | } |
| 76: | |
| 77: | /** |
| 78: | * {@inheritdoc} |
| 79: | */ |
| 80: | public function getBlocks(): array { |
| 81: | return $this->builder->getBlocks(); |
| 82: | } |
| 83: | |
| 84: | /** |
| 85: | * {@inheritdoc} |
| 86: | */ |
| 87: | public function getBlockData(): array { |
| 88: | return $this->builder->getBlockData(); |
| 89: | } |
| 90: | |
| 91: | /** |
| 92: | * {@inheritdoc} |
| 93: | */ |
| 94: | public function addAttachment(string $attachment_type, array $data): AttachmentManagerInterface { |
| 95: | return $this->builder->addAttachment($attachment_type, $data); |
| 96: | } |
| 97: | |
| 98: | /** |
| 99: | * {@inheritdoc} |
| 100: | */ |
| 101: | public function getAttachments(): array { |
| 102: | return $this->builder->getAttachments(); |
| 103: | } |
| 104: | |
| 105: | /** |
| 106: | * {@inheritdoc} |
| 107: | */ |
| 108: | public function getAttachmentTypes(): array { |
| 109: | return $this->builder->getAttachmentTypes(); |
| 110: | } |
| 111: | |
| 112: | /** |
| 113: | * {@inheritdoc} |
| 114: | */ |
| 115: | public function getAttachmentsByType(string $attachment_type) { |
| 116: | return $this->builder->getAttachmentsByType($attachment_type); |
| 117: | } |
| 118: | |
| 119: | /** |
| 120: | * {@inheritdoc} |
| 121: | */ |
| 122: | public function reset() { |
| 123: | $this->builder->reset(); |
| 124: | } |
| 125: | } |
| 126: | |
| 127: | ?> |