/** * _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 bool $loadProfileFlag Whether or not to throw an exception when no profile is found * @param string $projectDirectory The project directory to use to search * @param bool $searchParentDirectories Whether or not to search upper level direcotries * @return Zend_Tool_Project_Profile */ protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null, $searchParentDirectories = true) { $foundPath = $this->_findProfileDirectory($projectDirectory, $searchParentDirectories); if ($foundPath == false) { if ($loadProfileFlag == self::NO_PROFILE_THROW_EXCEPTION) { throw new Zend_Tool_Project_Provider_Exception('A project profile was not found.'); } else { return false; } } $profile = new Zend_Tool_Project_Profile(); $profile->setAttribute('projectDirectory', $foundPath); $profile->loadFromFile(); $this->_loadedProfile = $profile; return $profile; }
/** * _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 */ 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 Zend_Tool_Project_Provider_Exception('The $projectDirectory supplied does not exist.'); } $profile = new Zend_Tool_Project_Profile(); $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 Zend_Tool_Project_Provider_Exception('A project profile was not found.'); } elseif ($loadProfileFlag == self::NO_PROFILE_RETURN_FALSE) { return false; } } return $profile; }
/** * * @expectedException Zend_Tool_Project_Exception */ public function testProfileThrowsExceptionOnLoadFromFileWithBadPathForProfileFile() { $profile = new Zend_Tool_Project_Profile(); $profile->setAttribute('projectProfileFile', '/path/should/not/exist'); // missing file path or project path $profile->loadFromFile(); }
/** * _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 * * @ * @return Zend_Tool_Project_Profile */ protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null) { if ($projectDirectory == null) { $projectDirectory = getcwd(); } $profile = new Zend_Tool_Project_Profile(); $profile->setAttribute('projectDirectory', $projectDirectory); if ($profile->isLoadableFromFile()) { $profile->loadFromFile(); $this->_loadedProfile = $profile; } if ($this->_loadedProfile == null) { if ($loadProfileFlag == self::NO_PROFILE_THROW_EXCEPTION) { throw new Zend_Tool_Project_Provider_Exception('A project profile was not found.'); } elseif ($loadProfileFlag == self::NO_PROFILE_RETURN_FALSE) { return false; } } return $profile; }