Skip to content

Static factory method use case #1

@theUniC

Description

@theUniC

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions