File indexing completed on 2024-06-23 05:55:52

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_Provider_Abstract
0025  */
0026 // require_once 'Zend/Tool/Project/Provider/Abstract.php';
0027 
0028 /**
0029  * @category   Zend
0030  * @package    Zend_Tool
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstract
0035 {
0036 
0037     /**
0038      * createResource()
0039      *
0040      * @param Zend_Tool_Project_Profile $profile
0041      * @param string $actionName
0042      * @param string $controllerName
0043      * @param string $moduleName
0044      * @return Zend_Tool_Project_Profile_Resource
0045      */
0046     public static function createResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
0047     {
0048         if (!is_string($actionName)) {
0049             // require_once 'Zend/Tool/Project/Provider/Exception.php';
0050             throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
0051         }
0052 
0053         if (!is_string($controllerName)) {
0054             // require_once 'Zend/Tool/Project/Provider/Exception.php';
0055             throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
0056         }
0057 
0058         $profileSearchParams = array();
0059 
0060         if ($moduleName) {
0061             $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
0062             $noModuleSearch = null;
0063         } else {
0064             $noModuleSearch = array('modulesDirectory');
0065         }
0066 
0067         $profileSearchParams[] = 'viewsDirectory';
0068         $profileSearchParams[] = 'viewScriptsDirectory';
0069 
0070         if (($viewScriptsDirectory = $profile->search($profileSearchParams, $noModuleSearch)) === false) {
0071             // require_once 'Zend/Tool/Project/Provider/Exception.php';
0072             throw new Zend_Tool_Project_Provider_Exception('This project does not have a viewScriptsDirectory resource.');
0073         }
0074 
0075         $profileSearchParams['viewControllerScriptsDirectory'] = array('forControllerName' => $controllerName);
0076 
0077         // @todo check if below is failing b/c of above search params
0078         if (($viewControllerScriptsDirectory = $viewScriptsDirectory->search($profileSearchParams)) === false) {
0079             $viewControllerScriptsDirectory = $viewScriptsDirectory->createResource('viewControllerScriptsDirectory', array('forControllerName' => $controllerName));
0080         }
0081 
0082         $newViewScriptFile = $viewControllerScriptsDirectory->createResource('ViewScriptFile', array('forActionName' => $actionName));
0083 
0084         return $newViewScriptFile;
0085     }
0086 
0087     /**
0088      * create()
0089      *
0090      * @param string $controllerName
0091      * @param string $actionNameOrSimpleName
0092      */
0093     public function create($controllerName, $actionNameOrSimpleName, $module = null)
0094     {
0095 
0096         if ($controllerName == '' || $actionNameOrSimpleName == '') {
0097             // require_once 'Zend/Tool/Project/Provider/Exception.php';
0098             throw new Zend_Tool_Project_Provider_Exception('ControllerName and/or ActionName are empty.');
0099         }
0100 
0101         $profile = $this->_loadProfile();
0102 
0103         $view = self::createResource($profile, $actionNameOrSimpleName, $controllerName, $module);
0104 
0105         if ($this->_registry->getRequest()->isPretend()) {
0106             $this->_registry->getResponse(
0107                 'Would create a view script in location ' . $view->getContext()->getPath()
0108                 );
0109         } else {
0110             $this->_registry->getResponse(
0111                 'Creating a view script in location ' . $view->getContext()->getPath()
0112                 );
0113             $view->create();
0114             $this->_storeProfile();
0115         }
0116 
0117     }
0118 }