Zend_DI-Examples
Zend_DI-Examples copied to clipboard
Static factory method use case
Hi Ralph,
Could be possible to add a static factory method use case as an example? I'm in the case I have a dependency of a Zend\Cache\Storage\Adapter\AbstractAdapter
that gets generated via Zend\Cache\StorageFactory
, but I'm not able to find the way to get an instance of the AbstractAdapter and fullfil the dependency. Googling a bit I could get this snippet from some example seen in a gist
<?php
// file MyModule/configs/module.config.php
return array(
'di' => array(
'definition' => array(
'class' => array(
'Zend\Cache\StorageFactory' => array(
'methods' => array(
'factory' => array(
'cfg' => array(
'type' => false,
'required' => true
)
)
)
),
'Zend\Cache\Storage\Adapter\AbstractAdapter' => array(
'instantiator' => array(
'Zend\Cache\StorageFactory',
'factory'
)
)
)
),
'instance' => array(
'alias' => array(
'class_with_dependency' => 'Class\With\Dependency',
'zend_cache_storage_adapter_apc' => 'Zend\Cache\Storage\Adapter\AbstractAdapter'
),
'class_with_dependency' => array(
'injections' => array(
'cache' => 'zend_cache_storage_adapter_apc'
)
),
'zend_cache_storage_adapter_apc' => array(
'parameters' => array(
'cfg' => array(
'adapter' => array(
'name' => 'apc',
'options' => array(
'ttl' => 123,
)
),
'plugins' => array('Serializer')
)
)
)
),
),
);
Thanks in advance! Christian.
I need to update the examples to use beta2, ill add an example for this as well. Catch me on IRC today, -ralph
Hi Ralph!
Thanks a lot! I'll do it! See you on IRC :D
Christian.