Project.php 8.2 KB

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