Project.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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-2015 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-2015 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. $response = $this->_registry->getResponse();
  81. $response->appendContent('Creating project at ' . $path);
  82. $response->appendContent('Note: ', array('separator' => false, 'color' => 'yellow'));
  83. $response->appendContent(
  84. 'This command created a web project, '
  85. . 'for more information setting up your VHOST, please see docs/README');
  86. if (!Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) {
  87. $response->appendContent('Testing Note: ', array('separator' => false, 'color' => 'yellow'));
  88. $response->appendContent('PHPUnit was not found in your include_path, therefore no testing actions will be created.');
  89. }
  90. foreach ($newProfile->getIterator() as $resource) {
  91. $resource->create();
  92. }
  93. }
  94. public function show()
  95. {
  96. $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow'));
  97. }
  98. public function showInfo()
  99. {
  100. $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE);
  101. if (!$profile) {
  102. $this->_registry->getResponse()->appendContent('No project found.');
  103. } else {
  104. $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory'));
  105. }
  106. }
  107. protected function _getDefaultProfile()
  108. {
  109. $testAction = '';
  110. if (Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) {
  111. $testAction = ' <testApplicationActionMethod forActionName="index" />';
  112. }
  113. $version = Zend_Version::VERSION;
  114. $data = <<<EOS
  115. <?xml version="1.0" encoding="UTF-8"?>
  116. <projectProfile type="default" version="$version">
  117. <projectDirectory>
  118. <projectProfileFile />
  119. <applicationDirectory>
  120. <configsDirectory>
  121. <applicationConfigFile type="ini" />
  122. </configsDirectory>
  123. <controllersDirectory>
  124. <controllerFile controllerName="Index">
  125. <actionMethod actionName="index" />
  126. </controllerFile>
  127. <controllerFile controllerName="Error" />
  128. </controllersDirectory>
  129. <formsDirectory enabled="false" />
  130. <layoutsDirectory enabled="false" />
  131. <modelsDirectory />
  132. <modulesDirectory enabled="false" />
  133. <servicesDirectory enabled="false" />
  134. <viewsDirectory>
  135. <viewScriptsDirectory>
  136. <viewControllerScriptsDirectory forControllerName="Index">
  137. <viewScriptFile forActionName="index" />
  138. </viewControllerScriptsDirectory>
  139. <viewControllerScriptsDirectory forControllerName="Error">
  140. <viewScriptFile forActionName="error" />
  141. </viewControllerScriptsDirectory>
  142. </viewScriptsDirectory>
  143. <viewHelpersDirectory />
  144. <viewFiltersDirectory enabled="false" />
  145. </viewsDirectory>
  146. <bootstrapFile />
  147. </applicationDirectory>
  148. <dataDirectory enabled="false">
  149. <cacheDirectory enabled="false" />
  150. <searchIndexesDirectory enabled="false" />
  151. <localesDirectory enabled="false" />
  152. <logsDirectory enabled="false" />
  153. <sessionsDirectory enabled="false" />
  154. <uploadsDirectory enabled="false" />
  155. </dataDirectory>
  156. <docsDirectory>
  157. <file filesystemName="README.txt" defaultContentCallback="Zend_Tool_Project_Provider_Project::getDefaultReadmeContents"/>
  158. </docsDirectory>
  159. <libraryDirectory>
  160. <zfStandardLibraryDirectory enabled="false" />
  161. </libraryDirectory>
  162. <publicDirectory>
  163. <publicStylesheetsDirectory enabled="false" />
  164. <publicScriptsDirectory enabled="false" />
  165. <publicImagesDirectory enabled="false" />
  166. <publicIndexFile />
  167. <htaccessFile />
  168. </publicDirectory>
  169. <projectProvidersDirectory enabled="false" />
  170. <temporaryDirectory enabled="false" />
  171. <testsDirectory>
  172. <testPHPUnitConfigFile />
  173. <testPHPUnitBootstrapFile />
  174. <testApplicationDirectory>
  175. <testApplicationControllerDirectory>
  176. <testApplicationControllerFile filesystemName="IndexControllerTest.php" forControllerName="Index">
  177. $testAction
  178. </testApplicationControllerFile>
  179. </testApplicationControllerDirectory>
  180. </testApplicationDirectory>
  181. <testLibraryDirectory />
  182. </testsDirectory>
  183. </projectDirectory>
  184. </projectProfile>
  185. EOS;
  186. return $data;
  187. }
  188. public static function getDefaultReadmeContents($caller = null)
  189. {
  190. $projectDirResource = $caller->getResource()->getProfile()->search('projectDirectory');
  191. if ($projectDirResource) {
  192. $name = ltrim(strrchr($projectDirResource->getPath(), DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
  193. $path = $projectDirResource->getPath() . '/public';
  194. } else {
  195. $path = '/path/to/public';
  196. }
  197. return <<< EOS
  198. README
  199. ======
  200. This directory should be used to place project specfic documentation including
  201. but not limited to project notes, generated API/phpdoc documentation, or
  202. manual files generated or hand written. Ideally, this directory would remain
  203. in your development environment only and should not be deployed with your
  204. application to it's final production location.
  205. Setting Up Your VHOST
  206. =====================
  207. The following is a sample VHOST you might want to consider for your project.
  208. <VirtualHost *:80>
  209. DocumentRoot "$path"
  210. ServerName $name.local
  211. # This should be omitted in the production environment
  212. SetEnv APPLICATION_ENV development
  213. <Directory "$path">
  214. Options Indexes MultiViews FollowSymLinks
  215. AllowOverride All
  216. Order allow,deny
  217. Allow from all
  218. </Directory>
  219. </VirtualHost>
  220. EOS;
  221. }
  222. }