text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Tool.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Framework_Metadata_Basic
 */
require_once 'Zend/Tool/Framework/Metadata/Basic.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Metadata_Tool extends Zend_Tool_Framework_Metadata_Basic
{

    /**
     * @var string
     */
    protected $_type = 'Tool';

    /**#@+
     * @var string
     */
    protected $_clientName    = null;
    protected $_actionName    = null;
    protected $_providerName  = null;
    protected $_specialtyName = null;
    /**#@-*/

    /**#@+
     * @var string
     */
    protected $_clientReference = null;
    protected $_actionReference = null;
    protected $_providerReference = null;
    /**#@-*/

    public function setClientName($clientName)
    {
        $this->_clientName = $clientName;
        return $this;
    }

    public function getClientName()
    {
        return $this->_clientName;
    }

    /**
     * setActionName()
     *
     * @param string $actionName
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setActionName($actionName)
    {
        $this->_actionName = $actionName;
        return $this;
    }

    /**
     * getActionName()
     *
     * @return string
     */
    public function getActionName()
    {
        return $this->_actionName;
    }

    /**
     * setProviderName()
     *
     * @param string $providerName
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setProviderName($providerName)
    {
        $this->_providerName = $providerName;
        return $this;
    }

    /**
     * getProviderName()
     *
     * @return string
     */
    public function getProviderName()
    {
        return $this->_providerName;
    }

    /**
     * setSpecialtyName()
     *
     * @param string $specialtyName
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setSpecialtyName($specialtyName)
    {
        $this->_specialtyName = $specialtyName;
        return $this;
    }

    /**
     * getSpecialtyName()
     *
     * @return string
     */
    public function getSpecialtyName()
    {
        return $this->_specialtyName;
    }

    /**
     * setClientReference()
     *
     * @param Zend_Tool_Framework_Client_Abstract $client
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setClientReference(Zend_Tool_Framework_Client_Abstract $client)
    {
        $this->_clientReference = $client;
        return $this;
    }

    /**
     * getClientReference()
     *
     * @return Zend_Tool_Framework_Client_Abstract
     */
    public function getClientReference()
    {
        return $this->_clientReference;
    }

    /**
     * setActionReference()
     *
     * @param Zend_Tool_Framework_Action_Interface $action
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setActionReference(Zend_Tool_Framework_Action_Interface $action)
    {
        $this->_actionReference = $action;
        return $this;
    }

    /**
     * getActionReference()
     *
     * @return Zend_Tool_Framework_Action_Interface
     */
    public function getActionReference()
    {
        return $this->_actionReference;
    }

    /**
     * setProviderReference()
     *
     * @param Zend_Tool_Framework_Provider_Interface $provider
     * @return Zend_Tool_Framework_Metadata_Tool
     */
    public function setProviderReference(Zend_Tool_Framework_Provider_Interface $provider)
    {
        $this->_providerReference = $provider;
        return $this;
    }

    /**
     * getProviderReference()
     *
     * @return Zend_Tool_Framework_Provider_Interface
     */
    public function getProviderReference()
    {
        return $this->_providerReference;
    }

    /**
     * __toString() cast to string
     *
     * @return string
     */
    public function __toString()
    {
        $string = parent::__toString();
        $string .= ' (ProviderName: ' . $this->_providerName
             . ', ActionName: '     . $this->_actionName
             . ', SpecialtyName: '  . $this->_specialtyName
             . ')';

        return $string;
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Basic.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Framework_Metadata_Interface
 */
require_once 'Zend/Tool/Framework/Metadata/Interface.php';

/**
 * @see Zend_Tool_Framework_Metadata_Attributable
 */
require_once 'Zend/Tool/Framework/Metadata/Attributable.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Metadata_Basic
    implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable
{

    /**#@+
     * Search constants
     */
    const ATTRIBUTES_ALL        = 'attributesAll';
    const ATTRIBUTES_NO_PARENT  = 'attributesParent';
    /**#@-*/

    /**#@+
     * @var string
     */
    protected $_type        = 'Basic';
    protected $_name        = null;
    protected $_value       = null;
    /**#@-*/

    /**
     * @var mixed
     */
    protected $_reference   = null;

    /**
     * Constructor - allows for the setting of options
     *
     * @param array $options
     */
    public function __construct(Array $options = array())
    {
        if ($options) {
            $this->setOptions($options);
        }
    }

    /**
     * setOptions() - standard issue implementation, this will set any
     * options that are supported via a set method.
     *
     * @param array $options
     * @return Zend_Tool_Framework_Metadata_Basic
     */
    public function setOptions(Array $options)
    {
        foreach ($options as $optionName => $optionValue) {
            $setMethod = 'set' . $optionName;
            if (method_exists($this, $setMethod)) {
                $this->{$setMethod}($optionValue);
            }
        }

        return $this;
    }

    /**
     * getType()
     *
     * @return string
     */
    public function getType()
    {
        return $this->_type;
    }

    /**
     * setType()
     *
     * @param string $type
     * @return Zend_Tool_Framework_Metadata_Basic
     */
    public function setType($type)
    {
        $this->_type = $type;
        return $this;
    }

    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * setName()
     *
     * @param string $name
     * @return Zend_Tool_Framework_Metadata_Basic
     */
    public function setName($name)
    {
        $this->_name = $name;
        return $this;
    }

    /**
     * getValue()
     *
     * @return mixed
     */
    public function getValue()
    {
        return $this->_value;
    }

    /**
     * setValue()
     *
     * @param unknown_type $Value
     * @return Zend_Tool_Framework_Metadata_Basic
     */
    public function setValue($value)
    {
        $this->_value = $value;
        return $this;
    }

    /**
     * setReference()
     *
     * @param mixed $reference
     * @return Zend_Tool_Framework_Metadata_Basic
     */
    public function setReference($reference)
    {
        $this->_reference = $reference;
        return $this;
    }

    /**
     * getReference()
     *
     * @return mixed
     */
    public function getReference()
    {
        return $this->_reference;
    }

    /**
     * getAttributes() - this will retrieve any attributes of this object that exist as properties
     * This is most useful for printing metadata.
     *
     * @param const $type
     * @return array
     */
    public function getAttributes($type = self::ATTRIBUTES_ALL, $stringRepresentationOfNonScalars = false)
    {
        $thisReflection = new ReflectionObject($this);

        $metadataPairValues = array();

        foreach (get_object_vars($this) as $varName => $varValue) {
            if ($type == self::ATTRIBUTES_NO_PARENT && ($thisReflection->getProperty($varName)->getDeclaringClass()->getName() == 'Zend_Tool_Framework_Metadata_Basic')) {
                continue;
            }

            if ($stringRepresentationOfNonScalars) {

                if (is_object($varValue)) {
                    $varValue = '(object)';
                }

                if ($varValue === null) {
                    $varValue = '(null)';
                }

            }

            $metadataPairValues[ltrim($varName, '_')] = $varValue;
        }

        return $metadataPairValues;
    }

    /**
     * __toString() - string representation of this object
     *
     * @return string
     */
    public function __toString()
    {
        return 'Type: ' . $this->_type . ', Name: ' . $this->_name . ', Value: ' . (is_array($this->_value) ? http_build_query($this->_value) : (string) $this->_value);
    }
}

repo_name: michael-romer/zf-boilerplate

repo_language: PHP

mime_type: text/html


text:
<?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
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Attributable.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_Tool_Framework_Metadata_Attributable
{
    public function getAttributes();
}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_Tool_Framework_Metadata_Interface
{

    /**
     * getType()
     *
     * The type of metadata this describes
     *
     */
    public function getType();

    /**
     * getName()
     *
     */
    public function getName();

    /**
     * getValue()
     *
     */
    public function getValue();

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Dynamic.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Framework_Metadata_Interface
 */
require_once 'Zend/Tool/Framework/Metadata/Interface.php';

/**
 * @see Zend_Tool_Framework_Metadata_Attributable
 */
require_once 'Zend/Tool/Framework/Metadata/Attributable.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Metadata_Dynamic
    implements Zend_Tool_Framework_Metadata_Interface, Zend_Tool_Framework_Metadata_Attributable
{

    /**
     * @var string
     */
    protected $_type = 'Dynamic';

    /**
     * @var string
     */
    protected $_name = null;

    /**
     * @var string
     */
    protected $_value = null;

    /**
     * @var array
     */
    protected $_dynamicAttributes = array();

    public function __construct($options = array())
    {
        if ($options) {
            $this->setOptions($options);
        }
    }

    public function setOptions(Array $options = array())
    {
        foreach ($options as $optName => $optValue) {
            $methodName = 'set' . $optName;
            $this->{$methodName}($optValue);
        }
    }

    /**
     * setType()
     *
     * @param string $type
     * @return Zend_Tool_Framework_Metadata_Dynamic
     */
    public function setType($type)
    {
        $this->_type = $type;
        return $this;
    }

    /**
     * getType()
     *
     * The type of metadata this describes
     *
     * @return string
     */
    public function getType()
    {
        return $this->_type;
    }

    /**
     * setName()
     *
     * @param string $name
     * @return Zend_Tool_Framework_Metadata_Dynamic
     */
    public function setName($name)
    {
        $this->_name = $name;
        return $this;
    }

    /**
     * getName()
     *
     * Metadata name
     *
     * @return string
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * setValue()
     *
     * @param mixed $value
     * @return Zend_Tool_Framework_Metadata_Dynamic
     */
    public function setValue($value)
    {
        $this->_value = $value;
        return $this;
    }

    /**
     * getValue()
     *
     * Metadata Value
     *
     * @return string
     */
    public function getValue()
    {
        return $this->_value;
    }

    public function getAttributes()
    {
        return $this->_dynamicAttributes;
    }

    /**
     * __isset()
     *
     * Check if an attrbute is set
     *
     * @param string $name
     * @return bool
     */
    public function __isset($name)
    {
        return isset($this->_dynamicAttributes[$name]);
    }

    /**
     * __unset()
     *
     * @param string $name
     * @return null
     */
    public function __unset($name)
    {
        unset($this->_dynamicAttributes[$name]);
        return;
    }

    /**
     * __get() - Get a property via property call $metadata->foo
     *
     * @param string $name
     * @return mixed
     */
    public function __get($name)
    {
        if (method_exists($this, 'get' . $name)) {
            return $this->{'get' . $name}();
        } elseif (array_key_exists($name, $this->_dynamicAttributes)) {
            return $this->_dynamicAttributes[$name];
        } else {
            require_once 'Zend/Tool/Framework/Registry/Exception.php';
            throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this metadata.');
        }
    }

    /**
     * __set() - Set a property via the magic set $metadata->foo = 'foo'
     *
     * @param string $name
     * @param mixed $value
     */
    public function __set($name, $value)
    {
        if (method_exists($this, 'set' . $name)) {
            $this->{'set' . $name}($value);
            return $this;
        } else {
            $this->_dynamicAttributes[$name] = $value;
            return $this;
        }
//        {
//            require_once 'Zend/Tool/Framework/Registry/Exception.php';
//            throw new Zend_Tool_Framework_Registry_Exception('Property ' . $name . ' was not located in this registry.');
//        }
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Framework_Exception
 */
require_once 'Zend/Tool/Framework/Exception.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Action_Exception extends Zend_Tool_Framework_Exception
{

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Repository.php 23775 2011-03-01 17:25:24Z ralph $
 */

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

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Action_Repository
    implements Zend_Tool_Framework_Registry_EnabledInterface, IteratorAggregate, Countable
{

    /**
     * @var Zend_Tool_Framework_Registry_Interface
     */
    protected $_registry = null;

    /**
     * @var array
     */
    protected $_actions = array();

    /**
     * setRegistry()
     *
     * @param Zend_Tool_Framework_Registry_Interface $registry
     */
    public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
    {
        $this->_registry = $registry;
    }

    /**
     * addAction()
     *
     * @param Zend_Tool_Framework_Action_Interface $action
     * @return Zend_Tool_Framework_Action_Repository
     */
    public function addAction(Zend_Tool_Framework_Action_Interface $action, $overrideExistingAction = false)
    {
        $actionName = $action->getName();

        if ($actionName == '' || $actionName == 'Base') {
            require_once 'Zend/Tool/Framework/Action/Exception.php';
            throw new Zend_Tool_Framework_Action_Exception('An action name for the provided action could not be determined.');
        }

        if (!$overrideExistingAction && array_key_exists(strtolower($actionName), $this->_actions)) {
            require_once 'Zend/Tool/Framework/Action/Exception.php';
            throw new Zend_Tool_Framework_Action_Exception('An action by the name ' . $actionName
                . ' is already registered and $overrideExistingAction is set to false.');
        }

        $this->_actions[strtolower($actionName)] = $action;
        return $this;
    }

    /**
     * process() - this is called when the client is done constructing (after init())
     *
     * @return unknown
     */
    public function process()
    {
        return null;
    }

    /**
     * getActions() - get all actions in the repository
     *
     * @return array
     */
    public function getActions()
    {
        return $this->_actions;
    }

    /**
     * getAction() - get an action by a specific name
     *
     * @param string $actionName
     * @return Zend_Tool_Framework_Action_Interface
     */
    public function getAction($actionName)
    {
        if (!array_key_exists(strtolower($actionName), $this->_actions)) {
            return null;
        }

        return $this->_actions[strtolower($actionName)];
    }

    /**
     * count() required by the Countable interface
     *
     * @return int
     */
    public function count()
    {
        return count($this->_actions);
    }

    /**
     * getIterator() - get all actions, this supports the IteratorAggregate interface
     *
     * @return array
     */
    public function getIterator()
    {
        return new ArrayIterator($this->_actions);
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_Tool_Framework_Action_Interface
{
    public function getName();
}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Base.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Framework_Action_Interface
 */
require_once 'Zend/Tool/Framework/Action/Interface.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Framework_Action_Base implements Zend_Tool_Framework_Action_Interface
{

    /**
     * @var string
     */
    protected $_name = null;

    /**
     * constructor -
     *
     * @param unknown_type $options
     */
    public function __construct($options = null)
    {
        if ($options !== null) {
            if (is_string($options)) {
                $this->setName($options);
            }
            // implement $options here in the future if this is needed
        }
    }

    /**
     * setName()
     *
     * @param string $name
     * @return Zend_Tool_Framework_Action_Base
     */
    public function setName($name)
    {
        $this->_name = $name;
        return $this;
    }

    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        if ($this->_name == null) {
            $this->_name = $this->_parseName();
        }
        return $this->_name;
    }

    /**
     * _parseName - internal method to determine the name of an action when one is not explicity provided.
     *
     * @param Zend_Tool_Framework_Action_Interface $action
     * @return string
     */
    protected function _parseName()
    {
        $className = get_class($this);
        $actionName = substr($className, strrpos($className, '_')+1);
        return $actionName;
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Exception
 */
require_once 'Zend/Exception.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Exception extends Zend_Exception
{

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Profile.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Profile_FileParser_Xml
 */
require_once 'Zend/Tool/Project/Profile/FileParser/Xml.php';

/**
 * @see Zend_Tool_Project_Profile_Resource_Container
 */
require_once 'Zend/Tool/Project/Profile/Resource/Container.php';

/**
 * This class is the front most class for utilizing Zend_Tool_Project
 *
 * A profile is a hierarchical set of resources that keep track of
 * items within a specific project.
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile extends Zend_Tool_Project_Profile_Resource_Container
{

    /**
     * @var bool
     */
    protected static $_traverseEnabled = false;

    /**
     * Constructor, standard usage would allow the setting of options
     *
     * @param array $options
     * @return bool
     */
    public function __construct($options = null)
    {
        if ($options) {
            $this->setOptions($options);
        }

        $this->_topResources = new Zend_Tool_Project_Profile_Resource_Container();
    }

    /**
     * Process options and either set a profile property or
     * set a profile 'attribute'
     *
     * @param array $options
     */
    public function setOptions(Array $options)
    {
        $this->setAttributes($options);
    }

    /**
     * getIterator() - reqruied by the RecursiveIterator interface
     *
     * @return RecursiveIteratorIterator
     */
    public function getIterator()
    {
        require_once 'Zend/Tool/Project/Profile/Iterator/EnabledResourceFilter.php';

        return new RecursiveIteratorIterator(
            new Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter($this),
            RecursiveIteratorIterator::SELF_FIRST
            );
    }

    /**
     * loadFromData() - Load a profile from data provided by the
     * 'profilData' attribute
     *
     */
    public function loadFromData()
    {
        if (!isset($this->_attributes['profileData'])) {
            require_once 'Zend/Tool/Project/Exception.php';
            throw new Zend_Tool_Project_Exception('loadFromData() must have "profileData" set.');
        }

        $profileFileParser = new Zend_Tool_Project_Profile_FileParser_Xml();
        $profileFileParser->unserialize($this->_attributes['profileData'], $this);

        $this->rewind();
    }

    /**
     * isLoadableFromFile() - can a profile be loaded from a file
     *
     * wether or not a profile can be loaded from the
     * file in attribute 'projectProfileFile', or from a file named
     * '.zfproject.xml' inside a directory in key 'projectDirectory'
     *
     * @return bool
     */
    public function isLoadableFromFile()
    {
        if (!isset($this->_attributes['projectProfileFile']) && !isset($this->_attributes['projectDirectory'])) {
            return false;
        }

        if (isset($this->_attributes['projectProfileFile'])) {
            $projectProfileFilePath = $this->_attributes['projectProfileFile'];
            if (!file_exists($projectProfileFilePath)) {
                return false;
            }
        } else {
            $projectProfileFilePath = rtrim($this->_attributes['projectDirectory'], '/\\') . '/.zfproject.xml';
            if (!file_exists($projectProfileFilePath)) {
                return false;
            }
        }

        return true;
    }

    /**
     * loadFromFile() - Load data from file
     *
     * this attempts to load a project profile file from a variety of locations depending
     * on what information the user provided vie $options or attributes, specifically the
     * 'projectDirectory' or 'projectProfileFile'
     *
     */
    public function loadFromFile()
    {
        // if no data is supplied, need either a projectProfileFile or a projectDirectory
        if (!isset($this->_attributes['projectProfileFile']) && !isset($this->_attributes['projectDirectory'])) {
            require_once 'Zend/Tool/Project/Exception.php';
            throw new Zend_Tool_Project_Exception('loadFromFile() must have at least "projectProfileFile" or "projectDirectory" set.');
        }

        if (isset($this->_attributes['projectProfileFile'])) {
            $projectProfileFilePath = $this->_attributes['projectProfileFile'];
            if (!file_exists($projectProfileFilePath)) {
                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);

        $profileFileParser = new Zend_Tool_Project_Profile_FileParser_Xml();
        $profileFileParser->unserialize($profileData, $this);

        $this->rewind();
    }

    /**
     * storeToFile() - store the current profile to file
     *
     * This will store the profile in memory to a place on disk determined by the attributes
     * available, specifically if the key 'projectProfileFile' is available
     *
     */
    public function storeToFile()
    {
        $file = null;

        if (isset($this->_attributes['projectProfileFile'])) {
            $file = $this->_attributes['projectProfileFile'];
        }

        if ($file == null) {
            require_once 'Zend/Tool/Project/Exception.php';
            throw new Zend_Tool_Project_Exception('storeToFile() must have a "projectProfileFile" attribute set.');
        }

        $parser = new Zend_Tool_Project_Profile_FileParser_Xml();
        $xml = $parser->serialize($this);
        file_put_contents($file, $xml);
    }

    /**
     * storeToData() - create a string representation of the profile in memory
     *
     * @return string
     */
    public function storeToData()
    {
        $parser = new Zend_Tool_Project_Profile_FileParser_Xml();
        $xml = $parser->serialize($this);
        return $xml;
    }

    /**
     * __toString() - cast this profile to string to be able to view it.
     *
     * @return string
     */
    public function __toString()
    {
        $string = '';
        foreach ($this as $resource) {
            $string .= $resource->getName() . PHP_EOL;
            $rii = new RecursiveIteratorIterator($resource, RecursiveIteratorIterator::SELF_FIRST);
            foreach ($rii as $item) {
                $string .= str_repeat('  ', $rii->getDepth()+1) . $item->getName()
                        . ((count($attributes = $item->getAttributes()) > 0) ? ' [' . http_build_query($attributes) . ']' : '')
                        . PHP_EOL;
            }
        }
        return $string;
    }
}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Exception
 */
require_once 'Zend/Tool/Project/Exception.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Exception extends Zend_Tool_Project_Exception
{

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Resource.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Profile_Resource_Container
 */
require_once 'Zend/Tool/Project/Profile/Resource/Container.php';

/**
 * @see Zend_Tool_Project_Context_Repository
 */
require_once 'Zend/Tool/Project/Context/Repository.php';

/**
 * This class is an iterator that will iterate only over enabled resources
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Resource extends Zend_Tool_Project_Profile_Resource_Container
{

    /**
     * @var Zend_Tool_Project_Profile
     */
    protected $_profile = null;

    /**
     * @var Zend_Tool_Project_Profile_Resource
     */
    protected $_parentResource = null;

    /**#@+
     * @var bool
     */
    protected $_deleted = false;
    protected $_enabled = true;
    /**#@-*/

    /**
     * @var Zend_Tool_Project_Context|string
     */
    protected $_context = null;

    /**
     * @var array
     */
    protected $_attributes = array();

    /**
     * @var bool
     */
    protected $_isContextInitialized = false;

    /**
     * __construct()
     *
     * @param string|Zend_Tool_Project_Context_Interface $context
     */
    public function __construct($context)
    {
        $this->setContext($context);
    }

    /**
     * setContext()
     *
     * @param string|Zend_Tool_Project_Context_Interface $context
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function setContext($context)
    {
        $this->_context = $context;
        return $this;
    }

    /**
     * getContext()
     *
     * @return Zend_Tool_Project_Context_Interface
     */
    public function getContext()
    {
        return $this->_context;
    }

    /**
     * getName() - Get the resource name
     *
     * Name is derived from the context name
     *
     * @return string
     */
    public function getName()
    {
        if (is_string($this->_context)) {
            return $this->_context;
        } elseif ($this->_context instanceof Zend_Tool_Project_Context_Interface) {
            return $this->_context->getName();
        } else {
            throw new Zend_Tool_Project_Exception('Invalid context in resource');
        }
    }

    /**
     * setProfile()
     *
     * @param Zend_Tool_Project_Profile $profile
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function setProfile(Zend_Tool_Project_Profile $profile)
    {
        $this->_profile = $profile;
        return $this;
    }

    /**
     * getProfile
     *
     * @return Zend_Tool_Project_Profile
     */
    public function getProfile()
    {
        return $this->_profile;
    }

    /**
     * getPersistentAttributes()
     *
     * @return array
     */
    public function getPersistentAttributes()
    {
        if (method_exists($this->_context, 'getPersistentAttributes')) {
            return $this->_context->getPersistentAttributes();
        }

        return array();
    }

    /**
     * setEnabled()
     *
     * @param bool $enabled
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function setEnabled($enabled = true)
    {
        // convert fuzzy types to bool
        $this->_enabled = (!in_array($enabled, array('false', 'disabled', 0, -1, false), true)) ? true : false;
        return $this;
    }

    /**
     * isEnabled()
     *
     * @return bool
     */
    public function isEnabled()
    {
        return $this->_enabled;
    }

    /**
     * setDeleted()
     *
     * @param bool $deleted
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function setDeleted($deleted = true)
    {
        $this->_deleted = (bool) $deleted;
        return $this;
    }

    /**
     * isDeleted()
     *
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function isDeleted()
    {
        return $this->_deleted;
    }

    /**
     * initializeContext()
     *
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function initializeContext()
    {
        if ($this->_isContextInitialized) {
            return;
        }
        if (is_string($this->_context)) {
            $this->_context = Zend_Tool_Project_Context_Repository::getInstance()->getContext($this->_context);
        }

        if (method_exists($this->_context, 'setResource')) {
            $this->_context->setResource($this);
        }

        if (method_exists($this->_context, 'init')) {
            $this->_context->init();
        }

        $this->_isContextInitialized = true;
        return $this;
    }

    /**
     * __toString()
     *
     * @return string
     */
    public function __toString()
    {
        return $this->_context->getName();
    }

    /**
     * __call()
     *
     * @param string $method
     * @param array $arguments
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function __call($method, $arguments)
    {
        if (method_exists($this->_context, $method)) {
            if (!$this->isEnabled()) {
                $this->setEnabled(true);
            }
            return call_user_func_array(array($this->_context, $method), $arguments);
        } else {
            throw new Zend_Tool_Project_Profile_Exception('cannot call ' . $method);
        }
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_Tool_Project_Profile_FileParser_Interface
{

    /**
     * serialize()
     *
     * This method should take a profile and return a string
     * representation of it.
     *
     * @param Zend_Tool_Project_Profile $profile
     * @return string
     */
    public function serialize(Zend_Tool_Project_Profile $profile);

    /**
     * unserialize()
     *
     * This method should be able to take string data an create a
     * struture in the provided $profile
     *
     * @param string $data
     * @param Zend_Tool_Project_Profile $profile
     */
    public function unserialize($data, Zend_Tool_Project_Profile $profile);

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Xml.php 23775 2011-03-01 17:25:24Z ralph $
 */

require_once 'Zend/Tool/Project/Profile/FileParser/Interface.php';
require_once 'Zend/Tool/Project/Context/Repository.php';
require_once 'Zend/Tool/Project/Profile.php';
require_once 'Zend/Tool/Project/Profile/Resource.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_FileParser_Xml implements Zend_Tool_Project_Profile_FileParser_Interface
{

    /**
     * @var Zend_Tool_Project_Profile
     */
    protected $_profile = null;

    /**
     * @var Zend_Tool_Project_Context_Repository
     */
    protected $_contextRepository = null;

    /**
     * __construct()
     *
     */
    public function __construct()
    {
        $this->_contextRepository = Zend_Tool_Project_Context_Repository::getInstance();
    }

    /**
     * serialize()
     *
     * create an xml string from the provided profile
     *
     * @param Zend_Tool_Project_Profile $profile
     * @return string
     */
    public function serialize(Zend_Tool_Project_Profile $profile)
    {

        $profile = clone $profile;

        $this->_profile = $profile;
        $xmlElement = new SimpleXMLElement('<projectProfile />');

        if ($profile->hasAttribute('type')) {
            $xmlElement->addAttribute('type', $profile->getAttribute('type'));
        }

        if ($profile->hasAttribute('version')) {
            $xmlElement->addAttribute('version', $profile->getAttribute('version'));
        }

        self::_serializeRecurser($profile, $xmlElement);

        $doc = new DOMDocument('1.0');
        $doc->formatOutput = true;
        $domnode = dom_import_simplexml($xmlElement);
        $domnode = $doc->importNode($domnode, true);
        $domnode = $doc->appendChild($domnode);

        return $doc->saveXML();
    }

    /**
     * unserialize()
     *
     * Create a structure in the object $profile from the structure specficied
     * in the xml string provided
     *
     * @param string xml data
     * @param Zend_Tool_Project_Profile The profile to use as the top node
     * @return Zend_Tool_Project_Profile
     */
    public function unserialize($data, Zend_Tool_Project_Profile $profile)
    {
        if ($data == null) {
            throw new Exception('contents not available to unserialize.');
        }

        $this->_profile = $profile;

        $xmlDataIterator = new SimpleXMLIterator($data);

        if ($xmlDataIterator->getName() != 'projectProfile') {
            throw new Exception('Profiles must start with a projectProfile node');
        }

        if (isset($xmlDataIterator['type'])) {
            $this->_profile->setAttribute('type', (string) $xmlDataIterator['type']);
        }

        if (isset($xmlDataIterator['version'])) {
            $this->_profile->setAttribute('version', (string) $xmlDataIterator['version']);
        }

        // start un-serialization of the xml doc
        $this->_unserializeRecurser($xmlDataIterator);

        // contexts should be initialized after the unwinding of the profile structure
        $this->_lazyLoadContexts();

        return $this->_profile;

    }

    /**
     * _serializeRecurser()
     *
     * This method will be used to traverse the depths of the structure
     * when *serializing* an xml structure into a string
     *
     * @param array $resources
     * @param SimpleXmlElement $xmlNode
     */
    protected function _serializeRecurser($resources, SimpleXmlElement $xmlNode)
    {
        // @todo find a better way to handle concurrency.. if no clone, _position in node gets messed up
        //if ($resources instanceof Zend_Tool_Project_Profile_Resource) {
        //    $resources = clone $resources;
        //}

        foreach ($resources as $resource) {

            if ($resource->isDeleted()) {
                continue;
            }

            $resourceName = $resource->getContext()->getName();
            $resourceName[0] = strtolower($resourceName[0]);

            $newNode = $xmlNode->addChild($resourceName);

            //$reflectionClass = new ReflectionClass($resource->getContext());

            if ($resource->isEnabled() == false) {
                $newNode->addAttribute('enabled', 'false');
            }

            foreach ($resource->getPersistentAttributes() as $paramName => $paramValue) {
                $newNode->addAttribute($paramName, $paramValue);
            }

            if ($resource->hasChildren()) {
                self::_serializeRecurser($resource, $newNode);
            }

        }

    }

    /**
     * _unserializeRecurser()
     *
     * This method will be used to traverse the depths of the structure
     * as needed to *unserialize* the profile from an xmlIterator
     *
     * @param SimpleXMLIterator $xmlIterator
     * @param Zend_Tool_Project_Profile_Resource $resource
     */
    protected function _unserializeRecurser(SimpleXMLIterator $xmlIterator, Zend_Tool_Project_Profile_Resource $resource = null)
    {

        foreach ($xmlIterator as $resourceName => $resourceData) {

            $contextName = $resourceName;
            $subResource = new Zend_Tool_Project_Profile_Resource($contextName);
            $subResource->setProfile($this->_profile);

            if ($resourceAttributes = $resourceData->attributes()) {
                $attributes = array();
                foreach ($resourceAttributes as $attrName => $attrValue) {
                    $attributes[$attrName] = (string) $attrValue;
                }
                $subResource->setAttributes($attributes);
            }

            if ($resource) {
                $resource->append($subResource, false);
            } else {
                $this->_profile->append($subResource);
            }

            if ($this->_contextRepository->isOverwritableContext($contextName) == false) {
                $subResource->initializeContext();
            }

            if ($xmlIterator->hasChildren()) {
                self::_unserializeRecurser($xmlIterator->getChildren(), $subResource);
            }
        }
    }

    /**
     * _lazyLoadContexts()
     *
     * This method will call initializeContext on the resources in a profile
     * @todo determine if this method belongs inside the profile
     *
     */
    protected function _lazyLoadContexts()
    {

        foreach ($this->_profile as $topResource) {
            $rii = new RecursiveIteratorIterator($topResource, RecursiveIteratorIterator::SELF_FIRST);
            foreach ($rii as $resource) {
                $resource->initializeContext();
            }
        }

    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Container.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Profile_Resource_SearchConstraints
 */
require_once 'Zend/Tool/Project/Profile/Resource/SearchConstraints.php';

/**
 * This class is an iterator that will iterate only over enabled resources
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Resource_Container implements RecursiveIterator, Countable
{

    /**
     * @var array
     */
    protected $_subResources = array();

    /**
     * @var int
     */
    protected $_position = 0;

    /**
     * @var bool
     */
    protected $_appendable = true;

    /**
     * @var array
     */
    protected $_attributes = array();

    /**
     * Finder method to be able to find resources by context name
     * and attributes.  Example usage:
     *
     * <code>
     *
     * </code>
     *
     * @param Zend_Tool_Project_Profile_Resource_SearchConstraints|string|array $searchParameters
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function search($matchSearchConstraints, $nonMatchSearchConstraints = null)
    {
        if (!$matchSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_SearchConstraints) {
            $matchSearchConstraints = new Zend_Tool_Project_Profile_Resource_SearchConstraints($matchSearchConstraints);
        }

        $this->rewind();

        /**
         * @todo This should be re-written with better support for a filter iterator, its the way to go
         */

        if ($nonMatchSearchConstraints) {
            $filterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter($this, array('denyNames' => $nonMatchSearchConstraints));
            $riIterator = new RecursiveIteratorIterator($filterIterator, RecursiveIteratorIterator::SELF_FIRST);
        } else {
            $riIterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
        }

        $foundResource     = false;
        $currentConstraint = $matchSearchConstraints->getConstraint();
        $foundDepth        = 0;

        foreach ($riIterator as $currentResource) {

            // if current depth is less than found depth, end
            if ($riIterator->getDepth() < $foundDepth) {
                break;
            }

            if (strtolower($currentResource->getName()) == strtolower($currentConstraint->name)) {

                $paramsMatch = true;

                // @todo check to ensure params match (perhaps)
                if (count($currentConstraint->params) > 0) {
                    $currentResourceAttributes = $currentResource->getAttributes();
                    if (!is_array($currentConstraint->params)) {
                        require_once 'Zend/Tool/Project/Profile/Exception.php';
                        throw new Zend_Tool_Project_Profile_Exception('Search parameter specifics must be in the form of an array for key "'
                            . $currentConstraint->name .'"');
                    }
                    foreach ($currentConstraint->params as $paramName => $paramValue) {
                        if (!isset($currentResourceAttributes[$paramName]) || $currentResourceAttributes[$paramName] != $paramValue) {
                            $paramsMatch = false;
                            break;
                        }
                    }
                }

                if ($paramsMatch) {
                    $foundDepth = $riIterator->getDepth();

                    if (($currentConstraint = $matchSearchConstraints->getConstraint()) == null) {
                        $foundResource = $currentResource;
                        break;
                    }
                }

            }

        }

        return $foundResource;
    }

    /**
     * createResourceAt()
     *
     * @param array|Zend_Tool_Project_Profile_Resource_SearchConstraints $appendResourceOrSearchConstraints
     * @param string $context
     * @param array $attributes
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function createResourceAt($appendResourceOrSearchConstraints, $context, Array $attributes = array())
    {
        if (!$appendResourceOrSearchConstraints instanceof Zend_Tool_Project_Profile_Resource_Container) {
            if (($parentResource = $this->search($appendResourceOrSearchConstraints)) == false) {
                require_once 'Zend/Tool/Project/Profile/Exception.php';
                throw new Zend_Tool_Project_Profile_Exception('No node was found to append to.');
            }
        } else {
            $parentResource = $appendResourceOrSearchConstraints;
        }

        return $parentResource->createResource($context, $attributes);
    }

    /**
     * createResource()
     *
     * Method to create a resource with a given context with specific attributes
     *
     * @param string $context
     * @param array $attributes
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function createResource($context, Array $attributes = array())
    {
        if (is_string($context)) {
            $contextRegistry = Zend_Tool_Project_Context_Repository::getInstance();
            if ($contextRegistry->hasContext($context)) {
                $context = $contextRegistry->getContext($context);
            } else {
                require_once 'Zend/Tool/Project/Profile/Exception.php';
                throw new Zend_Tool_Project_Profile_Exception('Context by name ' . $context . ' was not found in the context registry.');
            }
        } elseif (!$context instanceof Zend_Tool_Project_Context_Interface) {
            require_once 'Zend/Tool/Project/Profile/Exception.php';
            throw new Zend_Tool_Project_Profile_Exception('Context must be of type string or Zend_Tool_Project_Context_Interface.');
        }

        $newResource = new Zend_Tool_Project_Profile_Resource($context);

        if ($attributes) {
            $newResource->setAttributes($attributes);
        }

        /**
         * Interesting logic here:
         *
         * First set the parentResource (this will also be done inside append).  This will allow
         * the initialization routine to change the appendability of the parent resource.  This
         * is important to allow specific resources to be appendable by very specific sub-resources.
         */
        $newResource->setParentResource($this);
        $newResource->initializeContext();
        $this->append($newResource);

        return $newResource;
    }

    /**
     * setAttributes()
     *
     * persist the attributes if the resource will accept them
     *
     * @param array $attributes
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function setAttributes(Array $attributes)
    {
        foreach ($attributes as $attrName => $attrValue) {
            $setMethod = 'set' . $attrName;
            if (method_exists($this, $setMethod)) {
                $this->{$setMethod}($attrValue);
            } else {
                $this->setAttribute($attrName, $attrValue);
            }
        }
        return $this;
    }

    /**
     * getAttributes()
     *
     * @return array
     */
    public function getAttributes()
    {
        return $this->_attributes;
    }

    /**
     * setAttribute()
     *
     * @param string $name
     * @param mixed $value
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function setAttribute($name, $value)
    {
        $this->_attributes[$name] = $value;
        return $this;
    }

    /**
     * getAttribute()
     *
     * @param string $name
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function getAttribute($name)
    {
        return (array_key_exists($name, $this->_attributes)) ? $this->_attributes[$name] : null;
    }

    /**
     * hasAttribute()
     *
     * @param string $name
     * @return bool
     */
    public function hasAttribute($name)
    {
        return array_key_exists($name, $this->_attributes);
    }

    /**
     * setAppendable()
     *
     * @param bool $appendable
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function setAppendable($appendable)
    {
        $this->_appendable = (bool) $appendable;
        return $this;
    }

    /**
     * isAppendable()
     *
     * @return bool
     */
    public function isAppendable()
    {
        return $this->_appendable;
    }

    /**
     * setParentResource()
     *
     * @param Zend_Tool_Project_Profile_Resource_Container $parentResource
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function setParentResource(Zend_Tool_Project_Profile_Resource_Container $parentResource)
    {
        $this->_parentResource = $parentResource;
        return $this;
    }

    /**
     * getParentResource()
     *
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function getParentResource()
    {
        return $this->_parentResource;
    }

    /**
     * append()
     *
     * @param Zend_Tool_Project_Profile_Resource_Container $resource
     * @return Zend_Tool_Project_Profile_Resource_Container
     */
    public function append(Zend_Tool_Project_Profile_Resource_Container $resource)
    {
        if (!$this->isAppendable()) {
            throw new Exception('Resource by name ' . (string) $this . ' is not appendable');
        }
        array_push($this->_subResources, $resource);
        $resource->setParentResource($this);

        return $this;
    }

    /**
     * current() - required by RecursiveIterator
     *
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function current()
    {
        return current($this->_subResources);
    }

    /**
     * key() - required by RecursiveIterator
     *
     * @return int
     */
    public function key()
    {
        return key($this->_subResources);
    }

    /**
     * next() - required by RecursiveIterator
     *
     * @return bool
     */
    public function next()
    {
        return next($this->_subResources);
    }

    /**
     * rewind() - required by RecursiveIterator
     *
     * @return bool
     */
    public function rewind()
    {
        return reset($this->_subResources);
    }

    /**
     * valid() - - required by RecursiveIterator
     *
     * @return bool
     */
    public function valid()
    {
        return (bool) $this->current();
    }

    /**
     * hasChildren()
     *
     * @return bool
     */
    public function hasChildren()
    {
        return (count($this->_subResources > 0)) ? true : false;
    }

    /**
     * getChildren()
     *
     * @return array
     */
    public function getChildren()
    {
        return $this->current();
    }

    /**
     * count()
     *
     * @return int
     */
    public function count()
    {
        return count($this->_subResources);
    }

    /**
     * __clone()
     *
     */
    public function __clone()
    {
        $this->rewind();
        foreach ($this->_subResources as $index => $resource) {
            $this->_subResources[$index] = clone $resource;
        }
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: SearchConstraints.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * This class is an iterator that will iterate only over enabled resources
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Resource_SearchConstraints
{

    /**
     * @var array
     */
    protected $_constraints = array();

    /**
     * __construct()
     *
     * @param array|string $options
     */
    public function __construct($options = null)
    {
        if (is_string($options)) {
            $this->addConstraint($options);
        } elseif (is_array($options)) {
            $this->setOptions($options);
        }
    }

    /**
     * setOptions()
     *
     * @param array $option
     * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
     */
    public function setOptions(Array $option)
    {
        foreach ($option as $optionName => $optionValue) {
            if (is_int($optionName)) {
                $this->addConstraint($optionValue);
            } elseif (is_string($optionName)) {
                $this->addConstraint(array('name' => $optionName, 'params' => $optionValue));
            }
        }

        return $this;
    }

    /**
     * addConstraint()
     *
     * @param string|array $constraint
     * @return Zend_Tool_Project_Profile_Resource_SearchConstraints
     */
    public function addConstraint($constraint)
    {
        if (is_string($constraint)) {
            $name   = $constraint;
            $params = array();
        } elseif (is_array($constraint)) {
            $name   = $constraint['name'];
            $params = $constraint['params'];
        }

        $constraint = $this->_makeConstraint($name, $params);

        array_push($this->_constraints, $constraint);
        return $this;
    }

    /**
     * getConstraint()
     *
     * @return ArrayObject
     */
    public function getConstraint()
    {
        return array_shift($this->_constraints);
    }

    /**
     * _makeConstraint
     *
     * @param string $name
     * @param mixed $params
     * @return ArrayObject
     */
    protected function _makeConstraint($name, $params)
    {
        $value = array('name' => $name, 'params' => $params);
        return new ArrayObject($value, ArrayObject::ARRAY_AS_PROPS);
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: EnabledResourceFilter.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * This class is an iterator that will iterate only over enabled resources
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter extends RecursiveFilterIterator
{

    /**
     * accept() is required by teh RecursiveFilterIterator
     *
     * @return bool
     */
    public function accept()
    {
        return $this->current()->isEnabled();
    }
}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: ContextFilter.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * This class is an iterator that will iterate only over enabled resources
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Profile_Iterator_ContextFilter extends RecursiveFilterIterator
{

    /**
     * @var array
     */
    protected $_acceptTypes = array();

    /**
     * @var array
     */
    protected $_denyTypes   = array();

    /**
     * @var array
     */
    protected $_acceptNames = array();

    /**
     * @var array
     */
    protected $_denyNames   = array();

    /**
     * @var array
     */
    protected $_rawOptions = array();

    /**
     * __construct()
     *
     * @param RecursiveIterator $iterator
     * @param array $options
     */
    public function __construct(RecursiveIterator $iterator, $options = array())
    {
        parent::__construct($iterator);
        $this->_rawOptions = $options;
        if ($options) {
            $this->setOptions($options);
        }
    }

    /**
     * setOptions()
     *
     * @param array $options
     */
    public function setOptions(Array $options)
    {
        foreach ($options as $optionName => $optionValue) {
            if (substr($optionName, -1, 1) != 's') {
                $optionName .= 's';
            }
            if (method_exists($this, 'set' . $optionName)) {
                $this->{'set' . $optionName}($optionValue);
            }
        }
    }

    /**
     * setAcceptTypes()
     *
     * @param array|string $acceptTypes
     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
     */
    public function setAcceptTypes($acceptTypes)
    {
        if (!is_array($acceptTypes)) {
            $acceptTypes = array($acceptTypes);
        }

        $this->_acceptTypes = $acceptTypes;
        return $this;
    }

    /**
     * setDenyTypes()
     *
     * @param array|string $denyTypes
     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
     */
    public function setDenyTypes($denyTypes)
    {
        if (!is_array($denyTypes)) {
            $denyTypes = array($denyTypes);
        }

        $this->_denyTypes = $denyTypes;
        return $this;
    }

    /**
     * setAcceptNames()
     *
     * @param array|string $acceptNames
     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
     */
    public function setAcceptNames($acceptNames)
    {
        if (!is_array($acceptNames)) {
            $acceptNames = array($acceptNames);
        }

        foreach ($acceptNames as $n => $v) {
            $acceptNames[$n] = strtolower($v);
        }

        $this->_acceptNames = $acceptNames;
        return $this;
    }

    /**
     * setDenyNames()
     *
     * @param array|string $denyNames
     * @return Zend_Tool_Project_Profile_Iterator_ContextFilter
     */
    public function setDenyNames($denyNames)
    {
        if (!is_array($denyNames)) {
            $denyNames = array($denyNames);
        }

        foreach ($denyNames as $n => $v) {
            $denyNames[$n] = strtolower($v);
        }

        $this->_denyNames = $denyNames;
        return $this;
    }

    /**
     * accept() is required by teh RecursiveFilterIterator
     *
     * @return bool
     */
    public function accept()
    {
        $currentItem = $this->current();

        if (in_array(strtolower($currentItem->getName()), $this->_acceptNames)) {
            return true;
        } elseif (in_array(strtolower($currentItem->getName()), $this->_denyNames)) {
            return false;
        }

        foreach ($this->_acceptTypes as $acceptType) {
            if ($currentItem->getContent() instanceof $acceptType) {
                return true;
            }
        }

        foreach ($this->_denyTypes as $denyType) {
            if ($currentItem->getContext() instanceof $denyType) {
                return false;
            }
        }

        return true;
    }

    /**
     * getChildren()
     *
     * This is here due to a bug/design issue in PHP
     * @link
     *
     * @return unknown
     */
    function getChildren()
    {

        if (empty($this->ref)) {
            $this->ref = new ReflectionClass($this);
        }

        return $this->ref->newInstance($this->getInnerIterator()->getChildren(), $this->_rawOptions);
    }

}


text:
<?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
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
 */

require_once 'Zend/Tool/Project/Exception.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Context_Exception extends Zend_Tool_Project_Exception
{

}


text:
<?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
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Repository.php 23775 2011-03-01 17:25:24Z ralph $
 */

require_once 'Zend/Tool/Project/Context/System/Interface.php';
require_once 'Zend/Tool/Project/Context/System/TopLevelRestrictable.php';
require_once 'Zend/Tool/Project/Context/System/NotOverwritable.php';

/**
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Context_Repository implements Countable
{

    protected static $_instance = null;
    protected static $_isInitialized = false;

    protected $_shortContextNames = array();
    protected $_contexts          = array();

    /**
     * Enter description here...
     *
     * @return Zend_Tool_Project_Context_Repository
     */
    public static function getInstance()
    {
        if (self::$_instance == null) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    public static function resetInstance()
    {
        self::$_instance = null;
        self::$_isInitialized = false;
    }

    protected function __construct()
    {
        if (self::$_isInitialized == false) {
            $this->addContextClass('Zend_Tool_Project_Context_System_ProjectDirectory')
                 ->addContextClass('Zend_Tool_Project_Context_System_ProjectProfileFile')
                 ->addContextClass('Zend_Tool_Project_Context_System_ProjectProvidersDirectory');
            self::$_isInitialized = true;
        }
    }

    public function addContextsFromDirectory($directory, $prefix)
    {
        $prefix = trim($prefix, '_') . '_';
        foreach (new DirectoryIterator($directory) as $directoryItem) {
            if ($directoryItem->isDot() || (substr($directoryItem->getFilename(), -4) !== '.php')) {
                continue;
            }
            $class = $prefix . substr($directoryItem->getFilename(), 0, -4);
            $this->addContextClass($class);
        }
    }

    public function addContextClass($contextClass)
    {
        if (!class_exists($contextClass)) {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($contextClass);
        }
        $reflectionContextClass = new ReflectionClass($contextClass);
        if ($reflectionContextClass->isInstantiable()) {
            $context = new $contextClass();
            return $this->addContext($context);
        }
        return $this;
    }

    /**
     * Enter description here...
     *
     * @param Zend_Tool_Project_Context_Interface $context
     * @return Zend_Tool_Project_Context_Repository
     */
    public function addContext(Zend_Tool_Project_Context_Interface $context)
    {
        $isSystem       = ($context instanceof Zend_Tool_Project_Context_System_Interface);
        $isTopLevel     = ($context instanceof Zend_Tool_Project_Context_System_TopLevelRestrictable);
        $isOverwritable = !($context instanceof Zend_Tool_Project_Context_System_NotOverwritable);

        $index = (count($this->_contexts)) ? max(array_keys($this->_contexts)) + 1 : 1;

        $normalName = $this->_normalizeName($context->getName());

        if (isset($this->_shortContextNames[$normalName]) && ($this->_contexts[$this->_shortContextNames[$normalName]]['isOverwritable'] === false) ) {
            require_once 'Zend/Tool/Project/Context/Exception.php';
            throw new Zend_Tool_Project_Context_Exception('Context ' . $context->getName() . ' is not overwriteable.');
        }

        $this->_shortContextNames[$normalName] = $index;
        $this->_contexts[$index] = array(
            'isTopLevel'     => $isTopLevel,
            'isSystem'       => $isSystem,
            'isOverwritable' => $isOverwritable,
            'normalName'     => $normalName,
            'context'        => $context
            );

        return $this;
    }

    public function getContext($name)
    {
        if (!$this->hasContext($name)) {
            require_once 'Zend/Tool/Project/Context/Exception.php';
            throw new Zend_Tool_Project_Context_Exception('Context by name ' . $name . ' does not exist in the registry.');
        }

        $name = $this->_normalizeName($name);
        return clone $this->_contexts[$this->_shortContextNames[$name]]['context'];
    }

    public function hasContext($name)
    {
        $name = $this->_normalizeName($name);
        return (isset($this->_shortContextNames[$name]) ? true : false);
    }

    public function isSystemContext($name)
    {
        if (!$this->hasContext($name)) {
            return false;
        }

        $name = $this->_normalizeName($name);
        $index = $this->_shortContextNames[$name];
        return $this->_contexts[$index]['isSystemContext'];
    }

    public function isTopLevelContext($name)
    {
        if (!$this->hasContext($name)) {
            return false;
        }
        $name = $this->_normalizeName($name);
        $index = $this->_shortContextNames[$name];
        return $this->_contexts[$index]['isTopLevel'];
    }

    public function isOverwritableContext($name)
    {
        if (!$this->hasContext($name)) {
            return false;
        }
        $name = $this->_normalizeName($name);
        $index = $this->_shortContextNames[$name];
        return $this->_contexts[$index]['isOverwritable'];
    }

    public function count()
    {
        return count($this->_contexts);
    }

    protected function _normalizeName($name)
    {
        return strtolower($name);
    }

}


text:
<?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
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Interface.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * Interface for contexts
 *
 * setResource() is an optional method that if the context supports
 * will be set with the resource at construction time
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
interface Zend_Tool_Project_Context_Interface
{

    public function getName();

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: File.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Context_Filesystem_Abstract
 */
require_once 'Zend/Tool/Project/Context/Filesystem/Abstract.php';

/**
 * This class is the front most class for utilizing Zend_Tool_Project
 *
 * A profile is a hierarchical set of resources that keep track of
 * items within a specific project.
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Context_Filesystem_File extends Zend_Tool_Project_Context_Filesystem_Abstract
{

    protected $_fileOnlyContext = null;

    protected $_filesystemName = null;

    protected $_content = null;

    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        return 'file';
    }

    /**
     * init()
     *
     * @return Zend_Tool_Project_Context_Filesystem_File
     */
    public function init()
    {
        if ($this->_resource->hasAttribute('filesystemName')) {
            $this->_filesystemName = $this->_resource->getAttribute('filesystemName');
        }

        // check to see if this file is
        if ($this->getName() == 'file') {
            $this->_initFileOnlyContext();
        }

        // @potential-todo check to ensure that this 'file' resource has no children
        parent::init();
        return $this;
    }

    /**
     * getPersistentAttributes()
     *
     * @return array
     */
    public function getPersistentAttributes()
    {
        $returnAttrs = array();
        if ($this->_filesystemName !== null) {
            $returnAttrs['filesystemName'] = $this->_filesystemName;
        }
        return $returnAttrs;
    }

    /**
     * setResource()
     *
     * @param unknown_type $resource
     */
    public function setResource(Zend_Tool_Project_Profile_Resource $resource)
    {
        $this->_resource = $resource;
        $this->_resource->setAppendable(false);
        return $this;
    }

    /**
     * getResource()
     *
     * @return Zend_Tool_Project_Profile_Resource
     */
    public function getResource()
    {
        return $this->_resource;
    }

    /**
     * create()
     *
     * @return Zend_Tool_Project_Context_Filesystem_File
     */
    public function create()
    {
        // check to ensure the parent exists, if not, call it and create it
        if (($parentResource = $this->_resource->getParentResource()) instanceof Zend_Tool_Project_Profile_Resource) {
            if ((($parentContext = $parentResource->getContext()) instanceof Zend_Tool_Project_Context_Filesystem_Abstract)
                && (!$parentContext->exists())) {
                $parentResource->create();
            }
        }

        if (file_exists($this->getPath())) {
            // @todo propt user to determine if its ok to overwrite file
        }

        file_put_contents($this->getPath(), $this->getContents());
        return $this;
    }

    /**
     * delete()
     *
     * @return Zend_Tool_Project_Context_Filesystem_File
     */
    public function delete()
    {
        unlink($this->getPath());
        $this->_resource->setDeleted(true);
        return $this;
    }

    /**
     * getContents()
     *
     * @return null
     */
    public function getContents()
    {
        return $this->_content;
    }

    protected function _initFileOnlyContext()
    {
        if ($this->_resource->hasAttribute('defaultContentCallback')) {
            $contentFunc = $this->_resource->getAttribute('defaultContentCallback');
            if (is_callable($contentFunc)) {
                $this->_content = call_user_func_array($contentFunc, array($this));
            }
        }
        if ($this->_filesystemName == null) {
            $this->_filesystemName = 'file.txt';
        }
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Directory.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Context_Filesystem_Abstract
 */
require_once 'Zend/Tool/Project/Context/Filesystem/Abstract.php';

/**
 * This class is the front most class for utilizing Zend_Tool_Project
 *
 * A profile is a hierarchical set of resources that keep track of
 * items within a specific project.
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Context_Filesystem_Directory extends Zend_Tool_Project_Context_Filesystem_Abstract
{

    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        return 'directory';
    }

    /**
     * create()
     *
     * @return Zend_Tool_Project_Context_Filesystem_Directory;
     */
    public function create()
    {
        // check to ensure the parent exists, if not, call it and create it
        if (($parentResource = $this->_resource->getParentResource()) instanceof Zend_Tool_Project_Profile_Resource) {
            if ((($parentContext = $parentResource->getContext()) instanceof Zend_Tool_Project_Context_Filesystem_Abstract)
                && (!$parentContext->exists())) {
                $parentResource->create();
            }
        }

        if (!file_exists($this->getPath())) {
            mkdir($this->getPath());
        }

        return $this;
    }

    /**
     * delete()
     *
     * @return Zend_Tool_Project_Context_Filesystem_Directory
     */
    public function delete()
    {
        $this->_resource->setDeleted(true);
        rmdir($this->getPath());

        return $this;
    }

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Context_Interface
 */
require_once 'Zend/Tool/Project/Context/Interface.php';

/**
 * This class is the front most class for utilizing Zend_Tool_Project
 *
 * A profile is a hierarchical set of resources that keep track of
 * items within a specific project.
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
abstract class Zend_Tool_Project_Context_Filesystem_Abstract implements Zend_Tool_Project_Context_Interface
{

    /**
     * @var Zend_Tool_Project_Profile_Resource
     */
    protected $_resource = null;

    /**
     * @var string
     */
    protected $_baseDirectory = null;

    /**
     * @var string
     */
    protected $_filesystemName = null;

    /**
     * init()
     *
     * @return Zend_Tool_Project_Context_Filesystem_Abstract
     */
    public function init()
    {
        $parentBaseDirectory = $this->_resource->getParentResource()->getContext()->getPath();
        $this->_baseDirectory = $parentBaseDirectory;
        return $this;
    }

    /**
     * setResource()
     *
     * @param Zend_Tool_Project_Profile_Resource $resource
     * @return Zend_Tool_Project_Context_Filesystem_Abstract
     */
    public function setResource(Zend_Tool_Project_Profile_Resource $resource)
    {
        $this->_resource = $resource;
        return $this;
    }

    /**
     * setBaseDirectory()
     *
     * @param string $baseDirectory
     * @return Zend_Tool_Project_Context_Filesystem_Abstract
     */
    public function setBaseDirectory($baseDirectory)
    {
        $this->_baseDirectory = rtrim(str_replace('\\', '/', $baseDirectory), '/');
        return $this;
    }

    /**
     * getBaseDirectory()
     *
     * @return string
     */
    public function getBaseDirectory()
    {
        return $this->_baseDirectory;
    }

    /**
     * setFilesystemName()
     *
     * @param string $filesystemName
     * @return Zend_Tool_Project_Context_Filesystem_Abstract
     */
    public function setFilesystemName($filesystemName)
    {
        $this->_filesystemName = $filesystemName;
        return $this;
    }

    /**
     * getFilesystemName()
     *
     * @return string
     */
    public function getFilesystemName()
    {
        return $this->_filesystemName;
    }

    /**
     * getPath()
     *
     * @return string
     */
    public function getPath()
    {
        $path = $this->_baseDirectory;
        if ($this->_filesystemName) {
            $path .= '/' . $this->_filesystemName;
        }
        return $path;
    }

    /**
     * exists()
     *
     * @return bool
     */
    public function exists()
    {
        return file_exists($this->getPath());
    }

    /**
     * create()
     *
     * Create this resource/context
     *
     */
    abstract public function create();

    /**
     * delete()
     *
     * Delete this resouce/context
     *
     */
    abstract public function delete();

}


text:
<?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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: ProjectDirectory.php 23775 2011-03-01 17:25:24Z ralph $
 */

/**
 * @see Zend_Tool_Project_Context_Filesystem_Directory
 */
require_once 'Zend/Tool/Project/Context/Filesystem/Directory.php';

/**
 * @see Zend_Tool_Project_Context_System_Interface
 */
require_once 'Zend/Tool/Project/Context/System/Interface.php';

/**
 * @see Zend_Tool_Project_Context_System_TopLevelRestrictable
 */
require_once 'Zend/Tool/Project/Context/System/TopLevelRestrictable.php';

/**
 * @see Zend_Tool_Project_Context_System_NotOverwritable
 */
require_once 'Zend/Tool/Project/Context/System/NotOverwritable.php';

/**
 * This class is the front most class for utilizing Zend_Tool_Project
 *
 * A profile is a hierarchical set of resources that keep track of
 * items within a specific project.
 *
 * @category   Zend
 * @package    Zend_Tool
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Tool_Project_Context_System_ProjectDirectory
    extends Zend_Tool_Project_Context_Filesystem_Directory
    implements Zend_Tool_Project_Context_System_Interface,
               Zend_Tool_Project_Context_System_NotOverwritable,
               Zend_Tool_Project_Context_System_TopLevelRestrictable
{

    /**
     * @var string
     */
    protected $_filesystemName = null;

    /**
     * getName()
     *
     * @return string
     */
    public function getName()
    {
        return 'ProjectDirectory';
    }

    /**
     * init()
     *
     * @return Zend_Tool_Project_Context_System_ProjectDirectory
     */
    public function init()
    {
        // get base path from attributes (would be in path attribute)
        $projectDirectory = $this->_resource->getAttribute('path');

        // if not, get from profile
        if ($projectDirectory == null) {
            $projectDirectory = $this->_resource->getProfile()->getAttribute('projectDirectory');
        }

        // if not, exception.
        if ($projectDirectory == null) {
            require_once 'Zend/Tool/Project/Exception.php';
            throw new Zend_Tool_Project_Exception('projectDirectory cannot find the directory for this project.');
        }

        $this->_baseDirectory = rtrim($projectDirectory, '\\/');
        return $this;
    }

    /**
     * create()
     *
     * @return Zend_Tool_Project_Context_System_ProjectDirectory
     */
    public function create()
    {
        if (file_exists($this->getPath())) {
            /*
            foreach (new DirectoryIterator($this->getPath()) as $item) {
                if (!$item->isDot()) {
                    if ($registry->getClient()->isInteractive()) {
                        // @todo prompt for override
                    } else {
                        require_once 'Zend/Tool/Project/Context/Exception.php';
                        throw new Zend_Tool_Project_Context_Exception('This directory is not empty, project creation aborted.');
                    }
                    break;
                }
            }
            */
        }

        parent::create();
        return $this;
    }

}