Project.php 6.6 KB

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