2
0

Project.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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_Project extends Zend_Tool_Project_Provider_Abstract
  33. {
  34. protected $_specialties = array('Info');
  35. /**
  36. * create()
  37. *
  38. * @param string $path
  39. */
  40. public function create($path)
  41. {
  42. if ($path == null) {
  43. $path = getcwd();
  44. } else {
  45. $path = trim($path);
  46. if (!file_exists($path)) {
  47. $created = mkdir($path);
  48. if (!$created) {
  49. require_once 'Zend/Tool/Framework/Client/Exception.php';
  50. throw new Zend_Tool_Framework_Client_Exception('Could not create requested project directory \'' . $path . '\'');
  51. }
  52. }
  53. $path = str_replace('\\', '/', realpath($path));
  54. }
  55. $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path);
  56. if ($profile !== false) {
  57. require_once 'Zend/Tool/Framework/Client/Exception.php';
  58. throw new Zend_Tool_Framework_Client_Exception('A project already exists here');
  59. }
  60. $newProfile = new Zend_Tool_Project_Profile(array(
  61. 'projectDirectory' => $path,
  62. 'profileData' => $this->_getDefaultProfile()
  63. ));
  64. $newProfile->loadFromData();
  65. $this->_registry->getResponse()->appendContent('Creating project at ' . $path);
  66. foreach ($newProfile->getIterator() as $resource) {
  67. $resource->create();
  68. }
  69. }
  70. public function show()
  71. {
  72. $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow'));
  73. }
  74. public function showInfo()
  75. {
  76. $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE);
  77. if (!$profile) {
  78. $this->_registry->getResponse()->appendContent('No project found.');
  79. } else {
  80. $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory'));
  81. }
  82. }
  83. protected function _getDefaultProfile()
  84. {
  85. $data = <<<EOS
  86. <?xml version="1.0" encoding="UTF-8"?>
  87. <projectProfile type="default">
  88. <projectDirectory>
  89. <projectProfileFile />
  90. <applicationDirectory>
  91. <apisDirectory enabled="false" />
  92. <configsDirectory>
  93. <applicationConfigFile type="ini" />
  94. </configsDirectory>
  95. <controllersDirectory>
  96. <controllerFile controllerName="index">
  97. <actionMethod actionName="index" />
  98. </controllerFile>
  99. <controllerFile controllerName="error" />
  100. </controllersDirectory>
  101. <layoutsDirectory enabled="false" />
  102. <modelsDirectory />
  103. <modulesDirectory enabled="false" />
  104. <viewsDirectory>
  105. <viewScriptsDirectory>
  106. <viewControllerScriptsDirectory forControllerName="index">
  107. <viewScriptFile forActionName="index" />
  108. </viewControllerScriptsDirectory>
  109. <viewControllerScriptsDirectory forControllerName="error">
  110. <viewScriptFile forActionName="error" />
  111. </viewControllerScriptsDirectory>
  112. </viewScriptsDirectory>
  113. <viewHelpersDirectory />
  114. <viewFiltersDirectory enabled="false" />
  115. </viewsDirectory>
  116. <bootstrapFile />
  117. </applicationDirectory>
  118. <dataDirectory enabled="false">
  119. <cacheDirectory enabled="false" />
  120. <searchIndexesDirectory enabled="false" />
  121. <localesDirectory enabled="false" />
  122. <logsDirectory enabled="false" />
  123. <sessionsDirectory enabled="false" />
  124. <uploadsDirectory enabled="false" />
  125. </dataDirectory>
  126. <libraryDirectory>
  127. <zfStandardLibraryDirectory enabled="false" />
  128. </libraryDirectory>
  129. <publicDirectory>
  130. <publicStylesheetsDirectory enabled="false" />
  131. <publicScriptsDirectory enabled="false" />
  132. <publicImagesDirectory enabled="false" />
  133. <publicIndexFile />
  134. <htaccessFile />
  135. </publicDirectory>
  136. <projectProvidersDirectory enabled="false" />
  137. <temporaryDirectory enabled="false" />
  138. <testsDirectory>
  139. <testPHPUnitConfigFile />
  140. <testApplicationDirectory>
  141. <testApplicationBootstrapFile />
  142. </testApplicationDirectory>
  143. <testLibraryDirectory>
  144. <testLibraryBootstrapFile />
  145. </testLibraryDirectory>
  146. </testsDirectory>
  147. </projectDirectory>
  148. </projectProfile>
  149. EOS;
  150. return $data;
  151. }
  152. }