Bladeren bron

ZF-6276
- Project loader will check parent directories for exiting project to find project profile

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16345 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 16 jaren geleden
bovenliggende
commit
01566341c8

+ 2 - 0
library/Zend/Tool/Project/Profile.php

@@ -165,12 +165,14 @@ class Zend_Tool_Project_Profile extends Zend_Tool_Project_Profile_Resource_Conta
                 require_once 'Zend/Tool/Project/Exception.php';
                 throw new Zend_Tool_Project_Exception('"projectProfileFile" was supplied but file was not found at location ' . $projectProfileFilePath);
             }
+            $this->_attributes['projectDirectory'] = dirname($projectProfileFilePath);
         } else {
             $projectProfileFilePath = rtrim($this->_attributes['projectDirectory'], '/\\') . '/.zfproject.xml';
             if (!file_exists($projectProfileFilePath)) {
                 require_once 'Zend/Tool/Project/Exception.php';
                 throw new Zend_Tool_Project_Exception('"projectDirectory" was supplied but no profile file file was not found at location ' . $projectProfileFilePath);
             }
+            $this->_attributes['projectProfileFile'] = $projectProfileFilePath;
         }
 
         $profileData = file_get_contents($projectProfileFilePath);

+ 28 - 10
library/Zend/Tool/Project/Provider/Abstract.php

@@ -105,25 +105,43 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
      *    - 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)
+    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();
-        $profile->setAttribute('projectDirectory', $projectDirectory);
-
-        if ($profile->isLoadableFromFile()) {
-            $profile->loadFromFile();
-            $this->_loadedProfile = $profile;
+        
+        $parentDirectoriesArray = split(DIRECTORY_SEPARATOR, ltrim($projectDirectory, DIRECTORY_SEPARATOR));
+        while ($parentDirectoriesArray) {
+            $projectDirectoryAssembled = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parentDirectoriesArray);
+            
+            $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.');

+ 17 - 0
library/Zend/Tool/Project/Provider/Project.php

@@ -34,6 +34,8 @@ require_once 'Zend/Tool/Project/Provider/Abstract.php';
 class Zend_Tool_Project_Provider_Project extends Zend_Tool_Project_Provider_Abstract
 {
 
+    protected $_specialties = array('Info');
+    
     /**
      * create()
      *
@@ -75,6 +77,21 @@ class Zend_Tool_Project_Provider_Project extends Zend_Tool_Project_Provider_Abst
             $resource->create();
         }
     }
+    
+    public function show()
+    {
+        $this->_registry->getResponse()->appendContent('You probably meant to run "show project.info".', array('color' => 'yellow'));
+    }
+    
+    public function showInfo()
+    {
+        $profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE);
+        if (!$profile) {
+            $this->_registry->getResponse()->appendContent('No project found.');
+        } else {
+            $this->_registry->getResponse()->appendContent('Working with project located at: ' . $profile->getAttribute('projectDirectory'));
+        }
+    }
 
     protected function _getDefaultProfile()
     {