Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro; |
| 4 | |
| 5 | /** |
| 6 | * Template processor |
| 7 | * |
| 8 | * This class is used for server side HTML rendering with the help of PHP. |
| 9 | */ |
| 10 | interface ViewInterface { |
| 11 | /** |
| 12 | * Returns with a view variable value by name |
| 13 | */ |
| 14 | public function get(string $name, mixed $default = null): mixed; |
| 15 | |
| 16 | /** |
| 17 | * Sets a view variable |
| 18 | */ |
| 19 | public function set(string $name, mixed $value): void; |
| 20 | |
| 21 | /** |
| 22 | * Adds a script for the view |
| 23 | */ |
| 24 | public function addScript(string $src, array $attributes = []): void; |
| 25 | |
| 26 | /** |
| 27 | * Returns with the scripts in [src => [attributes]] array |
| 28 | */ |
| 29 | public function scripts(): array; |
| 30 | |
| 31 | /** |
| 32 | * Adds a style for the view |
| 33 | */ |
| 34 | public function addStyle(string $src, array $attributes = []): void; |
| 35 | |
| 36 | /** |
| 37 | * Returns with the styles in [src => [attributes]] array |
| 38 | */ |
| 39 | public function styles(): array; |
| 40 | |
| 41 | /** |
| 42 | * Sets the layout so after the template was rendered it will render this layout. |
| 43 | * The path can contain a namespace if a folder was added with that namespace, for example: |
| 44 | * |
| 45 | * <pre> |
| 46 | * $view->addFolder('folder', 'views/example'); |
| 47 | * $view->useLayout('folder:layout'); |
| 48 | * </pre> |
| 49 | * |
| 50 | * will render the 'views/example/layout.phtml'. |
| 51 | */ |
| 52 | public function useLayout(string $path): void; |
| 53 | |
| 54 | /** |
| 55 | * Returns with the current layout |
| 56 | */ |
| 57 | public function layout(): string; |
| 58 | |
| 59 | /** |
| 60 | * Returns with the content of a block |
| 61 | */ |
| 62 | public function block(string $name): string; |
| 63 | |
| 64 | /** |
| 65 | * Starts a block |
| 66 | * |
| 67 | * If the block has content, when the endBlock() will be called the content will be appended to the block. |
| 68 | */ |
| 69 | public function startBlock(string $name): void; |
| 70 | |
| 71 | /** |
| 72 | * Ends a block |
| 73 | * |
| 74 | * If the block has content, the new content will be appended to the block. |
| 75 | */ |
| 76 | public function endBlock(): void; |
| 77 | |
| 78 | /** |
| 79 | * Adds a view folder |
| 80 | * |
| 81 | * For example, if the `app.root_path` config value is '/var/www/example.com', and you have the following code: |
| 82 | * |
| 83 | * <pre> |
| 84 | * $view->addFolder('folder', '~/views/example'); |
| 85 | * $view->fetch('folder:index'); |
| 86 | * </pre> |
| 87 | * |
| 88 | * will fetch the '/var/www/example.com/views/example/index.phtml'. |
| 89 | * |
| 90 | * The `$path` should NOT end with a '/' |
| 91 | */ |
| 92 | public function addFolder(string $namespace, string $path): void; |
| 93 | |
| 94 | /** |
| 95 | * Returns with the folder path by namespace |
| 96 | */ |
| 97 | public function folder(string $namespace): string; |
| 98 | |
| 99 | /** |
| 100 | * Sets the theme path for overriding templates |
| 101 | */ |
| 102 | public function setTheme(string $path): void; |
| 103 | |
| 104 | /** |
| 105 | * Returns with the theme path |
| 106 | */ |
| 107 | public function theme(): string; |
| 108 | |
| 109 | /** |
| 110 | * Fetches a template with variables |
| 111 | */ |
| 112 | public function fetch(string $__viewPath, array $__vars = []): string; |
| 113 | } |