-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderClient.php
More file actions
138 lines (132 loc) · 3.94 KB
/
Copy pathRenderClient.php
File metadata and controls
138 lines (132 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php declare(strict_types=1);
namespace Computator\FrameworkUtils\PHPTemplate\UserApi;
use Computator\FrameworkUtils\PHPTemplate\TemplateResolver;
use Computator\FrameworkUtils\PHPTemplate\Templates;
/**
* User-visible interface to a `Renderer`.
*
* These are the available methods intended for public use to configure and use
* a `Renderer`.
*
* Note that `Renderer` instances have additional public methods meant for
* internal use to control the rendering process (defined by the `RenderManager`
* interface), but these methods are not intended for use by end-users.
*
* @see Computator\FrameworkUtils\PHPTemplate\Renderer
* @see RenderManager
*/
interface RenderClient {
/**
* Create a new `Renderer`.
*
* This method is used to create a new `Renderer` (as a `RenderClient`) bound
* to the provided template.
*
* # Example
*
* ```php
* <?php
* $resolver = new TemplateResolver(
* // This is the class used to instantiate new templates.
* // In this case, `Templates\File` is the default so it
* // could also be left unspecified.
* Templates\File::class
* );
* $renderclient = Renderer::create(new Templates\File('main.php'), $resolver);
* ```
*
* @param Templates\Base $template The root template that the rendering process will start at.
*
* @param TemplateResolver $resolver (optional) The `TemplateResolver` that will be used to
* resolve additional template names referenced during
* the rendering process.
*/
public static function create(Templates\Base $template, TemplateResolver $resolver): RenderClient;
/**
* Set context to render the root template with.
*
* This method is used to set the data that the root template will be rendered
* with. Every call replaces any previous data and the template is rendered
* with the latest specified data.
*
* # Example
*
* ```php
* <?php
* // Example user
* $user = ['id' => 3, 'first' => "User", 'last' => "Name"];
*
* $renderclient = Renderer::create(new Templates\File('profile.php'));
* $renderclient->with(
* $user,
* message: "This is a profile message.",
* )->render();
* ```
*
* # Data Formats
*
* This method accepts data in multiple formats:
* - Named parameters
* - Parameter arrays
* - A mix of named parameters and arrays
*
* ## Named Parameters
*
* ```php
* <?php
* $renderclient->with(key1: "value1", key2: "value2", key3: 3)
* ```
*
* ## Parameter Arrays
*
* ```php
* <?php
* $renderclient->with(['key1' => "value1", 'key2' => "value2", 'key3' => 3])
* ```
*
* ```php
* <?php
* $data1 = ['key1' => "value1", 'key2' => "value2"];
* $data2 = ['key3' => "value3", 'key4' => 4];
* $renderclient->with($data1, $data2)
* ```
*
* ## Mixed
*
* ```php
* <?php
* $data = ['key3' => "value3", 'key4' => 4];
* $renderclient->with($data, key1: "value1", key2: "value2")
* ```
*
* @return $this Chains to self
*/
public function with(mixed ...$context): self;
/**
* Execute the rendering process.
*
* This method will render the base template and any templates referenced by
* it and output the rendered content directly.
*
* The base template will be rendered with any context data set by `with()`.
*
* @see RenderClient::with() Set the context for rendering
* @see RenderClient::renderToString() Alternative method to render to a string
*/
public function render(): void;
/**
* Execute the rendering process.
*
* This method will render the base template and any templates referenced by
* it and return the rendered content as a string. This method does not
* have any output.
*
* The base template will be rendered with any context data set by `with()`.
*
* @return string The rendered content
*
* @see RenderClient::with() Set the context for rendering
* @see RenderClient::render() Alternative method to output directly
*/
public function renderToString(): string;
}