import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
47
libs/Zend/Tool/Framework/Manifest/ActionManifestable.php
Normal file
47
libs/Zend/Tool/Framework/Manifest/ActionManifestable.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tool_Framework_Manifest_Interface
|
||||
*/
|
||||
require_once 'Zend/Tool/Framework/Manifest/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Tool_Framework_Manifest_ActionManifestable extends Zend_Tool_Framework_Manifest_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* getActions()
|
||||
*
|
||||
* Should either return a single action, or an array
|
||||
* of actions
|
||||
*
|
||||
* @return array|Zend_Tool_Framework_Action_Interface
|
||||
*/
|
||||
public function getActions();
|
||||
|
||||
}
|
37
libs/Zend/Tool/Framework/Manifest/Exception.php
Normal file
37
libs/Zend/Tool/Framework/Manifest/Exception.php
Normal 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-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tool_Framework_Exception
|
||||
*/
|
||||
require_once 'Zend/Tool/Framework/Exception.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tool_Framework_Manifest_Exception extends Zend_Tool_Framework_Exception
|
||||
{
|
||||
|
||||
}
|
42
libs/Zend/Tool/Framework/Manifest/Indexable.php
Normal file
42
libs/Zend/Tool/Framework/Manifest/Indexable.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Tool_Framework_Manifest_Indexable extends Zend_Tool_Framework_Manifest_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* getActions()
|
||||
*
|
||||
* Should either return a single action, or an array
|
||||
* of actions
|
||||
*
|
||||
* @return array|Zend_Tool_Framework_Action_Interface
|
||||
*/
|
||||
public function getIndex();
|
||||
|
||||
}
|
57
libs/Zend/Tool/Framework/Manifest/Interface.php
Normal file
57
libs/Zend/Tool/Framework/Manifest/Interface.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
interface Zend_Tool_Framework_Manifest_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* The following methods are completely optional, and any combination of them
|
||||
* can be used as part of a manifest. The manifest repository will process
|
||||
* the return values of these actions as specfied in the following method docblocks.
|
||||
*
|
||||
* Since these actions are
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* getMetadata()
|
||||
*
|
||||
* Should either return a single metadata object or an array
|
||||
* of metadata objects
|
||||
*
|
||||
* @return array|Zend_Tool_Framework_Manifest_Metadata
|
||||
**
|
||||
|
||||
public function getMetadata();
|
||||
|
||||
**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* getActions()
|
||||
*
|
||||
* Should either return a single action, or an array
|
||||
* of actions
|
||||
*
|
||||
* @return array|Zend_Tool_Framework_Action_Interface
|
||||
**
|
||||
|
||||
public function getActions();
|
||||
|
||||
**/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* getProviders()
|
||||
*
|
||||
* Should either return a single provider or an array
|
||||
* of providers
|
||||
*
|
||||
**
|
||||
|
||||
public function getProviders();
|
||||
|
||||
**/
|
||||
|
||||
}
|
47
libs/Zend/Tool/Framework/Manifest/MetadataManifestable.php
Normal file
47
libs/Zend/Tool/Framework/Manifest/MetadataManifestable.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tool_Framework_Manifest_Interface.php
|
||||
*/
|
||||
require_once 'Zend/Tool/Framework/Manifest/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Tool_Framework_Manifest_MetadataManifestable extends Zend_Tool_Framework_Manifest_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* getMetadata()
|
||||
*
|
||||
* Should either return a single metadata object or an array
|
||||
* of metadata objects
|
||||
*
|
||||
* @return array|Zend_Tool_Framework_Manifest_Metadata
|
||||
*/
|
||||
public function getMetadata();
|
||||
|
||||
}
|
47
libs/Zend/Tool/Framework/Manifest/ProviderManifestable.php
Normal file
47
libs/Zend/Tool/Framework/Manifest/ProviderManifestable.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tool_Framework_Manifest_Interface.php
|
||||
*/
|
||||
require_once 'Zend/Tool/Framework/Manifest/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Tool_Framework_Manifest_ProviderManifestable extends Zend_Tool_Framework_Manifest_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* getProviders()
|
||||
*
|
||||
* Should either return a single provider or an array
|
||||
* of providers
|
||||
*
|
||||
* @return array|string|Zend_Tool_Framework_Provider_Interface
|
||||
*/
|
||||
public function getProviders();
|
||||
|
||||
}
|
300
libs/Zend/Tool/Framework/Manifest/Repository.php
Normal file
300
libs/Zend/Tool/Framework/Manifest/Repository.php
Normal file
@ -0,0 +1,300 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Tool_Framework_Registry_EnabledInterface
|
||||
*/
|
||||
require_once 'Zend/Tool/Framework/Registry/EnabledInterface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Tool_Framework_Manifest_Repository
|
||||
implements Zend_Tool_Framework_Registry_EnabledInterface, IteratorAggregate, Countable
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Zend_Tool_Framework_Provider_Registry_Interface
|
||||
*/
|
||||
protected $_registry = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_manifests = array();
|
||||
|
||||
/**
|
||||
* @var array Array of Zend_Tool_Framework_Metadata_Interface
|
||||
*/
|
||||
protected $_metadatas = array();
|
||||
|
||||
/**
|
||||
* setRegistry()
|
||||
*
|
||||
* @param Zend_Tool_Framework_Registry_Interface $registry
|
||||
* @return unknown
|
||||
*/
|
||||
public function setRegistry(Zend_Tool_Framework_Registry_Interface $registry)
|
||||
{
|
||||
$this->_registry = $registry;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* addManifest() - Add a manifest for later processing
|
||||
*
|
||||
* @param Zend_Tool_Framework_Manifest_Interface $manifest
|
||||
* @return Zend_Tool_Framework_Manifest_Repository
|
||||
*/
|
||||
public function addManifest(Zend_Tool_Framework_Manifest_Interface $manifest)
|
||||
{
|
||||
// we need to get an index number so that manifests with
|
||||
// higher indexes have priority over others
|
||||
$index = count($this->_manifests);
|
||||
|
||||
if ($manifest instanceof Zend_Tool_Framework_Registry_EnabledInterface) {
|
||||
$manifest->setRegistry($this->_registry);
|
||||
}
|
||||
|
||||
// if the manifest supplies a getIndex() method, use it
|
||||
if ($manifest instanceof Zend_Tool_Framework_Manifest_Indexable) {
|
||||
$index = $manifest->getIndex();
|
||||
}
|
||||
|
||||
// get the required objects from the framework registry
|
||||
$actionRepository = $this->_registry->getActionRepository();
|
||||
$providerRepository = $this->_registry->getProviderRepository();
|
||||
|
||||
// load providers if interface supports that method
|
||||
if ($manifest instanceof Zend_Tool_Framework_Manifest_ProviderManifestable) {
|
||||
$providers = $manifest->getProviders();
|
||||
if (!is_array($providers)) {
|
||||
$providers = array($providers);
|
||||
}
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
if (!$provider instanceof Zend_Tool_Framework_Provider_Interface) {
|
||||
require_once 'Zend/Tool/Framework/Manifest/Exception.php';
|
||||
throw new Zend_Tool_Framework_Manifest_Exception(
|
||||
'A provider provided by the ' . get_class($manifest)
|
||||
. ' does not implement Zend_Tool_Framework_Provider_Interface'
|
||||
);
|
||||
}
|
||||
if (!$providerRepository->hasProvider($provider, false)) {
|
||||
$providerRepository->addProvider($provider);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// load actions if interface supports that method
|
||||
if ($manifest instanceof Zend_Tool_Framework_Manifest_ActionManifestable) {
|
||||
$actions = $manifest->getActions();
|
||||
if (!is_array($actions)) {
|
||||
$actions = array($actions);
|
||||
}
|
||||
|
||||
foreach ($actions as $action) {
|
||||
if (is_string($action)) {
|
||||
$action = new Zend_Tool_Framework_Action_Base($action);
|
||||
}
|
||||
$actionRepository->addAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
// should we detect collisions here? does it even matter?
|
||||
$this->_manifests[$index] = $manifest;
|
||||
ksort($this->_manifests);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getManifests()
|
||||
*
|
||||
* @return Zend_Tool_Framework_Manifest_Interface[]
|
||||
*/
|
||||
public function getManifests()
|
||||
{
|
||||
return $this->_manifests;
|
||||
}
|
||||
|
||||
/**
|
||||
* addMetadata() - add a metadata peice by peice
|
||||
*
|
||||
* @param Zend_Tool_Framework_Manifest_Metadata $metadata
|
||||
* @return Zend_Tool_Framework_Manifest_Repository
|
||||
*/
|
||||
public function addMetadata(Zend_Tool_Framework_Metadata_Interface $metadata)
|
||||
{
|
||||
$this->_metadatas[] = $metadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* process() - Process is expected to be called at the end of client construction time.
|
||||
* By this time, the loader has run and loaded any found manifests into the repository
|
||||
* for loading
|
||||
*
|
||||
* @return Zend_Tool_Framework_Manifest_Repository
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
|
||||
foreach ($this->_manifests as $manifest) {
|
||||
if ($manifest instanceof Zend_Tool_Framework_Manifest_MetadataManifestable) {
|
||||
$metadatas = $manifest->getMetadata();
|
||||
if (!is_array($metadatas)) {
|
||||
$metadatas = array($metadatas);
|
||||
}
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
if (!$metadata instanceof Zend_Tool_Framework_Metadata_Interface) {
|
||||
require_once 'Zend/Tool/Framework/Manifest/Exception.php';
|
||||
throw new Zend_Tool_Framework_Manifest_Exception(
|
||||
'A Zend_Tool_Framework_Metadata_Interface object was not found in manifest ' . get_class($manifest)
|
||||
);
|
||||
}
|
||||
|
||||
$this->addMetadata($metadata);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMetadatas() - This is the main search function for the repository.
|
||||
*
|
||||
* @example This will retrieve all metadata that matches the following criteria
|
||||
* $manifestRepo->getMetadatas(array(
|
||||
* 'providerName' => 'Version',
|
||||
* 'actionName' => 'show'
|
||||
* ));
|
||||
*
|
||||
* @param array $searchProperties
|
||||
* @param bool $includeNonExistentProperties
|
||||
* @return Zend_Tool_Framework_Manifest_Metadata[]
|
||||
*/
|
||||
public function getMetadatas(Array $searchProperties = array(), $includeNonExistentProperties = true)
|
||||
{
|
||||
|
||||
$returnMetadatas = array();
|
||||
|
||||
// loop through the metadatas so that we can search each individual one
|
||||
foreach ($this->_metadatas as $metadata) {
|
||||
|
||||
// each value will be retrieved from the metadata, each metadata should
|
||||
// implement a getter method to retrieve the value
|
||||
foreach ($searchProperties as $searchPropertyName => $searchPropertyValue) {
|
||||
if (method_exists($metadata, 'get' . $searchPropertyName)) {
|
||||
if ($metadata->{'get' . $searchPropertyName}() != $searchPropertyValue) {
|
||||
// if the metadata supports a specific property but the value does not
|
||||
// match, move on
|
||||
continue 2;
|
||||
}
|
||||
} elseif (!$includeNonExistentProperties) {
|
||||
// if the option $includeNonExitentProperties is false, then move on as
|
||||
// we dont want to include this metadata if non existent
|
||||
// search properties are not inside the target (current) metadata
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
// all searching has been accounted for, if we reach this point, then the metadata
|
||||
// is good and we can return it
|
||||
$returnMetadatas[] = $metadata;
|
||||
|
||||
}
|
||||
|
||||
return $returnMetadatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* getMetadata() - This will proxy to getMetadatas(), but will only return a single metadata. This method
|
||||
* should be used in situations where the search criteria is known to only find a single metadata object
|
||||
*
|
||||
* @param array $searchProperties
|
||||
* @param bool $includeNonExistentProperties
|
||||
* @return Zend_Tool_Framework_Manifest_Metadata
|
||||
*/
|
||||
public function getMetadata(Array $searchProperties = array(), $includeNonExistentProperties = true)
|
||||
{
|
||||
$metadatas = $this->getMetadatas($searchProperties, $includeNonExistentProperties);
|
||||
return array_shift($metadatas);
|
||||
}
|
||||
|
||||
/**
|
||||
* __toString() - cast to string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$metadatasByType = array();
|
||||
|
||||
foreach ($this->_metadatas as $metadata) {
|
||||
if (!array_key_exists($metadata->getType(), $metadatasByType)) {
|
||||
$metadatasByType[$metadata->getType()] = array();
|
||||
}
|
||||
$metadatasByType[$metadata->getType()][] = $metadata;
|
||||
}
|
||||
|
||||
$string = '';
|
||||
foreach ($metadatasByType as $type => $metadatas) {
|
||||
$string .= $type . PHP_EOL;
|
||||
foreach ($metadatas as $metadata) {
|
||||
$metadataString = ' ' . $metadata->__toString() . PHP_EOL;
|
||||
//$metadataString = str_replace(PHP_EOL, PHP_EOL . ' ', $metadataString);
|
||||
$string .= $metadataString;
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* count() - required by the Countable Interface
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->_metadatas);
|
||||
}
|
||||
|
||||
/**
|
||||
* getIterator() - required by the IteratorAggregate interface
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->_metadatas);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user