コード例 #1
0
 protected function _findProfileDirectory($projectDirectory = null, $searchParentDirectories = true)
 {
     // use the cwd if no directory was provided
     if ($projectDirectory == null) {
         $projectDirectory = getcwd();
     } elseif (realpath($projectDirectory) == false) {
         throw new Exception\InvalidArgumentException('The $projectDirectory supplied does not exist.');
     }
     $profile = new ProjectProfile();
     $parentDirectoriesArray = explode(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
     while ($parentDirectoriesArray) {
         $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
         if (DIRECTORY_SEPARATOR !== "\\") {
             $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
         }
         $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
         if ($profile->isLoadableFromFile()) {
             unset($profile);
             return $projectDirectoryAssembled;
         }
         // break after first run if we are not to check upper directories
         if ($searchParentDirectories == false) {
             break;
         }
         array_pop($parentDirectoriesArray);
     }
     return false;
 }
コード例 #2
0
ファイル: ProfileTest.php プロジェクト: rafalwrzeszcz/zf2
 public function testProfileFromVariousSourcesIsLoadableFromFile()
 {
     $profile = new Profile();
     // no options, should return false
     $this->assertFalse($profile->isLoadableFromFile());
     // invalid file path, should be false
     $profile->setAttribute('projectProfileFile', $this->_projectProfileFile . '.invalid-file');
     $this->assertFalse($profile->isLoadableFromFile());
     // valid file path, shoudl be true
     $profile->setAttribute('projectProfileFile', $this->_projectProfileFile);
     $this->assertTrue($profile->isLoadableFromFile());
     // just project directory
     $profile = new Profile();
     // shoudl be false with non existent directory
     $profile->setAttribute('projectDirectory', $this->_projectDirectory . 'non-existent/dir/');
     $this->assertFalse($profile->isLoadableFromFile());
     // should return true for proper directory
     copy($this->_projectProfileFile, $this->_projectDirectory . '/.zfproject.xml');
     $profile->setAttribute('projectDirectory', $this->_projectDirectory);
     $this->assertTrue($profile->isLoadableFromFile());
 }
コード例 #3
0
ファイル: AbstractProvider.php プロジェクト: rexmac/zf2
 /**
  * _getProject is designed to find if there is project file in the context of where
  * the client has been called from..   The search order is as follows..
  *    - traversing downwards from (PWD) - current working directory
  *    - if an enpoint variable has been registered in teh client registry - key=workingDirectory
  *    - if an ENV variable with the key ZFPROJECT_PATH is found
  *
  * @param $loadProfileFlag bool Whether or not to throw an exception when no profile is found
  * @param $projectDirectory string The project directory to use to search
  * @param $searchParentDirectories bool Whether or not to search upper level direcotries
  * @return \Zend\Tool\Project\Profile\Profile
  */
 protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null, $searchParentDirectories = true)
 {
     // use the cwd if no directory was provided
     if ($projectDirectory == null) {
         $projectDirectory = getcwd();
     } elseif (realpath($projectDirectory) == false) {
         throw new Exception\InvalidArgumentException('The $projectDirectory supplied does not exist.');
     }
     $profile = new ProjectProfile();
     $parentDirectoriesArray = explode(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
     while ($parentDirectoriesArray) {
         $projectDirectoryAssembled = implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
         if (DIRECTORY_SEPARATOR !== "\\") {
             $projectDirectoryAssembled = DIRECTORY_SEPARATOR . $projectDirectoryAssembled;
         }
         $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
         if ($profile->isLoadableFromFile()) {
             chdir($projectDirectoryAssembled);
             $profile->loadFromFile();
             $this->_loadedProfile = $profile;
             break;
         }
         // break after first run if we are not to check upper directories
         if ($searchParentDirectories == false) {
             break;
         }
         array_pop($parentDirectoriesArray);
     }
     if ($this->_loadedProfile == null) {
         if ($loadProfileFlag == self::NO_PROFILE_THROW_EXCEPTION) {
             throw new Exception\RuntimeException('A project profile was not found.');
         } elseif ($loadProfileFlag == self::NO_PROFILE_RETURN_FALSE) {
             return false;
         }
     }
     return $profile;
 }