|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YIKES Inc. Easy Forms. |
|
4
|
|
|
* |
|
5
|
|
|
* @package YIKES\EasyForms |
|
6
|
|
|
* @author Freddie Mixell |
|
7
|
|
|
* @license GPL2 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace YIKES\EasyForms\View; |
|
11
|
|
|
|
|
12
|
|
|
use YIKES\EasyForms\Exception\FailedToLoadView; |
|
13
|
|
|
use YIKES\EasyForms\Exception\InvalidURI; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class PostEscapedView. |
|
17
|
|
|
* |
|
18
|
|
|
* This is a Decorator that decorates a given View with escaping meant for |
|
19
|
|
|
* standard HTML post output. |
|
20
|
|
|
* |
|
21
|
|
|
* @since %VERSION% |
|
22
|
|
|
* |
|
23
|
|
|
* @package YIKES\EasyForms\View |
|
24
|
|
|
* @author Freddie Mixell |
|
25
|
|
|
*/ |
|
26
|
|
|
final class PostEscapedView implements View { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* View instance to decorate. |
|
30
|
|
|
* |
|
31
|
|
|
* @since %VERSION% |
|
32
|
|
|
* |
|
33
|
|
|
* @var View |
|
34
|
|
|
*/ |
|
35
|
|
|
private $view; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Instantiate a PostEscapedView object. |
|
39
|
|
|
* |
|
40
|
|
|
* @since %VERSION% |
|
41
|
|
|
* |
|
42
|
|
|
* @param View $view View instance to decorate. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( View $view ) { |
|
45
|
|
|
$this->view = $view; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Render a given URI. |
|
50
|
|
|
* |
|
51
|
|
|
* @since %VERSION% |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $context Context in which to render. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string Rendered HTML. |
|
56
|
|
|
* @throws FailedToLoadView If the View URI could not be loaded. |
|
57
|
|
|
*/ |
|
58
|
|
|
public function render( array $context = [] ) { |
|
59
|
|
|
return wp_kses_post( $this->view->render( $context ) ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Render a partial view. |
|
64
|
|
|
* |
|
65
|
|
|
* This can be used from within a currently rendered view, to include |
|
66
|
|
|
* nested partials. |
|
67
|
|
|
* |
|
68
|
|
|
* The passed-in context is optional, and will fall back to the parent's |
|
69
|
|
|
* context if omitted. |
|
70
|
|
|
* |
|
71
|
|
|
* @since %VERSION% |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $uri URI of the partial to render. |
|
74
|
|
|
* @param array|null $context Context in which to render the partial. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string Rendered HTML. |
|
77
|
|
|
* @throws InvalidURI If the provided URI was not valid. |
|
78
|
|
|
* @throws FailedToLoadView If the view could not be loaded. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function render_partial( $uri, array $context = null ) { |
|
81
|
|
|
return wp_kses_post( $this->view->render_partial( $uri, $context ) ); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|