Project.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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, $nameOfProfile = null, $fileOfProfile = null)
  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. $profileData = null;
  61. if ($fileOfProfile != null && file_exists($fileOfProfile)) {
  62. $profileData = file_get_contents($fileOfProfile);
  63. }
  64. $storage = $this->_registry->getStorage();
  65. if ($profileData == '' && $nameOfProfile != null && $storage->isEnabled()) {
  66. $profileData = $storage->get('project/profiles/' . $nameOfProfile . '.xml');
  67. }
  68. if ($profileData == '') {
  69. $profileData = $this->_getDefaultProfile();
  70. }
  71. $newProfile = new Zend_Tool_Project_Profile(array(
  72. 'projectDirectory' => $path,
  73. 'profileData' => $profileData
  74. ));
  75. $newProfile->loadFromData();
  76. $this->_registry->getResponse()->appendContent('Creating project at ' . $path);
  77. foreach ($newProfile->getIterator() as $resource) {
  78. $resource->create();
  79. }
  80. }
  81. public function show()
  82. {
  83. $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow'));
  84. }
  85. public function showInfo()
  86. {
  87. $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE);
  88. if (!$profile) {
  89. $this->_registry->getResponse()->appendContent('No project found.');
  90. } else {
  91. $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory'));
  92. }
  93. }
  94. protected function _getDefaultProfile()
  95. {
  96. $data = <<<EOS
  97. <?xml version="1.0" encoding="UTF-8"?>
  98. <projectProfile type="default">
  99. <projectDirectory>
  100. <projectProfileFile />
  101. <applicationDirectory>
  102. <apisDirectory enabled="false" />
  103. <configsDirectory>
  104. <applicationConfigFile type="ini" />
  105. </configsDirectory>
  106. <controllersDirectory>
  107. <controllerFile controllerName="index">
  108. <actionMethod actionName="index" />
  109. </controllerFile>
  110. <controllerFile controllerName="error" />
  111. </controllersDirectory>
  112. <layoutsDirectory enabled="false" />
  113. <modelsDirectory />
  114. <modulesDirectory enabled="false" />
  115. <viewsDirectory>
  116. <viewScriptsDirectory>
  117. <viewControllerScriptsDirectory forControllerName="index">
  118. <viewScriptFile forActionName="index" />
  119. </viewControllerScriptsDirectory>
  120. <viewControllerScriptsDirectory forControllerName="error">
  121. <viewScriptFile forActionName="error" />
  122. </viewControllerScriptsDirectory>
  123. </viewScriptsDirectory>
  124. <viewHelpersDirectory />
  125. <viewFiltersDirectory enabled="false" />
  126. </viewsDirectory>
  127. <bootstrapFile />
  128. </applicationDirectory>
  129. <dataDirectory enabled="false">
  130. <cacheDirectory enabled="false" />
  131. <searchIndexesDirectory enabled="false" />
  132. <localesDirectory enabled="false" />
  133. <logsDirectory enabled="false" />
  134. <sessionsDirectory enabled="false" />
  135. <uploadsDirectory enabled="false" />
  136. </dataDirectory>
  137. <libraryDirectory>
  138. <zfStandardLibraryDirectory enabled="false" />
  139. </libraryDirectory>
  140. <publicDirectory>
  141. <publicStylesheetsDirectory enabled="false" />
  142. <publicScriptsDirectory enabled="false" />
  143. <publicImagesDirectory enabled="false" />
  144. <publicIndexFile />
  145. <htaccessFile />
  146. </publicDirectory>
  147. <projectProvidersDirectory enabled="false" />
  148. <temporaryDirectory enabled="false" />
  149. <testsDirectory>
  150. <testPHPUnitConfigFile />
  151. <testApplicationDirectory>
  152. <testApplicationBootstrapFile />
  153. </testApplicationDirectory>
  154. <testLibraryDirectory>
  155. <testLibraryBootstrapFile />
  156. </testLibraryDirectory>
  157. </testsDirectory>
  158. </projectDirectory>
  159. </projectProfile>
  160. EOS;
  161. return $data;
  162. }
  163. }