ViewScriptFile.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Tool
  17. * @subpackage Framework
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Tool_Project_Context_Filesystem_File
  24. */
  25. require_once 'Zend/Tool/Project/Context/Filesystem/File.php';
  26. /**
  27. * @see Zend_Filter
  28. */
  29. require_once 'Zend/Filter.php';
  30. /**
  31. * @see Zend_Filter_Word_CamelCaseToDash
  32. */
  33. require_once 'Zend/Filter/Word/CamelCaseToDash.php';
  34. /**
  35. * @see Zend_Filter_StringToLower
  36. */
  37. require_once 'Zend/Filter/StringToLower.php';
  38. /**
  39. * This class is the front most class for utilizing Zend_Tool_Project
  40. *
  41. * A profile is a hierarchical set of resources that keep track of
  42. * items within a specific project.
  43. *
  44. * @category Zend
  45. * @package Zend_Tool
  46. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  47. * @license http://framework.zend.com/license/new-bsd New BSD License
  48. */
  49. class Zend_Tool_Project_Context_Zf_ViewScriptFile extends Zend_Tool_Project_Context_Filesystem_File
  50. {
  51. /**
  52. * @var string
  53. */
  54. protected $_filesystemName = 'view.phtml';
  55. /**
  56. * @var string
  57. */
  58. protected $_forActionName = null;
  59. /**
  60. * @var string
  61. */
  62. protected $_scriptName = null;
  63. /**
  64. * getName()
  65. *
  66. * @return string
  67. */
  68. public function getName()
  69. {
  70. return 'ViewScriptFile';
  71. }
  72. /**
  73. * init()
  74. *
  75. * @return Zend_Tool_Project_Context_Zf_ViewScriptFile
  76. */
  77. public function init()
  78. {
  79. if ($forActionName = $this->_resource->getAttribute('forActionName')) {
  80. $this->_forActionName = $forActionName;
  81. $this->_filesystemName = $this->_convertActionNameToFilesystemName($forActionName) . '.phtml';
  82. } elseif ($scriptName = $this->_resource->getAttribute('scriptName')) {
  83. $this->_scriptName = $scriptName;
  84. $this->_filesystemName = $scriptName . '.phtml';
  85. } else {
  86. throw new Exception('Either a forActionName or scriptName is required.');
  87. }
  88. parent::init();
  89. return $this;
  90. }
  91. /**
  92. * getPersistentAttributes()
  93. *
  94. * @return unknown
  95. */
  96. public function getPersistentAttributes()
  97. {
  98. $attributes = array();
  99. if ($this->_forActionName) {
  100. $attributes['forActionName'] = $this->_forActionName;
  101. }
  102. if ($this->_scriptName) {
  103. $attributes['scriptName'] = $this->_scriptName;
  104. }
  105. return $attributes;
  106. }
  107. /**
  108. * getContents()
  109. *
  110. * @return string
  111. */
  112. public function getContents()
  113. {
  114. $contents = '';
  115. if ($this->_filesystemName == 'error.phtml') { // should also check that the above directory is forController=error
  116. $contents .= <<<EOS
  117. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  118. <html xmlns="http://www.w3.org/1999/xhtml">
  119. <head>
  120. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  121. <title>Zend Framework Default Application</title>
  122. </head>
  123. <body>
  124. <h1>An error occurred</h1>
  125. <h2><?php echo \$this->message ?></h2>
  126. <?php if (isset(\$this->exception)): ?>
  127. <h3>Exception information:</h3>
  128. <p>
  129. <b>Message:</b> <?php echo \$this->exception->getMessage() ?>
  130. </p>
  131. <h3>Stack trace:</h3>
  132. <pre><?php echo \$this->exception->getTraceAsString() ?>
  133. </pre>
  134. <h3>Request Parameters:</h3>
  135. <pre><?php echo var_export(\$this->request->getParams(), true) ?>
  136. </pre>
  137. <?php endif ?>
  138. </body>
  139. </html>
  140. EOS;
  141. } elseif ($this->_forActionName == 'index' && $this->_resource->getParentResource()->getAttribute('forControllerName') == 'Index') {
  142. $contents =<<<EOS
  143. <style>
  144. a:link,
  145. a:visited
  146. {
  147. color: #0398CA;
  148. }
  149. span#zf-name
  150. {
  151. color: #91BE3F;
  152. }
  153. div#welcome
  154. {
  155. color: #FFFFFF;
  156. background-image: url(http://framework.zend.com/images/bkg_header.jpg);
  157. width: 600px;
  158. height: 400px;
  159. border: 2px solid #444444;
  160. overflow: hidden;
  161. text-align: center;
  162. }
  163. div#more-information
  164. {
  165. background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
  166. height: 100%;
  167. }
  168. </style>
  169. <div id="welcome">
  170. <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1>
  171. <h3>This is your project's main page</h3>
  172. <div id="more-information">
  173. <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p>
  174. <p>
  175. Helpful Links: <br />
  176. <a href="http://framework.zend.com/">Zend Framework Website</a> |
  177. <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a>
  178. </p>
  179. </div>
  180. </div>
  181. EOS;
  182. } else {
  183. $contents = '<br /><br /><center>View script for controller <b>' . $this->_resource->getParentResource()->getAttribute('forControllerName') . '</b>'
  184. . ' and script/action name <b>' . $this->_forActionName . '</b></center>';
  185. }
  186. return $contents;
  187. }
  188. protected function _convertActionNameToFilesystemName($actionName)
  189. {
  190. $filter = new Zend_Filter();
  191. $filter->addFilter(new Zend_Filter_Word_CamelCaseToDash())
  192. ->addFilter(new Zend_Filter_StringToLower());
  193. return $filter->filter($actionName);
  194. }
  195. }