|
|
@@ -45,13 +45,17 @@ require_once 'Zend/Tool/Project/Profile/FileParser/Xml.php';
|
|
|
*/
|
|
|
require_once 'Zend/Tool/Framework/Registry.php';
|
|
|
|
|
|
+require_once 'Zend/Tool/Framework/Provider/Initializable.php';
|
|
|
+
|
|
|
/**
|
|
|
* @category Zend
|
|
|
* @package Zend_Tool
|
|
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
*/
|
|
|
-abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_Provider_Abstract
|
|
|
+abstract class Zend_Tool_Project_Provider_Abstract
|
|
|
+ extends Zend_Tool_Framework_Provider_Abstract
|
|
|
+ implements Zend_Tool_Framework_Provider_Initializable
|
|
|
{
|
|
|
|
|
|
const NO_PROFILE_THROW_EXCEPTION = true;
|
|
|
@@ -69,16 +73,12 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
*/
|
|
|
protected $_loadedProfile = null;
|
|
|
|
|
|
- /**
|
|
|
- * constructor
|
|
|
- *
|
|
|
- * YOU SHOULD NOT OVERRIDE THIS, unless you know what you are doing
|
|
|
- *
|
|
|
- */
|
|
|
- public function __construct()
|
|
|
+ public function initialize()
|
|
|
{
|
|
|
// initialize the ZF Contexts (only once per php request)
|
|
|
if (!self::$_isInitialized) {
|
|
|
+
|
|
|
+ // load all base contexts ONCE
|
|
|
$contextRegistry = Zend_Tool_Project_Context_Repository::getInstance();
|
|
|
$contextRegistry->addContextsFromDirectory(
|
|
|
dirname(dirname(__FILE__)) . '/Context/Zf/', 'Zend_Tool_Project_Context_Zf_'
|
|
|
@@ -86,6 +86,16 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
$contextRegistry->addContextsFromDirectory(
|
|
|
dirname(dirname(__FILE__)) . '/Context/Filesystem/', 'Zend_Tool_Project_Context_Filesystem_'
|
|
|
);
|
|
|
+
|
|
|
+ // determine if there are project specfic providers ONCE
|
|
|
+ $profilePath = $this->_findProfileDirectory();
|
|
|
+ if ($this->_hasProjectProviderDirectory($profilePath . DIRECTORY_SEPARATOR . '.zfproject.xml')) {
|
|
|
+ $profile = $this->_loadProfile();
|
|
|
+ // project providers directory resource
|
|
|
+ $ppd = $profile->search('ProjectProvidersDirectory');
|
|
|
+ $ppd->loadProviders($this->_registry);
|
|
|
+ }
|
|
|
+
|
|
|
self::$_isInitialized = true;
|
|
|
}
|
|
|
|
|
|
@@ -115,6 +125,25 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
*/
|
|
|
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;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _findProfileDirectory($projectDirectory = null, $searchParentDirectories = true)
|
|
|
+ {
|
|
|
// use the cwd if no directory was provided
|
|
|
if ($projectDirectory == null) {
|
|
|
$projectDirectory = getcwd();
|
|
|
@@ -134,13 +163,10 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
|
|
|
$profile->setAttribute('projectDirectory', $projectDirectoryAssembled);
|
|
|
if ($profile->isLoadableFromFile()) {
|
|
|
- chdir($projectDirectoryAssembled);
|
|
|
-
|
|
|
- $profile->loadFromFile();
|
|
|
- $this->_loadedProfile = $profile;
|
|
|
- break;
|
|
|
+ unset($profile);
|
|
|
+ return $projectDirectoryAssembled;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// break after first run if we are not to check upper directories
|
|
|
if ($searchParentDirectories == false) {
|
|
|
break;
|
|
|
@@ -148,18 +174,10 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
|
|
|
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;
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Load the project profile from the current working directory, if not throw exception
|
|
|
*
|
|
|
@@ -223,6 +241,23 @@ abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_P
|
|
|
return $engine->getContent($context, $methodName, $parameters);
|
|
|
}
|
|
|
|
|
|
+ protected function _hasProjectProviderDirectory($pathToProfileFile)
|
|
|
+ {
|
|
|
+ // do some static analysis of the file so that we cna determin whether or not to incure
|
|
|
+ // the cost of loading the profile before the system is fully bootstrapped
|
|
|
+
|
|
|
+ $contents = file_get_contents($pathToProfileFile);
|
|
|
+ if (strstr($contents, '<projectProvidersDirectory') === false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strstr($contents, '<projectProvidersDirectory enabled="false"')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* _loadContextClassesIntoRegistry() - This is called by the constructor
|
|
|
* so that child providers can provide a list of contexts to load into the
|