web/lib/Zend/Tool/Project/Provider/View.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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: View.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Tool_Project_Provider_Abstract
       
    25  */
       
    26 require_once 'Zend/Tool/Project/Provider/Abstract.php';
       
    27 
       
    28 /**
       
    29  * @category   Zend
       
    30  * @package    Zend_Tool
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  */
       
    34 class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstract
       
    35 {
       
    36 
       
    37     /**
       
    38      * createResource()
       
    39      *
       
    40      * @param Zend_Tool_Project_Profile $profile
       
    41      * @param string $actionName
       
    42      * @param string $controllerName
       
    43      * @param string $moduleName
       
    44      * @return Zend_Tool_Project_Profile_Resource
       
    45      */
       
    46     public static function createResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
       
    47     {
       
    48         if (!is_string($actionName)) {
       
    49             require_once 'Zend/Tool/Project/Provider/Exception.php';
       
    50             throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
       
    51         }
       
    52 
       
    53         if (!is_string($controllerName)) {
       
    54             require_once 'Zend/Tool/Project/Provider/Exception.php';
       
    55             throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
       
    56         }
       
    57 
       
    58         $profileSearchParams = array();
       
    59 
       
    60         if ($moduleName) {
       
    61             $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
       
    62             $noModuleSearch = null;
       
    63         } else {
       
    64             $noModuleSearch = array('modulesDirectory');
       
    65         }
       
    66 
       
    67         $profileSearchParams[] = 'viewsDirectory';
       
    68         $profileSearchParams[] = 'viewScriptsDirectory';
       
    69 
       
    70         if (($viewScriptsDirectory = $profile->search($profileSearchParams, $noModuleSearch)) === false) {
       
    71             require_once 'Zend/Tool/Project/Provider/Exception.php';
       
    72             throw new Zend_Tool_Project_Provider_Exception('This project does not have a viewScriptsDirectory resource.');
       
    73         }
       
    74 
       
    75         $profileSearchParams['viewControllerScriptsDirectory'] = array('forControllerName' => $controllerName);
       
    76 
       
    77         // @todo check if below is failing b/c of above search params
       
    78         if (($viewControllerScriptsDirectory = $viewScriptsDirectory->search($profileSearchParams)) === false) {
       
    79             $viewControllerScriptsDirectory = $viewScriptsDirectory->createResource('viewControllerScriptsDirectory', array('forControllerName' => $controllerName));
       
    80         }
       
    81 
       
    82         $newViewScriptFile = $viewControllerScriptsDirectory->createResource('ViewScriptFile', array('forActionName' => $actionName));
       
    83 
       
    84         return $newViewScriptFile;
       
    85     }
       
    86 
       
    87     /**
       
    88      * create()
       
    89      *
       
    90      * @param string $controllerName
       
    91      * @param string $actionNameOrSimpleName
       
    92      */
       
    93     public function create($controllerName, $actionNameOrSimpleName)
       
    94     {
       
    95 
       
    96         if ($controllerName == '' || $actionNameOrSimpleName == '') {
       
    97             require_once 'Zend/Tool/Project/Provider/Exception.php';
       
    98             throw new Zend_Tool_Project_Provider_Exception('ControllerName and/or ActionName are empty.');
       
    99         }
       
   100 
       
   101         $profile = $this->_loadProfile();
       
   102 
       
   103         $view = self::createResource($profile, $actionNameOrSimpleName, $controllerName);
       
   104 
       
   105         if ($this->_registry->getRequest()->isPretend()) {
       
   106             $this->_registry->getResponse(
       
   107                 'Would create a view script in location ' . $view->getContext()->getPath()
       
   108                 );
       
   109         } else {
       
   110             $this->_registry->getResponse(
       
   111                 'Creating a view script in location ' . $view->getContext()->getPath()
       
   112                 );
       
   113             $view->create();
       
   114             $this->_storeProfile();
       
   115         }
       
   116 
       
   117     }
       
   118 }