## Apache Zeta Components Manual :: File Source for view.php

## Source for file view.php

Documentation is available at view.php

1. <?php
2. /**
3. * File containing the ezcMvcView class
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
23. * @version //autogentag//
24. * @filesource
25. * @package MvcTools
26. */
28. /**
29. * The abstract view that you need to inherit from to supply your view zones.
30. *
31. * @package MvcTools
32. * @version //autogentag//
33. * @mainclass
34. */
35. abstract class ezcMvcView
36. {
37. /**
38. * Holds the request object
39. *
40. * @var ezcMvcRequest
41. */
42. protected $request ;
44. /**
45. * Holds the result object, that's the result of all the views.
46. *
47. * @var ezcMvcResult
48. */
49. protected $result ;
51. /**
52. * Creates the view object
53. *
54. * @param ezcMvcRequest $request
55. * @param ezcMvcResult $result
56. */
57. public function __construct ( ezcMvcRequest $request, ezcMvcResult $result )
58. {
59. $this-> request = $request;
60. $this-> result = $result;
61. }
63. /**
64. * The user-implemented that returns the zones.
65. *
66. * This method creates all the zones that are needed to render a view. A
67. * zone is an array of elements that implement a view handler. The view
68. * handlers do not have to be of the same type, as long as they implement
69. * the ezcMvcViewHandler interface.
70. *
71. * The $layout parameter can be used to determine whether a "page layout" should
72. * be added to the list of zones. This can be useful in case you're incorporating
73. * many different applications. The $layout parameter will be set to true automatically
74. * for the top level createZones() method, which can then chose to add zones from
75. * other views as well. The createZones() methods from those other views should
76. * have the $layout parameter set to false.
77. *
78. * @param bool $layout
79. *
80. * @return array(ezcMvcViewHandler)
81. */
82. abstract public function createZones ( $layout );
84. /**
85. * Creates a controller from the set of routes.
86. *
87. * This method is run by the createResponse() method to obtain a rendered
88. * result from data from the controller. It uses the user implemented
89. * createZones() method from the inherited class to fetch the different
90. * zones of the view, and then loops over these zones in order. Each zone's
91. * results are made available to subsequent zones. Each zone will be
92. * processed by a view handler of the ezcMvcViewHandler class.
93. *
94. * @throws ezcMvcNoZonesException when there are no zones defined.
95. * @throws ezcBaseValueException when one of the returned zones was not
96. * actually an object implementing the ezcMvcViewHandler interface.
97. * @return mixed
98. */
99. protected function createResponseBody ()
100. {
101. $processed = array();
102. $zones = $this-> createZones ( true );
103. if ( ezcBase :: inDevMode () && ( ! is_array ( $zones ) || ! count ( $zones ) ) )
104. {
105. throw new ezcMvcNoZonesException ();
106. }
108. // get the last zone
109. $lastZone = array_pop ( $zones );
110. array_push ( $zones, $lastZone );
112. foreach ( $zones as $zone )
113. {
114. if ( ezcBase :: inDevMode () && !$zone instanceof ezcMvcViewHandler )
115. {
116. throw new ezcBaseValueException ( 'zone', $zone, 'instance of ezcMvcViewHandler' );
117. }
119. // Get the variables returned by the controller for the view
120. foreach ( $this-> result -> variables as $propertyName => $propertyValue )
121. {
122. // Send it verbatim to the template processor
123. $zone->send( $propertyName, $propertyValue );
124. }
126. // Zones are additional templates that the final view should be built
127. // with. The main page layout is the last zone returned from
128. // createZones() method.
129. foreach ( $processed as $processedZone )
130. {
131. $zone->send( $processedZone->getName(), $processedZone->getResult() );
132. }
134. $zone->process( $zone === $lastZone );
136. $processed[] = $zone;
137. }
138. return $zone->getResult();
139. }
141. /**
142. * This method is called from the dispatched to create the rendered response from
143. * the controller's result.
144. *
145. * It calls the createResponseBody() to do the actual rendering. If any exception
146. * is thrown in any of the view handlers, this method catches it and returns that
147. * exception object to the dispatcher. The dispatcher must therefore check whether
148. * an exception object was returned. In case there was an exception, the dispatcher
149. * can take appropriate actions such as rendering a fatal error template.
150. *
151. * If everything goes well, this method returns an ezcMvcResponse object with the
152. * headers from the $result, and the response body from the processed views.
153. *
154. * @return ezcMvcResponse
155. */
156. public function createResponse ()
157. {
158. $resultBody = $this-> createResponseBody ();
159. $result = $this-> result ;
160. return new ezcMvcResponse ( $result->status, $result->date,
161. $result->generator, $result->cache, $result->cookies,
162. $result->content, $resultBody );
163. }
164. }
165. ?>

Documentation generated by phpDocumentor 1.4.3