| 1: | <?php |
| 2: | /* |
| 3: | * SimpleID |
| 4: | * |
| 5: | * Copyright (C) Kelvin Mo 2023-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\UI; |
| 24: | |
| 25: | /** |
| 26: | * Interface for building user interfaces. |
| 27: | * |
| 28: | * User interfaces built by adding "blocks" using the {@link addBlock()} |
| 29: | * method. A block is essentially a piece of HTML code that can be |
| 30: | * inserted in a particular order. |
| 31: | * |
| 32: | * In addition to blocks, attachments can also be added. Attachments |
| 33: | * can be things such as CSS style sheets, Javascript references or |
| 34: | * Javascript code. Each attachment is associated with a type. |
| 35: | * |
| 36: | */ |
| 37: | interface UIBuilderInterface extends AttachmentManagerInterface { |
| 38: | /** |
| 39: | * Adds a UI block. |
| 40: | * |
| 41: | * @param string $id the block ID |
| 42: | * @param string $content the contents |
| 43: | * @param int $weight the weight |
| 44: | * @param array<string, mixed> $additional additional data |
| 45: | * @return UIBuilderInterface |
| 46: | */ |
| 47: | public function addBlock(string $id, string $content, int $weight = 0, array $additional = []); |
| 48: | |
| 49: | /** |
| 50: | * Merges another UI builder into this builder. |
| 51: | * |
| 52: | * Blocks from the other builder are appended to this builder. |
| 53: | * Attachments from the other builder are also appended, while |
| 54: | * preserving the type. |
| 55: | * |
| 56: | * @param UIBuilderInterface $builder the builder to merge |
| 57: | * @return UIBuilderInterface |
| 58: | */ |
| 59: | public function merge(UIBuilderInterface $builder); |
| 60: | |
| 61: | /** |
| 62: | * Retrieves the blocks from the builder, ordered by the |
| 63: | * weight, from lowest to highest. |
| 64: | * |
| 65: | * @return array<array<mixed>> |
| 66: | */ |
| 67: | public function getBlocks(): array; |
| 68: | |
| 69: | /** |
| 70: | * Retrieves the raw block data stored in the builder. |
| 71: | * |
| 72: | * @return array<array<mixed>> |
| 73: | */ |
| 74: | public function getBlockData(): array; |
| 75: | |
| 76: | /** |
| 77: | * Resets the builder by removing all the blocks |
| 78: | * |
| 79: | * @return void |
| 80: | */ |
| 81: | public function reset(); |
| 82: | } |
| 83: | |
| 84: | ?> |