web/lib/Zend/Tool/Project/Provider/Abstract.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Tool
    16  * @package    Zend_Tool
    17  * @subpackage Framework
    17  * @subpackage Framework
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Abstract.php 23202 2010-10-21 15:08:15Z ralph $
    20  * @version    $Id: Abstract.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_Tool_Project_Profile
    24  * @see Zend_Tool_Project_Profile
    25  */
    25  */
    48 require_once 'Zend/Tool/Framework/Provider/Initializable.php';
    48 require_once 'Zend/Tool/Framework/Provider/Initializable.php';
    49 
    49 
    50 /**
    50 /**
    51  * @category   Zend
    51  * @category   Zend
    52  * @package    Zend_Tool
    52  * @package    Zend_Tool
    53  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    53  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    54  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    54  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    55  */
    55  */
    56 abstract class Zend_Tool_Project_Provider_Abstract
    56 abstract class Zend_Tool_Project_Provider_Abstract
    57     extends Zend_Tool_Framework_Provider_Abstract
    57     extends Zend_Tool_Framework_Provider_Abstract
    58     implements Zend_Tool_Framework_Provider_Initializable
    58     implements Zend_Tool_Framework_Provider_Initializable
    75 
    75 
    76     public function initialize()
    76     public function initialize()
    77     {
    77     {
    78         // initialize the ZF Contexts (only once per php request)
    78         // initialize the ZF Contexts (only once per php request)
    79         if (!self::$_isInitialized) {
    79         if (!self::$_isInitialized) {
    80             
    80 
    81             // load all base contexts ONCE
    81             // load all base contexts ONCE
    82             $contextRegistry = Zend_Tool_Project_Context_Repository::getInstance();
    82             $contextRegistry = Zend_Tool_Project_Context_Repository::getInstance();
    83             $contextRegistry->addContextsFromDirectory(
    83             $contextRegistry->addContextsFromDirectory(
    84                 dirname(dirname(__FILE__)) . '/Context/Zf/', 'Zend_Tool_Project_Context_Zf_'
    84                 dirname(dirname(__FILE__)) . '/Context/Zf/', 'Zend_Tool_Project_Context_Zf_'
    85             );
    85             );
    86             $contextRegistry->addContextsFromDirectory(
    86             $contextRegistry->addContextsFromDirectory(
    87                 dirname(dirname(__FILE__)) . '/Context/Filesystem/', 'Zend_Tool_Project_Context_Filesystem_'
    87                 dirname(dirname(__FILE__)) . '/Context/Filesystem/', 'Zend_Tool_Project_Context_Filesystem_'
    88             );
    88             );
    89             
    89 
    90             // determine if there are project specfic providers ONCE
    90             // determine if there are project specfic providers ONCE
    91             $profilePath = $this->_findProfileDirectory();
    91             $profilePath = $this->_findProfileDirectory();
    92             if ($this->_hasProjectProviderDirectory($profilePath . DIRECTORY_SEPARATOR . '.zfproject.xml')) {
    92             if ($this->_hasProjectProviderDirectory($profilePath . DIRECTORY_SEPARATOR . '.zfproject.xml')) {
    93                 $profile = $this->_loadProfile();
    93                 $profile = $this->_loadProfile();
    94                 // project providers directory resource
    94                 // project providers directory resource
    95                 $ppd = $profile->search('ProjectProvidersDirectory');
    95                 $ppd = $profile->search('ProjectProvidersDirectory');
    96                 $ppd->loadProviders($this->_registry);
    96                 $ppd->loadProviders($this->_registry);
    97             }
    97             }
    98             
    98 
    99             self::$_isInitialized = true;
    99             self::$_isInitialized = true;
   100         }
   100         }
   101 
   101 
   102         // load up the extending providers required context classes
   102         // load up the extending providers required context classes
   103         if ($contextClasses = $this->getContextClasses()) {
   103         if ($contextClasses = $this->getContextClasses()) {
   116      * the client has been called from..   The search order is as follows..
   116      * the client has been called from..   The search order is as follows..
   117      *    - traversing downwards from (PWD) - current working directory
   117      *    - traversing downwards from (PWD) - current working directory
   118      *    - if an enpoint variable has been registered in teh client registry - key=workingDirectory
   118      *    - if an enpoint variable has been registered in teh client registry - key=workingDirectory
   119      *    - if an ENV variable with the key ZFPROJECT_PATH is found
   119      *    - if an ENV variable with the key ZFPROJECT_PATH is found
   120      *
   120      *
   121      * @param $loadProfileFlag bool Whether or not to throw an exception when no profile is found
   121      * @param bool   $loadProfileFlag         Whether or not to throw an exception when no profile is found
   122      * @param $projectDirectory string The project directory to use to search
   122      * @param string $projectDirectory        The project directory to use to search
   123      * @param $searchParentDirectories bool Whether or not to search upper level direcotries
   123      * @param bool   $searchParentDirectories Whether or not to search upper level direcotries
   124      * @return Zend_Tool_Project_Profile
   124      * @return Zend_Tool_Project_Profile
   125      */
   125      */
   126     protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null, $searchParentDirectories = true)
   126     protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null, $searchParentDirectories = true)
   127     {
   127     {
   128         $foundPath = $this->_findProfileDirectory($projectDirectory, $searchParentDirectories);
   128         $foundPath = $this->_findProfileDirectory($projectDirectory, $searchParentDirectories);
   132                 throw new Zend_Tool_Project_Provider_Exception('A project profile was not found.');
   132                 throw new Zend_Tool_Project_Provider_Exception('A project profile was not found.');
   133             } else {
   133             } else {
   134                 return false;
   134                 return false;
   135             }
   135             }
   136         }
   136         }
   137         
   137 
   138         $profile = new Zend_Tool_Project_Profile();
   138         $profile = new Zend_Tool_Project_Profile();
   139         $profile->setAttribute('projectDirectory', $foundPath);
   139         $profile->setAttribute('projectDirectory', $foundPath);
   140         $profile->loadFromFile();
   140         $profile->loadFromFile();
   141         $this->_loadedProfile = $profile;
   141         $this->_loadedProfile = $profile;
   142         return $profile;
   142         return $profile;
   143     }
   143     }
   144     
   144 
   145     protected function _findProfileDirectory($projectDirectory = null, $searchParentDirectories = true)
   145     protected function _findProfileDirectory($projectDirectory = null, $searchParentDirectories = true)
   146     {
   146     {
   147         // use the cwd if no directory was provided
   147         // use the cwd if no directory was provided
   148         if ($projectDirectory == null) {
   148         if ($projectDirectory == null) {
   149             $projectDirectory = getcwd();
   149             $projectDirectory = getcwd();
   164             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
   164             $profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
   165             if ($profile->isLoadableFromFile()) {
   165             if ($profile->isLoadableFromFile()) {
   166                 unset($profile);
   166                 unset($profile);
   167                 return $projectDirectoryAssembled;
   167                 return $projectDirectoryAssembled;
   168             }
   168             }
   169             
   169 
   170             // break after first run if we are not to check upper directories
   170             // break after first run if we are not to check upper directories
   171             if ($searchParentDirectories == false) {
   171             if ($searchParentDirectories == false) {
   172                 break;
   172                 break;
   173             }
   173             }
   174 
   174 
   175             array_pop($parentDirectoriesArray);
   175             array_pop($parentDirectoriesArray);
   176         }
   176         }
   177         
   177 
   178         return false;
   178         return false;
   179     }
   179     }
   180     
   180 
   181     /**
   181     /**
   182      * Load the project profile from the current working directory, if not throw exception
   182      * Load the project profile from the current working directory, if not throw exception
   183      *
   183      *
   184      * @return Zend_Tool_Project_Profile
   184      * @return Zend_Tool_Project_Profile
   185      */
   185      */
   246         // do some static analysis of the file so that we can determin whether or not to incure
   246         // do some static analysis of the file so that we can determin whether or not to incure
   247         // the cost of loading the profile before the system is fully bootstrapped
   247         // the cost of loading the profile before the system is fully bootstrapped
   248         if (!file_exists($pathToProfileFile)) {
   248         if (!file_exists($pathToProfileFile)) {
   249             return false;
   249             return false;
   250         }
   250         }
   251         
   251 
   252         $contents = file_get_contents($pathToProfileFile);
   252         $contents = file_get_contents($pathToProfileFile);
   253         if (strstr($contents, '<projectProvidersDirectory') === false) {
   253         if (strstr($contents, '<projectProvidersDirectory') === false) {
   254             return false;
   254             return false;
   255         }
   255         }
   256         
   256 
   257         if (strstr($contents, '<projectProvidersDirectory enabled="false"')) {
   257         if (strstr($contents, '<projectProvidersDirectory enabled="false"')) {
   258             return false;
   258             return false;
   259         }
   259         }
   260         
   260 
   261         return true;
   261         return true;
   262     }
   262     }
   263     
   263 
   264     /**
   264     /**
   265      * _loadContextClassesIntoRegistry() - This is called by the constructor
   265      * _loadContextClassesIntoRegistry() - This is called by the constructor
   266      * so that child providers can provide a list of contexts to load into the
   266      * so that child providers can provide a list of contexts to load into the
   267      * context repository
   267      * context repository
   268      *
   268      *