Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static factory method use case #1

Open
theUniC opened this issue Dec 29, 2011 · 2 comments
Open

Static factory method use case #1

theUniC opened this issue Dec 29, 2011 · 2 comments

Comments

@theUniC
Copy link

theUniC commented Dec 29, 2011

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.

@ralphschindler
Copy link
Owner

I need to update the examples to use beta2, ill add an example for this as well.
Catch me on IRC today,
-ralph

@theUniC
Copy link
Author

theUniC commented Jan 3, 2012

Hi Ralph!

Thanks a lot! I'll do it! See you on IRC :D

Christian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants