Sfoglia il codice sorgente

ZF-7260
- merged 1.9 Zend_Tool from incubator to trunk

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

ralph 16 anni fa
parent
commit
073ffc685b

+ 17 - 0
library/Zend/Tool/Framework/Client/Abstract.php

@@ -60,6 +60,23 @@ abstract class Zend_Tool_Framework_Client_Abstract implements Zend_Tool_Framewor
      */
     protected $_debugLogger = null;
     
+    public function __construct($options = array())
+    {
+        if ($options) {
+            $this->setOptions($options);
+        }
+    }
+    
+    public function setOptions(Array $options)
+    {
+        foreach ($options as $optionName => $optionValue) {
+            $setMethodName = 'set' . $optionName;
+            if (method_exists($this, $setMethodName)) {
+                $this->{$setMethodName}($optionValue);
+            }
+        }
+    }
+    
     /**
      * getName() - Return the client name which can be used to 
      * query the manifest if need be.

+ 105 - 0
library/Zend/Tool/Framework/Client/Config.php

@@ -0,0 +1,105 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Framework_Client_Config
+{
+    
+    protected $_configFilepath = null;
+    
+    /**
+     * @var Zend_Config
+     */
+    protected $_config = null;
+    
+    public function __config($options = array())
+    {
+        if ($options) {
+            $this->setOptions($options);
+        }
+    }
+    
+    public function setOptions(Array $options)
+    {
+        foreach ($options as $optionName => $optionValue) {
+            $setMethodName = 'set' . $optionName;
+            if (method_exists($this, $setMethodName)) {
+                $this->{$setMethodName}($optionValue);
+            }
+        }
+    }
+    
+    public function setConfigFilepath($configFilepath)
+    {
+        if (!file_exists($configFilepath)) {
+            require_once 'Zend/Tool/Framework/Client/Exception.php';
+            throw new Zend_Tool_Framework_Client_Exception('Provided path to config ' . $configFilepath . ' does not exist');
+        }
+
+        $this->_configFilepath = $configFilepath;
+        
+        $suffix = substr($configFilepath, -4);
+        
+        switch ($suffix) {
+            case '.ini':
+                require_once 'Zend/Config/Ini.php';
+                $this->_config = new Zend_Config_Ini($configFilepath);
+                break;
+            case '.xml':
+                require_once 'Zend/Config/Xml.php';
+                $this->_config = new Zend_Config_Xml($configFilepath);
+                break;
+            case '.php':
+                require_once 'Zend/Config.php';
+                $this->_config = new Zend_Config(include $configFilepath);
+                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;
+    }
+    
+    public function getConfigFilepath()
+    {
+        return $this->_configFilepath;
+    }
+    
+    public function get($name, $defaultValue)
+    {
+        return $this->_config->get($name, $defaultValue);
+    }
+    
+    public function __get($name)
+    {
+        return $this->_config->{$name};
+    }
+    
+}

+ 19 - 2
library/Zend/Tool/Framework/Client/Console.php

@@ -65,6 +65,11 @@ class Zend_Tool_Framework_Client_Console
 {
 
     /**
+     * @var string
+     */
+    protected $_configOptions = null;
+    
+    /**
      * @var Zend_Filter_Word_CamelCaseToDash
      */
     protected $_filterToClientNaming = null;
@@ -79,13 +84,19 @@ class Zend_Tool_Framework_Client_Console
      * self contained main() function.
      *
      */
-    public static function main()
+    public static function main($options = array())
     {
         ini_set('display_errors', true);
-        $cliClient = new self();
+        $cliClient = new self($options);
         $cliClient->dispatch();
     }
 
+    public function setConfigOptions($configOptions)
+    {
+        $this->_configOptions = $configOptions;
+        return $this;
+    }
+    
     /**
      * getName() - return the name of the client, in this case 'console'
      *
@@ -102,6 +113,12 @@ class Zend_Tool_Framework_Client_Console
      */
     protected function _preInit()
     {
+        $config = $this->_registry->getConfig();
+
+        if ($this->_configOptions != null) {
+            $config->setOptions($this->_configOptions);
+        }
+        
         // support the changing of the current working directory, necessary for some providers
         if (isset($_ENV['ZEND_TOOL_CURRENT_WORKING_DIRECTORY'])) {
             chdir($_ENV['ZEND_TOOL_CURRENT_WORKING_DIRECTORY']);

+ 104 - 0
library/Zend/Tool/Framework/Client/Storage.php

@@ -0,0 +1,104 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Tool_Framework_Client_Storage_AdapterInterface
+ */
+require_once 'Zend/Tool/Framework/Client/Storage/AdapterInterface.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Framework_Client_Storage
+{
+    
+    /**
+     * @var Zend_Tool_Framework_Client_Storage_AdapterInterface
+     */
+    protected $_adapter = null;
+    
+    public function __construct($options = array())
+    {
+        if (isset($options['adapter'])) {
+            $this->setAdapter($options['adapter']);
+        }
+    }
+    
+    public function setAdapter(Zend_Tool_Framework_Client_Storage_AdapterInterface $adapter)
+    {
+        $this->_adapter = $adapter;
+    }
+    
+    public function isEnabled()
+    {
+        return ($this->_adapter instanceof Zend_Tool_Framework_Client_Storage_AdapterInterface);
+    }
+    
+    public function put($name, $value)
+    {
+        if (!$this->_adapter) {
+            return false;
+        }
+        
+        $this->_adapter->put($name, $value);
+        
+        return $this;
+    }
+    
+    public function get($name, $defaultValue = false)
+    {
+        if (!$this->_adapter) {
+            return false;
+        }
+        
+        if ($this->_adapter->has($name)) {
+            return $this->_adapter->get($name);
+        } else {
+            return $defaultValue;
+        }
+
+    }
+    
+    public function has($name)
+    {
+        if (!$this->_adapter) {
+            return false;
+        }
+        
+        return $this->_adapter->has($name);
+    }
+    
+    public function remove($name)
+    {
+        if (!$this->_adapter) {
+            return false;
+        }
+        
+        $this->_adapter->remove($name);
+        
+        return $this;
+    }
+    
+}

+ 40 - 0
library/Zend/Tool/Framework/Client/Storage/AdapterInterface.php

@@ -0,0 +1,40 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+interface Zend_Tool_Framework_Client_Storage_AdapterInterface
+{
+    
+    public function put($name, $value);
+    
+    public function get($name);
+    
+    public function has($name);
+    
+    public function remove($name);
+    
+}

+ 64 - 0
library/Zend/Tool/Framework/Client/Storage/Directory.php

@@ -0,0 +1,64 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Tool
+ * @subpackage Framework
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Tool_Framework_Client_Storage_AdapterInterface
+ */
+require_once 'Zend/Tool/Framework/Client/Storage/AdapterInterface.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Tool
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Tool_Framework_Client_Storage_Directory
+{
+    
+    protected $_directoryPath = null;
+    
+    public function __construct($directoryPath)
+    {
+        $this->_directoryPath = $directoryPath;
+    }
+    
+    public function put($name, $value)
+    {
+        return file_put_contents($this->_directoryPath . DIRECTORY_SEPARATOR . $name, $value);
+    }
+    
+    public function get($name)
+    {
+        return file_get_contents($this->_directoryPath . DIRECTORY_SEPARATOR . $name);
+    }
+    
+    public function has($name)
+    {
+        return file_exists($this->_directoryPath . DIRECTORY_SEPARATOR . $name);
+    }
+    
+    public function remove($name)
+    {
+        return unlink($this->_directoryPath . DIRECTORY_SEPARATOR . $name);
+    }
+    
+}

+ 32 - 0
library/Zend/Tool/Framework/Registry.php

@@ -44,6 +44,11 @@ class Zend_Tool_Framework_Registry implements Zend_Tool_Framework_Registry_Inter
     protected $_client = null;
     
     /**
+     * @var Zend_Tool_Framework_Client_Config
+     */
+    protected $_config = null;
+    
+    /**
      * @var Zend_Tool_Framework_Action_Repository
      */
     protected $_actionRepository = null;
@@ -113,6 +118,33 @@ class Zend_Tool_Framework_Registry implements Zend_Tool_Framework_Registry_Inter
     }
     
     /**
+     * setConfig() 
+     *
+     * @param Zend_Tool_Framework_Client_Config $config
+     * @return Zend_Tool_Framework_Registry
+     */
+    public function setConfig(Zend_Tool_Framework_Client_Config $config)
+    {
+        $this->_config = $config;
+        return $this;
+    }
+    
+    /**
+     * getConfig()
+     *
+     * @return Zend_Tool_Framework_Client_Config
+     */
+    public function getConfig()
+    {
+        if ($this->_config === null) {
+            require_once 'Zend/Tool/Framework/Client/Config.php';
+            $this->setConfig(new Zend_Tool_Framework_Client_Config());
+        }
+        
+        return $this->_config;
+    }
+    
+    /**
      * setLoader() 
      *
      * @param Zend_Tool_Framework_Loader_Abstract $loader