1 <?php
2
3 /*
4 * This file is part of the Brickrouge package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Brickrouge;
13
14 /**
15 * Indicates that instances can be rendered into an safe HTML string.
16 */
17 interface HTMLStringInterface
18 {
19 public function __toString();
20 }
21
22 /**
23 * Representation of an HTML string.
24 *
25 * An HTML string is considered safe to use and is not escaped after it has been rendered.
26 */
27 class HTMLString implements HTMLStringInterface
28 {
29 protected $html;
30
31 public function __construct($html)
32 {
33 $this->html = $html;
34 }
35
36 public function render()
37 {
38 return $this->html;
39 }
40
41 public function __toString()
42 {
43 try
44 {
45 return (string) $this->render();
46 }
47 catch (\Exception $e)
48 {
49 return render_exception($e);
50 }
51 }
52 }