示例#1
0
文件: Project.php 项目: rexmac/zf2
 /**
  * create()
  *
  * @param string $path
  * @param string $nameOfProfile shortName=n
  * @param string $fileOfProfile shortName=f
  */
 public function create($path, $nameOfProfile = null, $fileOfProfile = null)
 {
     if ($path == null) {
         $path = getcwd();
     } else {
         $path = trim($path);
         if (!file_exists($path)) {
             $created = mkdir($path);
             if (!$created) {
                 throw new Client\Exception('Could not create requested project directory \'' . $path . '\'');
             }
         }
         $path = str_replace('\\', '/', realpath($path));
     }
     $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path);
     if ($profile !== false) {
         throw new Client\Exception('A project already exists here');
     }
     $profileData = null;
     if ($fileOfProfile != null && file_exists($fileOfProfile)) {
         $profileData = file_get_contents($fileOfProfile);
     }
     $storage = $this->_registry->getStorage();
     if ($profileData == '' && $nameOfProfile != null && $storage->isEnabled()) {
         $profileData = $storage->get('project/profiles/' . $nameOfProfile . '.xml');
     }
     if ($profileData == '') {
         $profileData = $this->_getDefaultProfile();
     }
     $newProfile = new ProjectProfile(array('projectDirectory' => $path, 'profileData' => $profileData));
     $newProfile->loadFromData();
     $response = $this->_registry->getResponse();
     $response->appendContent('Creating project at ' . $path);
     $response->appendContent('Note: ', array('separator' => false, 'color' => 'yellow'));
     $response->appendContent('This command created a web project, ' . 'for more information setting up your VHOST, please see docs/README');
     foreach ($newProfile->getIterator() as $resource) {
         $resource->create();
     }
 }
示例#2
0
 public function testProfileThrowsExceptionOnLoadFromData()
 {
     $profile = new Profile();
     // missing data from attributes should throw exception here
     $this->setExpectedException('Zend\\Tool\\Project\\Profile\\Exception\\RuntimeException');
     $profile->loadFromData();
 }