File indexing completed on 2025-03-02 05:29:55
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Project_Context_Filesystem_File 0025 */ 0026 // require_once 'Zend/Tool/Project/Context/Filesystem/File.php'; 0027 0028 /** 0029 * @see Zend_Filter 0030 */ 0031 // require_once 'Zend/Filter.php'; 0032 0033 /** 0034 * @see Zend_Filter_Word_CamelCaseToDash 0035 */ 0036 // require_once 'Zend/Filter/Word/CamelCaseToDash.php'; 0037 0038 /** 0039 * @see Zend_Filter_StringToLower 0040 */ 0041 // require_once 'Zend/Filter/StringToLower.php'; 0042 0043 0044 /** 0045 * This class is the front most class for utilizing Zend_Tool_Project 0046 * 0047 * A profile is a hierarchical set of resources that keep track of 0048 * items within a specific project. 0049 * 0050 * @category Zend 0051 * @package Zend_Tool 0052 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0053 * @license http://framework.zend.com/license/new-bsd New BSD License 0054 */ 0055 class Zend_Tool_Project_Context_Zf_ViewScriptFile extends Zend_Tool_Project_Context_Filesystem_File 0056 { 0057 0058 /** 0059 * @var string 0060 */ 0061 protected $_filesystemName = 'view.phtml'; 0062 0063 /** 0064 * @var string 0065 */ 0066 protected $_forActionName = null; 0067 0068 /** 0069 * @var string 0070 */ 0071 protected $_scriptName = null; 0072 0073 /** 0074 * getName() 0075 * 0076 * @return string 0077 */ 0078 public function getName() 0079 { 0080 return 'ViewScriptFile'; 0081 } 0082 0083 /** 0084 * init() 0085 * 0086 * @return Zend_Tool_Project_Context_Zf_ViewScriptFile 0087 */ 0088 public function init() 0089 { 0090 if ($forActionName = $this->_resource->getAttribute('forActionName')) { 0091 $this->_forActionName = $forActionName; 0092 $this->_filesystemName = $this->_convertActionNameToFilesystemName($forActionName) . '.phtml'; 0093 } elseif ($scriptName = $this->_resource->getAttribute('scriptName')) { 0094 $this->_scriptName = $scriptName; 0095 $this->_filesystemName = $scriptName . '.phtml'; 0096 } else { 0097 throw new Exception('Either a forActionName or scriptName is required.'); 0098 } 0099 0100 parent::init(); 0101 return $this; 0102 } 0103 0104 /** 0105 * getPersistentAttributes() 0106 * 0107 * @return unknown 0108 */ 0109 public function getPersistentAttributes() 0110 { 0111 $attributes = array(); 0112 0113 if ($this->_forActionName) { 0114 $attributes['forActionName'] = $this->_forActionName; 0115 } 0116 0117 if ($this->_scriptName) { 0118 $attributes['scriptName'] = $this->_scriptName; 0119 } 0120 0121 return $attributes; 0122 } 0123 0124 /** 0125 * getContents() 0126 * 0127 * @return string 0128 */ 0129 public function getContents() 0130 { 0131 $contents = ''; 0132 0133 $controllerName = $this->_resource->getParentResource()->getAttribute('forControllerName'); 0134 0135 $viewsDirectoryResource = $this->_resource 0136 ->getParentResource() // view script 0137 ->getParentResource() // view controller dir 0138 ->getParentResource(); // views dir 0139 if ($viewsDirectoryResource->getParentResource()->getName() == 'ModuleDirectory') { 0140 $moduleName = $viewsDirectoryResource->getParentResource()->getModuleName(); 0141 } else { 0142 $moduleName = 'default'; 0143 } 0144 0145 if ($this->_filesystemName == 'error.phtml') { // should also check that the above directory is forController=error 0146 $contents .= <<<EOS 0147 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 0148 <html xmlns="http://www.w3.org/1999/xhtml"> 0149 <head> 0150 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 0151 <title>Zend Framework Default Application</title> 0152 </head> 0153 <body> 0154 <h1>An error occurred</h1> 0155 <h2><?php echo \$this->message ?></h2> 0156 0157 <?php if (isset(\$this->exception)): ?> 0158 0159 <h3>Exception information:</h3> 0160 <p> 0161 <b>Message:</b> <?php echo \$this->exception->getMessage() ?> 0162 </p> 0163 0164 <h3>Stack trace:</h3> 0165 <pre><?php echo \$this->exception->getTraceAsString() ?> 0166 </pre> 0167 0168 <h3>Request Parameters:</h3> 0169 <pre><?php echo \$this->escape(var_export(\$this->request->getParams(), true)) ?> 0170 </pre> 0171 0172 <?php endif ?> 0173 0174 </body> 0175 </html> 0176 0177 EOS; 0178 } elseif ($this->_forActionName == 'index' && $controllerName == 'Index' && $moduleName == 'default') { 0179 0180 $contents =<<<EOS 0181 <style> 0182 a:link, 0183 a:visited 0184 { 0185 color: #0398CA; 0186 } 0187 0188 span#zf-name 0189 { 0190 color: #91BE3F; 0191 } 0192 0193 div#welcome 0194 { 0195 color: #FFFFFF; 0196 background-image: url(http://framework.zend.com/images/bkg_header.jpg); 0197 width: 600px; 0198 height: 400px; 0199 border: 2px solid #444444; 0200 overflow: hidden; 0201 text-align: center; 0202 } 0203 0204 div#more-information 0205 { 0206 background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif); 0207 height: 100%; 0208 } 0209 </style> 0210 <div id="welcome"> 0211 <h1>Welcome to the <span id="zf-name">Zend Framework!</span></h1> 0212 0213 <h3>This is your project's main page</h3> 0214 0215 <div id="more-information"> 0216 <p><img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /></p> 0217 <p> 0218 Helpful Links: <br /> 0219 <a href="http://framework.zend.com/">Zend Framework Website</a> | 0220 <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a> 0221 </p> 0222 </div> 0223 </div> 0224 EOS; 0225 0226 } else { 0227 $controllerName = $this->_resource->getParentResource()->getAttribute('forControllerName'); 0228 $actionName = $this->_forActionName; 0229 $contents = <<<EOS 0230 <br /><br /> 0231 <div id="view-content"> 0232 <p>View script for controller <b>$controllerName</b> and script/action name <b>$actionName</b></p> 0233 </div> 0234 EOS; 0235 } 0236 return $contents; 0237 } 0238 0239 protected function _convertActionNameToFilesystemName($actionName) 0240 { 0241 $filter = new Zend_Filter(); 0242 $filter->addFilter(new Zend_Filter_Word_CamelCaseToDash()) 0243 ->addFilter(new Zend_Filter_StringToLower()); 0244 return $filter->filter($actionName); 0245 } 0246 0247 }