View.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_Provider_Abstract
  24. */
  25. require_once 'Zend/Tool/Project/Provider/Abstract.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Tool
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstract
  33. {
  34. /**
  35. * createResource()
  36. *
  37. * @param Zend_Tool_Project_Profile $profile
  38. * @param string $controllerName
  39. * @param string $actionName
  40. * @param string $moduleName
  41. * @return Zend_Tool_Project_Profile_Resource
  42. */
  43. public static function createResource(Zend_Tool_Project_Profile $profile, $controllerName, $actionName, $moduleName = null)
  44. {
  45. if (!is_string($controllerName)) {
  46. require_once 'Zend/Tool/Project/Provider/Exception.php';
  47. throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
  48. }
  49. if (!is_string($actionName)) {
  50. require_once 'Zend/Tool/Project/Provider/Exception.php';
  51. throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
  52. }
  53. $profileSearchParams = array();
  54. if ($moduleName) {
  55. $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => $moduleName);
  56. }
  57. $profileSearchParams[] = 'viewsDirectory';
  58. $profileSearchParams[] = 'viewScriptsDirectory';
  59. if (($viewScriptsDirectory = $profile->search($profileSearchParams)) === false) {
  60. require_once 'Zend/Tool/Project/Provider/Exception.php';
  61. throw new Zend_Tool_Project_Provider_Exception('This project does not have a viewScriptsDirectory resource.');
  62. }
  63. $profileSearchParams['viewControllerScriptsDirectory'] = array('forControllerName' => $controllerName);
  64. // XXXXXXXXX below is failing b/c of above search params
  65. if (($viewControllerScriptsDirectory = $viewScriptsDirectory->search($profileSearchParams)) === false) {
  66. $viewControllerScriptsDirectory = $viewScriptsDirectory->createResource('viewControllerScriptsDirectory', array('forControllerName' => $controllerName));
  67. }
  68. $newViewScriptFile = $viewControllerScriptsDirectory->createResource('ViewScriptFile', array('forActionName' => $actionName));
  69. return $newViewScriptFile;
  70. }
  71. /**
  72. * create()
  73. *
  74. * @param string $controllerName
  75. * @param string $actionNameOrSimpleName
  76. */
  77. public function create($controllerName, $actionNameOrSimpleName)
  78. {
  79. if ($controllerName == '' || $actionName == '') {
  80. require_once 'Zend/Tool/Project/Provider/Exception.php';
  81. throw new Zend_Tool_Project_Provider_Exception('ControllerName and/or ActionName are empty.');
  82. }
  83. $profile = $this->_loadProfile();
  84. $view = self::createResource($profile, $controllerName, $actionName);
  85. if ($this->_registry->getRequest()->isPretend()) {
  86. $this->_registry->getResponse(
  87. 'Would create a view script in location ' . $view->getContext()->getPath()
  88. );
  89. } else {
  90. $this->_registry->getResponse(
  91. 'Creating a view script in location ' . $view->getContext()->getPath()
  92. );
  93. $view->create();
  94. $this->_storeProfile();
  95. }
  96. }
  97. }