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