adding zend project folders into old campcaster.

This commit is contained in:
naomiaro 2010-12-07 14:19:27 -05:00
parent 56abfaf28e
commit 7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Tool_Project_Exception
*/
require_once 'Zend/Tool/Project/Exception.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Profile_Exception extends Zend_Tool_Project_Exception
{
}

View file

@ -0,0 +1,54 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
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);
}

View file

@ -0,0 +1,240 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Xml.php 20967 2010-02-07 18:17:49Z 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-2010 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();
}
}
}
}

View file

@ -0,0 +1,211 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: ContextFilter.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* This class is an iterator that will iterate only over enabled resources
*
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
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);
}
}

View file

@ -0,0 +1,43 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: EnabledResourceFilter.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* This class is an iterator that will iterate only over enabled resources
*
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter extends RecursiveFilterIterator
{
/**
* accept() is required by teh RecursiveFilterIterator
*
* @return bool
*/
public function accept()
{
return $this->current()->isEnabled();
}
}

View file

@ -0,0 +1,262 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Resource.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @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-2010 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);
}
}
}

View file

@ -0,0 +1,421 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Container.php 20967 2010-02-07 18:17:49Z 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-2010 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;
}
}
}

View file

@ -0,0 +1,117 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: SearchConstraints.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* This class is an iterator that will iterate only over enabled resources
*
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
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);
}
}