| 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 managing attachments. |
| 27: | * |
| 28: | * Attachments can be things such as CSS style sheets, Javascript |
| 29: | * references or Javascript code. Each attachment is associated |
| 30: | * with a type. |
| 31: | * |
| 32: | */ |
| 33: | interface AttachmentManagerInterface { |
| 34: | /** |
| 35: | * Constant specifying the attachment type for CSS stylesheets. |
| 36: | * |
| 37: | * The attachment should be specified as an array with one of the following keys: |
| 38: | * |
| 39: | * - inline: the css code to be emdedded |
| 40: | * - src: the path to the stylesheet |
| 41: | */ |
| 42: | const CSS_ATTACHMENT = 'css'; |
| 43: | |
| 44: | /** |
| 45: | * Constant specifying the attachment type for Javascript. |
| 46: | * |
| 47: | * The attachment should be specified as an array with one of inline or src, |
| 48: | * plus zero or more of the following keys: |
| 49: | * |
| 50: | * - inline: the Javascript code to be emdedded |
| 51: | * - src: the path to the script to load |
| 52: | * - defer: value of the defer attribute |
| 53: | * - async: value of the async attribute |
| 54: | * - type: value of the type attribute |
| 55: | */ |
| 56: | const JS_ATTACHMENT = 'js'; |
| 57: | |
| 58: | /** |
| 59: | * Adds an attachment. |
| 60: | * |
| 61: | * @param string $attachment_type the type of attachment |
| 62: | * @param array<mixed> $data the details of the attachment |
| 63: | * @return AttachmentManagerInterface |
| 64: | */ |
| 65: | public function addAttachment(string $attachment_type, array $data): AttachmentManagerInterface; |
| 66: | |
| 67: | /** |
| 68: | * Retrieves all the attachments. |
| 69: | * |
| 70: | * This function returns an array of all attachments, with the |
| 71: | * key being the attachment type, and the value an array of the |
| 72: | * attachment details. |
| 73: | * |
| 74: | * Note that the value array may contain duplicates. To filter |
| 75: | * for unique values, use the {@link getAttachmentsByType()} method. |
| 76: | * |
| 77: | * @return array<string, array<mixed>> the attachments |
| 78: | */ |
| 79: | public function getAttachments(): array; |
| 80: | |
| 81: | /** |
| 82: | * Returns an array of attachment types currently attached. |
| 83: | * |
| 84: | * @return array<string> |
| 85: | */ |
| 86: | public function getAttachmentTypes(): array; |
| 87: | |
| 88: | /** |
| 89: | * Returns the attachments of a particular type. |
| 90: | * |
| 91: | * Only unique elements are returned. |
| 92: | * |
| 93: | * @param string $attachment_type the attachment type |
| 94: | * @return array<array<mixed>> |
| 95: | */ |
| 96: | public function getAttachmentsByType(string $attachment_type); |
| 97: | } |
| 98: | |
| 99: | ?> |