|
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: Project.php 20898 2010-02-04 07:03:46Z ralph $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Project_Provider_Abstract |
|
25 */ |
|
26 require_once 'Zend/Tool/Project/Provider/Abstract.php'; |
|
27 |
|
28 /** |
|
29 * @category Zend |
|
30 * @package Zend_Tool |
|
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
33 */ |
|
34 class Zend_Tool_Project_Provider_Project |
|
35 extends Zend_Tool_Project_Provider_Abstract |
|
36 //implements Zend_Tool_Framework_Provider_DocblockManifestInterface |
|
37 { |
|
38 |
|
39 protected $_specialties = array('Info'); |
|
40 |
|
41 /** |
|
42 * create() |
|
43 * |
|
44 * @param string $path |
|
45 * @param string $nameOfProfile shortName=n |
|
46 * @param string $fileOfProfile shortName=f |
|
47 */ |
|
48 public function create($path, $nameOfProfile = null, $fileOfProfile = null) |
|
49 { |
|
50 if ($path == null) { |
|
51 $path = getcwd(); |
|
52 } else { |
|
53 $path = trim($path); |
|
54 if (!file_exists($path)) { |
|
55 $created = mkdir($path); |
|
56 if (!$created) { |
|
57 require_once 'Zend/Tool/Framework/Client/Exception.php'; |
|
58 throw new Zend_Tool_Framework_Client_Exception('Could not create requested project directory \'' . $path . '\''); |
|
59 } |
|
60 } |
|
61 $path = str_replace('\\', '/', realpath($path)); |
|
62 } |
|
63 |
|
64 $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path); |
|
65 |
|
66 if ($profile !== false) { |
|
67 require_once 'Zend/Tool/Framework/Client/Exception.php'; |
|
68 throw new Zend_Tool_Framework_Client_Exception('A project already exists here'); |
|
69 } |
|
70 |
|
71 $profileData = null; |
|
72 |
|
73 if ($fileOfProfile != null && file_exists($fileOfProfile)) { |
|
74 $profileData = file_get_contents($fileOfProfile); |
|
75 } |
|
76 |
|
77 $storage = $this->_registry->getStorage(); |
|
78 if ($profileData == '' && $nameOfProfile != null && $storage->isEnabled()) { |
|
79 $profileData = $storage->get('project/profiles/' . $nameOfProfile . '.xml'); |
|
80 } |
|
81 |
|
82 if ($profileData == '') { |
|
83 $profileData = $this->_getDefaultProfile(); |
|
84 } |
|
85 |
|
86 $newProfile = new Zend_Tool_Project_Profile(array( |
|
87 'projectDirectory' => $path, |
|
88 'profileData' => $profileData |
|
89 )); |
|
90 |
|
91 $newProfile->loadFromData(); |
|
92 |
|
93 $response = $this->_registry->getResponse(); |
|
94 |
|
95 $response->appendContent('Creating project at ' . $path); |
|
96 $response->appendContent('Note: ', array('separator' => false, 'color' => 'yellow')); |
|
97 $response->appendContent( |
|
98 'This command created a web project, ' |
|
99 . 'for more information setting up your VHOST, please see docs/README'); |
|
100 |
|
101 foreach ($newProfile->getIterator() as $resource) { |
|
102 $resource->create(); |
|
103 } |
|
104 } |
|
105 |
|
106 public function show() |
|
107 { |
|
108 $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow')); |
|
109 } |
|
110 |
|
111 public function showInfo() |
|
112 { |
|
113 $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE); |
|
114 if (!$profile) { |
|
115 $this->_registry->getResponse()->appendContent('No project found.'); |
|
116 } else { |
|
117 $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory')); |
|
118 } |
|
119 } |
|
120 |
|
121 protected function _getDefaultProfile() |
|
122 { |
|
123 $data = <<<EOS |
|
124 <?xml version="1.0" encoding="UTF-8"?> |
|
125 <projectProfile type="default" version="1.10"> |
|
126 <projectDirectory> |
|
127 <projectProfileFile /> |
|
128 <applicationDirectory> |
|
129 <apisDirectory enabled="false" /> |
|
130 <configsDirectory> |
|
131 <applicationConfigFile type="ini" /> |
|
132 </configsDirectory> |
|
133 <controllersDirectory> |
|
134 <controllerFile controllerName="Index"> |
|
135 <actionMethod actionName="index" /> |
|
136 </controllerFile> |
|
137 <controllerFile controllerName="Error" /> |
|
138 </controllersDirectory> |
|
139 <formsDirectory enabled="false" /> |
|
140 <layoutsDirectory enabled="false" /> |
|
141 <modelsDirectory /> |
|
142 <modulesDirectory enabled="false" /> |
|
143 <viewsDirectory> |
|
144 <viewScriptsDirectory> |
|
145 <viewControllerScriptsDirectory forControllerName="Index"> |
|
146 <viewScriptFile forActionName="index" /> |
|
147 </viewControllerScriptsDirectory> |
|
148 <viewControllerScriptsDirectory forControllerName="Error"> |
|
149 <viewScriptFile forActionName="error" /> |
|
150 </viewControllerScriptsDirectory> |
|
151 </viewScriptsDirectory> |
|
152 <viewHelpersDirectory /> |
|
153 <viewFiltersDirectory enabled="false" /> |
|
154 </viewsDirectory> |
|
155 <bootstrapFile /> |
|
156 </applicationDirectory> |
|
157 <dataDirectory enabled="false"> |
|
158 <cacheDirectory enabled="false" /> |
|
159 <searchIndexesDirectory enabled="false" /> |
|
160 <localesDirectory enabled="false" /> |
|
161 <logsDirectory enabled="false" /> |
|
162 <sessionsDirectory enabled="false" /> |
|
163 <uploadsDirectory enabled="false" /> |
|
164 </dataDirectory> |
|
165 <docsDirectory> |
|
166 <file filesystemName="README.txt" defaultContentCallback="Zend_Tool_Project_Provider_Project::getDefaultReadmeContents"/> |
|
167 </docsDirectory> |
|
168 <libraryDirectory> |
|
169 <zfStandardLibraryDirectory enabled="false" /> |
|
170 </libraryDirectory> |
|
171 <publicDirectory> |
|
172 <publicStylesheetsDirectory enabled="false" /> |
|
173 <publicScriptsDirectory enabled="false" /> |
|
174 <publicImagesDirectory enabled="false" /> |
|
175 <publicIndexFile /> |
|
176 <htaccessFile /> |
|
177 </publicDirectory> |
|
178 <projectProvidersDirectory enabled="false" /> |
|
179 <temporaryDirectory enabled="false" /> |
|
180 <testsDirectory> |
|
181 <testPHPUnitConfigFile /> |
|
182 <testApplicationDirectory> |
|
183 <testApplicationBootstrapFile /> |
|
184 </testApplicationDirectory> |
|
185 <testLibraryDirectory> |
|
186 <testLibraryBootstrapFile /> |
|
187 </testLibraryDirectory> |
|
188 </testsDirectory> |
|
189 </projectDirectory> |
|
190 </projectProfile> |
|
191 EOS; |
|
192 return $data; |
|
193 } |
|
194 |
|
195 public static function getDefaultReadmeContents($caller = null) |
|
196 { |
|
197 $projectDirResource = $caller->getResource()->getProfile()->search('projectDirectory'); |
|
198 if ($projectDirResource) { |
|
199 $name = ltrim(strrchr($projectDirResource->getPath(), DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); |
|
200 $path = $projectDirResource->getPath() . '/public'; |
|
201 } else { |
|
202 $path = '/path/to/public'; |
|
203 } |
|
204 |
|
205 return <<< EOS |
|
206 README |
|
207 ====== |
|
208 |
|
209 This directory should be used to place project specfic documentation including |
|
210 but not limited to project notes, generated API/phpdoc documentation, or |
|
211 manual files generated or hand written. Ideally, this directory would remain |
|
212 in your development environment only and should not be deployed with your |
|
213 application to it's final production location. |
|
214 |
|
215 |
|
216 Setting Up Your VHOST |
|
217 ===================== |
|
218 |
|
219 The following is a sample VHOST you might want to consider for your project. |
|
220 |
|
221 <VirtualHost *:80> |
|
222 DocumentRoot "$path" |
|
223 ServerName $name.local |
|
224 |
|
225 # This should be omitted in the production environment |
|
226 SetEnv APPLICATION_ENV development |
|
227 |
|
228 <Directory "$path"> |
|
229 Options Indexes MultiViews FollowSymLinks |
|
230 AllowOverride All |
|
231 Order allow,deny |
|
232 Allow from all |
|
233 </Directory> |
|
234 |
|
235 </VirtualHost> |
|
236 |
|
237 EOS; |
|
238 } |
|
239 } |