|
Hi all,
I would like to know what would be the best way to configure an instance of an adapter class generated through a factory method from another class. In my concrete example, I have a component which has dependency on * Zend\Cache\Storage\Adapter\AbstractAdapter* whose instances get generated through the class *Zend\Cache\StorageFactory*. So I would like to know what would be the proper way to specify the "generation" of this class in the "module.config.php" file. Currently, I have this 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( 'my_component' => 'My\Component', 'zend_cache_storage_adapter_apc' => 'Zend\Cache\Storage\Adapter\AbstractAdapter' ), 'my_component' => array( 'injections' => array( 'cache' => 'zend_cache_storage_adapter_apc' ) ), 'zend_cache_storage_adapter_apc' => array( 'parameters' => array( 'adapter' => array( 'name' => 'apc', 'options' => array( 'ttl' => 123, ) ), 'plugins' => array('Serializer') ) ) ) ) ); When the code gets executed, a *"Zend\Di\Exception\MissingPropertyException" * is thrown telling "Missing instance/object for parameter cfg for Zend\Cache\StorageFactory::factory". I have googled a lot, but no way to find a good example of this kind of situation. If someone could help me, it would be so appreciated!! Thanks in advance! Christian. |
|
Where do you set the 'cfg' parameter when getting the storage factory? I
don't see any usage of it... Marco Pivetta http://twitter.com/Ocramius http://marco-pivetta.com On 2 January 2012 20:36, theUniC <[hidden email]> wrote: > Hi all, > > I would like to know what would be the best way to configure an instance of > an adapter class generated through a factory method from another class. In > my concrete example, I have a component which has dependency on * > Zend\Cache\Storage\Adapter\AbstractAdapter* whose instances get generated > through the class *Zend\Cache\StorageFactory*. So I would like to know what > would be the proper way to specify the "generation" of this class in the > "module.config.php" file. Currently, I have this 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( > > 'my_component' => 'My\Component', > > 'zend_cache_storage_adapter_apc' => > 'Zend\Cache\Storage\Adapter\AbstractAdapter' > > ), > > 'my_component' => array( > > 'injections' => array( > > 'cache' => 'zend_cache_storage_adapter_apc' > > ) > > ), > > 'zend_cache_storage_adapter_apc' => array( > > 'parameters' => array( > > 'adapter' => array( > > 'name' => 'apc', > > 'options' => array( > > 'ttl' => 123, > > ) > > ), > > 'plugins' => array('Serializer') > > ) > > ) > > ) > > ) > > ); > When the code gets executed, a > *"Zend\Di\Exception\MissingPropertyException" > * is thrown telling "Missing instance/object for parameter cfg for > Zend\Cache\StorageFactory::factory". > > I have googled a lot, but no way to find a good example of this kind of > situation. If someone could help me, it would be so appreciated!! > > Thanks in advance! > Christian. > |
|
In reply to this post by theUniC
theUniC, Did you find a solution to this? I'm also getting the same error even though I pass the cfg parameter; 'di' => array( 'instance' => array( 'alias' => array( 'cache' => 'Zend\Cache\StorageFactory', ), 'cache' => array( 'injections' => array( 'factory' => array( 'cfg' => array( 'adapter' => array( 'name' => 'Filesystem', 'options' => array( 'dirLevel' => 2, 'cacheDir' => __DIR__ . '/../../data/cache', ), ), 'plugins' => array( 'Serializer' ), ), ), ), ), ), ) PHP Warning: Missing argument 1 for Zend\Cache\StorageFactory::factory() in /***/Zend/Cache/StorageFactory.php on line 59 Thanks! |
|
In reply to this post by theUniC
Hi all.
currently, my setting for Zend\Cache & Factory. It works. In Module. https://github.com/sasezaki/AzunyanModule/blob/master/config/module.config.php In case usage as Di Component https://gist.github.com/2291030 -- List: [hidden email] Info: http://framework.zend.com/archives Unsubscribe: [hidden email] |
Thanks sasezaki! That worked! but I'm still having trouble with Serializer plugin: 'cache' => array( 'parameters' => array('cfg' => array( 'adapter' => array( 'name' => 'Filesystem', 'options' => array( 'dirLevel' => 2, 'cacheDir' => __DIR__ . '/../../../data/cache', ), ), 'plugins' => array( 'Serializer' ), ), ), ), This worked before taking the latest zf2 version update, is there some sort of new option I need to pass? |
|
anyone?
|
|
Hey, did you already read through http://packages.zendframework.com/docs/latest/manual/en/zend.cache.html ? That is not very complete, but should be up to date :)
Marco Pivetta http://twitter.com/Ocramius http://marco-pivetta.com On 21 April 2012 16:14, cmple [via Zend Framework Community] <[hidden email]> wrote: anyone? |
Yeah, I've read it before and I had it working, but after taking the latest zf2 update it looks like the plugin functionality has stopped working Try pasting the following code in Module initializeView() function: $cache = StorageFactory::factory(array( 'adapter' => array( 'name' => 'Filesystem', 'options' => array( 'cacheDir' => __DIR__ . '/../../data/cache', ), ), 'plugins' => array('serializer'), )); $cache->setItem('testing-array', array('hello' => 'test')); $array = $cache->getItem('testing-array'); print_r($array); this outputs a string 'test' instead of an array array('hello' => 'test') |
| Powered by Nabble | Edit this page |
