2
0

ViewScriptFile.php 5.6 KB

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