What about an aggregate metadata factory implementation, so you could pass
it multiple metadata factory instances of varying types.
For example...
class Zend_Entity_MetadataFactory_Aggregate implements
Zend_Entity_MetadataFactory_Interface
{
protected $_metadataFactories = array();
protected $_maps;
protected $_entityNames;
public function __construct(array $metadataFactories)
{
$this->_metadataFactories = $metadataFactories;
}
protected function _loadDefinitions()
{
if ($this->_maps === null) {
$this->_maps = array();
$this->_entityNames = array();
foreach ($this->_metadataFactories as $metadataFactory) {
$this->_maps =
array_merge($metadataFactory->getDefinitionEntityNames(), $this->_maps);
}
$this->_entityNames = array_keys($this->_maps);
}
}
/**
* Retrieve an array of all definitions by name.
*
* @return array
*/
public function getDefinitionEntityNames()
{
$this->_loadDefinitions();
return $this->_entityNames;
}
/**
* Get an Entity Mapper Definition by the name of the Entity
*
* @param string $entityName
* @throws Zend_Entity_InvalidEntityException
* @return Zend_Entity_Definition_Entity
*/
public function getDefinitionByEntityName($entityName)
{
$this->_loadDefinitions();
if(!isset($this->_maps[$entityName])) {
throw new Zend_Entity_InvalidEntityException("The entity
'".$entityName."' is unknown.");
}
return $this->_maps[$entityName];
}
/**
*
* @param string $visitorClass
* @return Zend_Entity_Definition_MappingVisitor[]
*/
public function transform($visitorClass)
{
// ...
}
}
2009/9/11 keith Pope <[email protected]>
> 2009/9/11 keith Pope <[email protected]>:
> > Hi,
> >
> > I am just having a look at Zend_Entity, I was wondering how it handles
> > object/entity instantiation, having a look through the code the
> > Zend_Db_Mapper_Loader_LoaderAbstract has a createEntity() method which
> > instantiates the entity. Is it planned that we will be able to
> > override this and provide custom instantiation code/loaders for the
> > entity manager? I am coming from the angle that it would be nice to be
> > able to inject a DI container into the manager, maybe I am thinking
> > about it wrong?
> >
> > Other than that the docs were really good and I was able to get
> > everything working very quickly, good work :)
> >
> > Thx
> >
> > Keith
> >
>
> Another bit of feedback....
>
> When creating the Mappings from the metadata it would be nice if you
> could specifiy either multiple paths or add more than one
> Zend_Entity_MetadataFactory_Code to the create method. This way we can
> have module specific metadata and load it via a boostrap class
> resource.
>