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

## Source for file php.php

Documentation is available at php.php

1. <?php
2. /**
3. * File containing the ezcMvcPhpViewHandler 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 view handler that uses PHP files to render result objects.
30. *
31. * @package MvcTools
32. * @version //autogentag//
33. * @mainclass
34. */
35. class ezcMvcPhpViewHandler implements ezcMvcViewHandler
36. {
37. /**
38. * Contains the zone name
39. *
40. * @var string
41. */
42. protected $zoneName ;
44. /**
45. * Contains the result after process() has been called.
46. *
47. * @var mixed
48. */
49. protected $result ;
51. /**
52. * Contains the variables that will be available in the template.
53. *
54. * @var array(mixed)
55. */
56. protected $variables = array();
58. /**
59. * Contains the path to the template file.
60. *
61. * @var string
62. */
63. protected $templateLocation ;
65. /**
66. * Creates a new view handler, where $zoneName is the name of the block and
67. * $templateLocation the location of a view template.
68. *
69. * @param string $zoneName
70. * @param string $templateLocation
71. */
72. public function __construct ( $zoneName, $templateLocation = null )
73. {
74. $this-> zoneName = $zoneName;
75. $this-> templateLocation = $templateLocation;
76. }
78. /**
79. * Adds a variable to the template, which can then be used for rendering
80. * the view.
81. *
82. * @param string $name
83. * @param mixed $value
84. */
85. public function send ( $name, $value )
86. {
87. $this-> variables [$name] = $value;
88. }
90. /**
91. * Processes the template with the variables added by the send() method.
92. * The result of this action should be retrievable through the getResult() method.
93. *
94. * The $last parameter is set if the view handler is the last one in the
95. * list of zones for a specific view.
96. *
97. * @param bool $last
98. */
99. public function process ( $last )
100. {
101. if ( ! file_exists ( $this-> templateLocation ) )
102. {
103. $fileName = ezcBaseFile :: isAbsolutePath ( $this-> templateLocation ) ? $this-> templateLocation : getcwd () . DIRECTORY_SEPARATOR . $this-> templateLocation ;
104. throw new ezcBaseFileNotFoundException ( $fileName, 'php template' );
105. }
106. ob_start ();
107. include $this-> templateLocation ;
108. $this-> result = ob_get_contents ();
109. ob_end_clean ();
110. }
112. /**
113. * Returns the value of the property $name.
114. *
115. * @throws ezcBasePropertyNotFoundException if the property does not exist.
116. * @param string $name
117. * @ignore
118. */
119. public function __get( $name )
120. {
121. return $this-> variables [$name];
122. }
124. /**
125. * Returns true if the property $name is set, otherwise false.
126. *
127. * @param string $name
128. * @return bool
129. * @ignore
130. */
131. public function __isset( $name )
132. {
133. return array_key_exists ( $name, $this-> variables );
134. }
136. /**
137. * Returns the name of the template, as set in the constructor.
138. *
139. * @return string
140. */
141. public function getName ()
142. {
143. return $this-> zoneName ;
144. }
146. /**
147. * Returns the result of the process() method.
148. *
149. * @return mixed
150. */
151. public function getResult ()
152. {
153. return $this-> result ;
154. }
155. }
156. ?>

Documentation generated by phpDocumentor 1.4.3