ViewScriptFile.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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-2014 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-2014 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. $controllerName = $this->_resource->getParentResource()->getAttribute('forControllerName');
  116. $viewsDirectoryResource = $this->_resource
  117. ->getParentResource() // view script
  118. ->getParentResource() // view controller dir
  119. ->getParentResource(); // views dir
  120. if ($viewsDirectoryResource->getParentResource()->getName() == 'ModuleDirectory') {
  121. $moduleName = $viewsDirectoryResource->getParentResource()->getModuleName();
  122. } else {
  123. $moduleName = 'default';
  124. }
  125. if ($this->_filesystemName == 'error.phtml') { // should also check that the above directory is forController=error
  126. $contents .= <<<EOS
  127. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  128. <html xmlns="http://www.w3.org/1999/xhtml">
  129. <head>
  130. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  131. <title>Zend Framework Default Application</title>
  132. </head>
  133. <body>
  134. <h1>An error occurred</h1>
  135. <h2><?php echo \$this->message ?></h2>
  136. <?php if (isset(\$this->exception)): ?>
  137. <h3>Exception information:</h3>
  138. <p>
  139. <b>Message:</b> <?php echo \$this->exception->getMessage() ?>
  140. </p>
  141. <h3>Stack trace:</h3>
  142. <pre><?php echo \$this->exception->getTraceAsString() ?>
  143. </pre>
  144. <h3>Request Parameters:</h3>
  145. <pre><?php echo \$this->escape(var_export(\$this->request->getParams(), true)) ?>
  146. </pre>
  147. <?php endif ?>
  148. </body>
  149. </html>
  150. EOS;
  151. } elseif ($this->_forActionName == 'index' && $controllerName == 'Index' && $moduleName == 'default') {
  152. $contents =<<<EOS
  153. <style>
  154. a:link,
  155. a:visited
  156. {
  157. color: #0398CA;
  158. }
  159. span#zf-name
  160. {
  161. color: #91BE3F;
  162. }
  163. div#welcome
  164. {
  165. color: #FFFFFF;
  166. background-image: url(http://framework.zend.com/images/bkg_header.jpg);
  167. width: 600px;
  168. height: 400px;
  169. border: 2px solid #444444;
  170. overflow: hidden;
  171. text-align: center;
  172. }
  173. div#more-information
  174. {
  175. background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif);
  176. height: 100%;
  177. }
  178. </style>
  179. <div id="welcome">
  180. <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1>
  181. <h3>This is your project's main page</h3>
  182. <div id="more-information">
  183. <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p>
  184. <p>
  185. Helpful Links: <br />
  186. <a href="http://framework.zend.com/">Zend Framework Website</a> |
  187. <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a>
  188. </p>
  189. </div>
  190. </div>
  191. EOS;
  192. } else {
  193. $controllerName = $this->_resource->getParentResource()->getAttribute('forControllerName');
  194. $actionName = $this->_forActionName;
  195. $contents = <<<EOS
  196. <br /><br />
  197. <div id="view-content">
  198. <p>View script for controller <b>$controllerName</b> and script/action name <b>$actionName</b></p>
  199. </div>
  200. EOS;
  201. }
  202. return $contents;
  203. }
  204. protected function _convertActionNameToFilesystemName($actionName)
  205. {
  206. $filter = new Zend_Filter();
  207. $filter->addFilter(new Zend_Filter_Word_CamelCaseToDash())
  208. ->addFilter(new Zend_Filter_StringToLower());
  209. return $filter->filter($actionName);
  210. }
  211. }