These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
2 | /** |
||
3 | * Ion |
||
4 | * |
||
5 | * Building blocks for web development |
||
6 | * |
||
7 | * @package Ion |
||
8 | * @author Timothy J. Warren |
||
9 | * @copyright Copyright (c) 2015 - 2016 |
||
10 | * @license MIT |
||
11 | */ |
||
12 | |||
13 | namespace Aviat\Ion; |
||
14 | |||
15 | use Aviat\Ion\Di\ContainerInterface; |
||
16 | use Aviat\Ion\Type\StringType; |
||
17 | |||
18 | /** |
||
19 | * Base view response class |
||
20 | */ |
||
21 | abstract class View { |
||
22 | |||
23 | use Di\ContainerAware; |
||
24 | use \Aviat\Ion\StringWrapper; |
||
25 | |||
26 | /** |
||
27 | * HTTP response Object |
||
28 | * |
||
29 | * @var Aura\Web\Response |
||
30 | */ |
||
31 | protected $response; |
||
32 | |||
33 | /** |
||
34 | * Response mime type |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $contentType = ''; |
||
39 | |||
40 | /** |
||
41 | * String of response to be output |
||
42 | * |
||
43 | * @var StringType |
||
44 | */ |
||
45 | protected $output; |
||
46 | |||
47 | /** |
||
48 | * If the view has sent output via |
||
49 | * __toString or send method |
||
50 | * |
||
51 | * @var boolean |
||
52 | */ |
||
53 | protected $hasRendered = FALSE; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | * |
||
58 | * @param ContainerInterface $container |
||
59 | */ |
||
60 | public function __construct(ContainerInterface $container) |
||
61 | { |
||
62 | $this->setContainer($container); |
||
63 | $this->response = $container->get('response'); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Send output to client |
||
68 | */ |
||
69 | public function __destruct() |
||
70 | { |
||
71 | if ( ! $this->hasRendered) |
||
72 | { |
||
73 | $this->send(); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Return rendered output |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function __toString() |
||
83 | { |
||
84 | $this->hasRendered = TRUE; |
||
85 | return $this->getOutput(); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Set the output string |
||
90 | * |
||
91 | * @param string $string |
||
92 | * @return View |
||
93 | */ |
||
94 | public function setOutput($string) |
||
95 | { |
||
96 | $this->output = $this->string($string); |
||
97 | |||
98 | return $this; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Append additional output |
||
103 | * |
||
104 | * @param string $string |
||
105 | * @return View |
||
106 | */ |
||
107 | public function appendOutput($string) |
||
108 | { |
||
109 | $this->output = $this->string($this->output)->append($string); |
||
110 | |||
111 | return $this; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get the current output string |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getOutput() |
||
120 | { |
||
121 | return $this->string($this->output)->__toString(); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Send output to client |
||
126 | */ |
||
127 | abstract public function send(); |
||
0 ignored issues
–
show
For interfaces and abstract methods it is generally a good practice to add a
@return annotation even if it is just @return void or @return null , so that implementors know what to do in the overridden method.
For interface and abstract methods, it is impossible to infer the return type
from the immediate code. In these cases, it is generally advisible to explicitly
annotate these methods with a
Loading history...
|
|||
128 | } |
||
129 | // End of View.php |