Skip to content

Commit

Permalink
ZF-7940
Browse files Browse the repository at this point in the history
- Remerging Zend_Tool 1.10 feature from incubator to trunk.


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19525 44c647ce-9c0f-0410-b52a-842ac1e357ba
  • Loading branch information
ralph committed Dec 8, 2009
1 parent 9a3bc47 commit e81cedb
Show file tree
Hide file tree
Showing 51 changed files with 2,894 additions and 359 deletions.
679 changes: 540 additions & 139 deletions bin/zf.php

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion bin/zf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ else
PHP_DIR="$(dirname "$SELF_LINK")"
fi

"$PHP_BIN" -d safe_mode=Off -f "$PHP_DIR/zf.php" -- $@
"$PHP_BIN" -d safe_mode=Off -f "$PHP_DIR/zf.php" -- "$@"

53 changes: 36 additions & 17 deletions library/Zend/Tool/Framework/Client/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
*/

/**
* @see Zend_Tool_Framework_Registry_EnabledInterface
* @see Zend_Loader_Autoloader
*/
require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
require_once 'Zend/Loader/Autoloader.php';

/**
* @see Zend_Tool_Framework_Registry
* @see Zend_Tool_Framework_Registry_EnabledInterface
*/
require_once 'Zend/Tool/Framework/Registry.php';

require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';

/**
* @category Zend
Expand Down Expand Up @@ -62,6 +61,16 @@ abstract class Zend_Tool_Framework_Client_Abstract implements Zend_Tool_Framewor

public function __construct($options = array())
{
// require autoloader
Zend_Loader_Autoloader::getInstance();

// this might look goofy, but this is setting up the
// registry for dependency injection into the client
$registry = new Zend_Tool_Framework_Registry();
$registry->setClient($this);

// NOTE: at this moment, $this->_registry should contain the registry object

if ($options) {
$this->setOptions($options);
}
Expand Down Expand Up @@ -96,17 +105,12 @@ public function initialize()
return;
}

// this might look goofy, but this is setting up the
// registry for dependency injection into the client
$registry = new Zend_Tool_Framework_Registry();
$registry->setClient($this);

// NOTE: at this moment, $this->_registry should contain
// the registry object

// run any preInit
$this->_preInit();

$manifest = $this->_registry->getManifestRepository();
$manifest->addManifest(new Zend_Tool_Framework_Client_Manifest());

// setup the debug log
if (!$this->_debugLogger instanceof Zend_Log) {
require_once 'Zend/Log.php';
Expand Down Expand Up @@ -173,6 +177,16 @@ public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
$this->_registry = $registry;
return $this;
}

/**
* getRegistry();
*
* @return Zend_Tool_Framework_Registry_Interface
*/
public function getRegistry()
{
return $this->_registry;
}

/**
* hasInteractiveInput() - Convienence method for determining if this
Expand Down Expand Up @@ -304,10 +318,15 @@ protected function _handleDispatch()
$methodName .= $specialtyName;
}

if (method_exists($provider, $methodName)) {
call_user_func_array(array($provider, $methodName), $callParameters);
} elseif (method_exists($provider, $methodName . 'Action')) {
call_user_func_array(array($provider, $methodName . 'Action'), $callParameters);
$this->_handleDispatchExecution($provider, $methodName, $callParameters);
}

protected function _handleDispatchExecution($class, $methodName, $callParameters)
{
if (method_exists($class, $methodName)) {
call_user_func_array(array($class, $methodName), $callParameters);
} elseif (method_exists($class, $methodName . 'Action')) {
call_user_func_array(array($class, $methodName . 'Action'), $callParameters);
} else {
require_once 'Zend/Tool/Framework/Client/Exception.php';
throw new Zend_Tool_Framework_Client_Exception('Not a supported method.');
Expand Down
155 changes: 147 additions & 8 deletions library/Zend/Tool/Framework/Client/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ class Zend_Tool_Framework_Client_Config
*/
protected $_config = null;

/**
* @param array $options
*/
public function __config($options = array())
{
if ($options) {
$this->setOptions($options);
}
}

/**
* @param array $options
*/
public function setOptions(Array $options)
{
foreach ($options as $optionName => $optionValue) {
Expand All @@ -53,6 +59,10 @@ public function setOptions(Array $options)
}
}

/**
* @param string $configFilepath
* @return Zend_Tool_Framework_Client_Config
*/
public function setConfigFilepath($configFilepath)
{
if (!file_exists($configFilepath)) {
Expand All @@ -61,45 +71,174 @@ public function setConfigFilepath($configFilepath)
}

$this->_configFilepath = $configFilepath;
$this->loadConfig($configFilepath);

return $this;
}

/**
* Load the configuration from the given path.
*
* @param string $configFilepath
*/
protected function loadConfig($configFilepath)
{
$suffix = substr($configFilepath, -4);

switch ($suffix) {
case '.ini':
require_once 'Zend/Config/Ini.php';
$this->_config = new Zend_Config_Ini($configFilepath);
$this->_config = new Zend_Config_Ini($configFilepath, null, array('allowModifications' => true));
break;
case '.xml':
require_once 'Zend/Config/Xml.php';
$this->_config = new Zend_Config_Xml($configFilepath);
$this->_config = new Zend_Config_Xml($configFilepath, null, array('allowModifications' => true));
break;
case '.php':
require_once 'Zend/Config.php';
$this->_config = new Zend_Config(include $configFilepath);
$this->_config = new Zend_Config(include $configFilepath, true);
break;
default:
require_once 'Zend/Tool/Framework/Client/Exception.php';
throw new Zend_Tool_Framework_Client_Exception('Unknown config file type '
. $suffix . ' at location ' . $configFilepath
);
}

return $this;
}

/**
* Return the filepath of the configuration.
*
* @return string
*/
public function getConfigFilepath()
{
return $this->_configFilepath;
}

public function get($name, $defaultValue)
/**
* Get a configuration value.
*
* @param string $name
* @param string $defaultValue
* @return mixed
*/
public function get($name, $defaultValue=null)
{
return $this->_config->get($name, $defaultValue);
return $this->getConfigInstance()->get($name, $defaultValue);
}

/**
* Get a configuration value
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
return $this->_config->{$name};
return $this->getConfigInstance()->{$name};
}

/**
* Check if a configuration value isset.
*
* @param string $name
* @return boolean
*/
public function __isset($name)
{
if($this->exists() == false) {
return false;
}
return isset($this->getConfigInstance()->{$name});
}

/**
* @param string $name
*/
public function __unset($name)
{
unset($this->getConfigInstance()->$name);
}

/**
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
return $this->getConfigInstance()->$name = $value;
}

/**
* Check if the User profile has a configuration.
*
* @return bool
*/
public function exists()
{
return ($this->_config!==null);
}

/**
* @throws Zend_Tool_Framework_Client_Exception
* @return Zend_Config
*/
public function getConfigInstance()
{
if(!$this->exists()) {
require_once "Zend/Tool/Framework/Client/Exception.php";
throw new Zend_Tool_Framework_Client_Exception("Client has no persistent configuration.");
}

return $this->_config;
}

/**
* Save changes to the configuration into persistence.
*
* @return bool
*/
public function save()
{
if($this->exists()) {
$writer = $this->getConfigWriter();
$writer->write($this->getConfigFilepath(), $this->getConfigInstance(), true);
$this->loadConfig($this->getConfigFilepath());

return true;
}
return false;
}

/**
* Get the config writer that corresponds to the current config file type.
*
* @return Zend_Config_Writer_FileAbstract
*/
protected function getConfigWriter()
{
$suffix = substr($this->getConfigFilepath(), -4);
switch($suffix) {
case '.ini':
require_once "Zend/Config/Writer/Ini.php";
$writer = new Zend_Config_Writer_Ini();
$writer->setRenderWithoutSections();
break;
case '.xml':
require_once "Zend/Config/Writer/Xml.php";
$writer = new Zend_Config_Writer_Xml();
break;
case '.php':
require_once "Zend/Config/Writer/Array.php";
$writer = new Zend_Config_Writer_Array();
break;
default:
require_once 'Zend/Tool/Framework/Client/Exception.php';
throw new Zend_Tool_Framework_Client_Exception('Unknown config file type '
. $suffix . ' at location ' . $this->getConfigFilepath()
);
}
return $writer;
}
}
Loading

0 comments on commit e81cedb

Please sign in to comment.