File indexing completed on 2025-01-19 05:21:37
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Tool 0017 * @subpackage Framework 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Tool_Project_Provider_Abstract 0025 */ 0026 // require_once 'Zend/Tool/Project/Provider/Abstract.php'; 0027 0028 /** 0029 * @category Zend 0030 * @package Zend_Tool 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 */ 0034 class Zend_Tool_Project_Provider_Project 0035 extends Zend_Tool_Project_Provider_Abstract 0036 //implements Zend_Tool_Framework_Provider_DocblockManifestInterface 0037 { 0038 0039 protected $_specialties = array('Info'); 0040 0041 /** 0042 * create() 0043 * 0044 * @param string $path 0045 * @param string $nameOfProfile shortName=n 0046 * @param string $fileOfProfile shortName=f 0047 */ 0048 public function create($path, $nameOfProfile = null, $fileOfProfile = null) 0049 { 0050 if ($path == null) { 0051 $path = getcwd(); 0052 } else { 0053 $path = trim($path); 0054 if (!file_exists($path)) { 0055 $created = mkdir($path); 0056 if (!$created) { 0057 // require_once 'Zend/Tool/Framework/Client/Exception.php'; 0058 throw new Zend_Tool_Framework_Client_Exception('Could not create requested project directory \'' . $path . '\''); 0059 } 0060 } 0061 $path = str_replace('\\', '/', realpath($path)); 0062 } 0063 0064 $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path); 0065 0066 if ($profile !== false) { 0067 // require_once 'Zend/Tool/Framework/Client/Exception.php'; 0068 throw new Zend_Tool_Framework_Client_Exception('A project already exists here'); 0069 } 0070 0071 $profileData = null; 0072 0073 if ($fileOfProfile != null && file_exists($fileOfProfile)) { 0074 $profileData = file_get_contents($fileOfProfile); 0075 } 0076 0077 $storage = $this->_registry->getStorage(); 0078 if ($profileData == '' && $nameOfProfile != null && $storage->isEnabled()) { 0079 $profileData = $storage->get('project/profiles/' . $nameOfProfile . '.xml'); 0080 } 0081 0082 if ($profileData == '') { 0083 $profileData = $this->_getDefaultProfile(); 0084 } 0085 0086 $newProfile = new Zend_Tool_Project_Profile(array( 0087 'projectDirectory' => $path, 0088 'profileData' => $profileData 0089 )); 0090 0091 $newProfile->loadFromData(); 0092 0093 $response = $this->_registry->getResponse(); 0094 0095 $response->appendContent('Creating project at ' . $path); 0096 $response->appendContent('Note: ', array('separator' => false, 'color' => 'yellow')); 0097 $response->appendContent( 0098 'This command created a web project, ' 0099 . 'for more information setting up your VHOST, please see docs/README'); 0100 0101 if (!Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) { 0102 $response->appendContent('Testing Note: ', array('separator' => false, 'color' => 'yellow')); 0103 $response->appendContent('PHPUnit was not found in your include_path, therefore no testing actions will be created.'); 0104 } 0105 0106 foreach ($newProfile->getIterator() as $resource) { 0107 $resource->create(); 0108 } 0109 } 0110 0111 public function show() 0112 { 0113 $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow')); 0114 } 0115 0116 public function showInfo() 0117 { 0118 $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE); 0119 if (!$profile) { 0120 $this->_registry->getResponse()->appendContent('No project found.'); 0121 } else { 0122 $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory')); 0123 } 0124 } 0125 0126 protected function _getDefaultProfile() 0127 { 0128 $testAction = ''; 0129 if (Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) { 0130 $testAction = ' <testApplicationActionMethod forActionName="index" />'; 0131 } 0132 0133 $version = Zend_Version::VERSION; 0134 0135 $data = <<<EOS 0136 <?xml version="1.0" encoding="UTF-8"?> 0137 <projectProfile type="default" version="$version"> 0138 <projectDirectory> 0139 <projectProfileFile /> 0140 <applicationDirectory> 0141 <configsDirectory> 0142 <applicationConfigFile type="ini" /> 0143 </configsDirectory> 0144 <controllersDirectory> 0145 <controllerFile controllerName="Index"> 0146 <actionMethod actionName="index" /> 0147 </controllerFile> 0148 <controllerFile controllerName="Error" /> 0149 </controllersDirectory> 0150 <formsDirectory enabled="false" /> 0151 <layoutsDirectory enabled="false" /> 0152 <modelsDirectory /> 0153 <modulesDirectory enabled="false" /> 0154 <servicesDirectory enabled="false" /> 0155 <viewsDirectory> 0156 <viewScriptsDirectory> 0157 <viewControllerScriptsDirectory forControllerName="Index"> 0158 <viewScriptFile forActionName="index" /> 0159 </viewControllerScriptsDirectory> 0160 <viewControllerScriptsDirectory forControllerName="Error"> 0161 <viewScriptFile forActionName="error" /> 0162 </viewControllerScriptsDirectory> 0163 </viewScriptsDirectory> 0164 <viewHelpersDirectory /> 0165 <viewFiltersDirectory enabled="false" /> 0166 </viewsDirectory> 0167 <bootstrapFile /> 0168 </applicationDirectory> 0169 <dataDirectory enabled="false"> 0170 <cacheDirectory enabled="false" /> 0171 <searchIndexesDirectory enabled="false" /> 0172 <localesDirectory enabled="false" /> 0173 <logsDirectory enabled="false" /> 0174 <sessionsDirectory enabled="false" /> 0175 <uploadsDirectory enabled="false" /> 0176 </dataDirectory> 0177 <docsDirectory> 0178 <file filesystemName="README.txt" defaultContentCallback="Zend_Tool_Project_Provider_Project::getDefaultReadmeContents"/> 0179 </docsDirectory> 0180 <libraryDirectory> 0181 <zfStandardLibraryDirectory enabled="false" /> 0182 </libraryDirectory> 0183 <publicDirectory> 0184 <publicStylesheetsDirectory enabled="false" /> 0185 <publicScriptsDirectory enabled="false" /> 0186 <publicImagesDirectory enabled="false" /> 0187 <publicIndexFile /> 0188 <htaccessFile /> 0189 </publicDirectory> 0190 <projectProvidersDirectory enabled="false" /> 0191 <temporaryDirectory enabled="false" /> 0192 <testsDirectory> 0193 <testPHPUnitConfigFile /> 0194 <testPHPUnitBootstrapFile /> 0195 <testApplicationDirectory> 0196 <testApplicationControllerDirectory> 0197 <testApplicationControllerFile filesystemName="IndexControllerTest.php" forControllerName="Index"> 0198 $testAction 0199 </testApplicationControllerFile> 0200 </testApplicationControllerDirectory> 0201 </testApplicationDirectory> 0202 <testLibraryDirectory /> 0203 </testsDirectory> 0204 </projectDirectory> 0205 </projectProfile> 0206 EOS; 0207 return $data; 0208 } 0209 0210 public static function getDefaultReadmeContents($caller = null) 0211 { 0212 $projectDirResource = $caller->getResource()->getProfile()->search('projectDirectory'); 0213 if ($projectDirResource) { 0214 $name = ltrim(strrchr($projectDirResource->getPath(), DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); 0215 $path = $projectDirResource->getPath() . '/public'; 0216 } else { 0217 $path = '/path/to/public'; 0218 } 0219 0220 return <<< EOS 0221 README 0222 ====== 0223 0224 This directory should be used to place project specfic documentation including 0225 but not limited to project notes, generated API/phpdoc documentation, or 0226 manual files generated or hand written. Ideally, this directory would remain 0227 in your development environment only and should not be deployed with your 0228 application to it's final production location. 0229 0230 0231 Setting Up Your VHOST 0232 ===================== 0233 0234 The following is a sample VHOST you might want to consider for your project. 0235 0236 <VirtualHost *:80> 0237 DocumentRoot "$path" 0238 ServerName $name.local 0239 0240 # This should be omitted in the production environment 0241 SetEnv APPLICATION_ENV development 0242 0243 <Directory "$path"> 0244 Options Indexes MultiViews FollowSymLinks 0245 AllowOverride All 0246 Order allow,deny 0247 Allow from all 0248 </Directory> 0249 0250 </VirtualHost> 0251 0252 EOS; 0253 } 0254 }