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 declare(strict_types=1); |
| 2 | |
| 3 | namespace Computator\FrameworkUtils\PHPTemplate\UserApi; |
| 4 | |
| 5 | /** |
| 6 | * Template object reference methods available in templates. |
| 7 | * |
| 8 | * These methods are available on objects retrieved using `self::tpl()`. |
| 9 | */ |
| 10 | interface ResolvedTemplateClient { |
| 11 | /** |
| 12 | * Set context to render the template with. |
| 13 | * |
| 14 | * This method is used to set the data that the template will be rendered |
| 15 | * with. Every call replaces any previous data so that the template can be |
| 16 | * rendered repeatedly with different values. |
| 17 | * |
| 18 | * # Example |
| 19 | * |
| 20 | * ```php |
| 21 | * <?php |
| 22 | * // Example user |
| 23 | * $user = ['id' => 3, 'first' => "User", 'last' => "Name"]; |
| 24 | * ?> |
| 25 | * |
| 26 | * <div class="comment-list"> |
| 27 | * <? self::tpl('comment.php')->with( |
| 28 | * $user, |
| 29 | * text: "This is a comment.", |
| 30 | * )() ?> |
| 31 | * </div> |
| 32 | * ``` |
| 33 | * |
| 34 | * # Data Formats |
| 35 | * |
| 36 | * This method accepts data in multiple formats: |
| 37 | * - Named parameters |
| 38 | * - Parameter arrays |
| 39 | * - A mix of named parameters and arrays |
| 40 | * |
| 41 | * ## Named Parameters |
| 42 | * |
| 43 | * ```php |
| 44 | * <?php |
| 45 | * $t->with(key1: "value1", key2: "value2", key3: 3) |
| 46 | * ``` |
| 47 | * |
| 48 | * ## Parameter Arrays |
| 49 | * |
| 50 | * ```php |
| 51 | * <?php |
| 52 | * $t->with(['key1' => "value1", 'key2' => "value2", 'key3' => 3]) |
| 53 | * ``` |
| 54 | * |
| 55 | * ```php |
| 56 | * <?php |
| 57 | * $data1 = ['key1' => "value1", 'key2' => "value2"]; |
| 58 | * $data2 = ['key3' => "value3", 'key4' => 4]; |
| 59 | * $t->with($data1, $data2) |
| 60 | * ``` |
| 61 | * |
| 62 | * ## Mixed |
| 63 | * |
| 64 | * ```php |
| 65 | * <?php |
| 66 | * $data = ['key3' => "value3", 'key4' => 4]; |
| 67 | * $t->with($data, key1: "value1", key2: "value2") |
| 68 | * ``` |
| 69 | * |
| 70 | * @return $this Chains to self |
| 71 | */ |
| 72 | public function with(mixed ...$context): self; |
| 73 | |
| 74 | /** |
| 75 | * Render the template. |
| 76 | * |
| 77 | * Invoking the template object reference by calling it as a function will |
| 78 | * render the template with the current context data. |
| 79 | * |
| 80 | * # Example |
| 81 | * |
| 82 | * ```php |
| 83 | * <? self::tpl('child.php')() ?> |
| 84 | * ``` |
| 85 | */ |
| 86 | public function __invoke(): void; |
| 87 | } |