Created
November 12, 2011 13:42
-
-
Save Ocramius/1360533 to your computer and use it in GitHub Desktop.
Zend\Db adapter instantiation through Zend Framework 2 Di
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'di' => array( | |
'definition' => array( | |
//teaching DI to use the factory | |
'class' => array( | |
'Zend\Db\Db' => array( | |
'methods' => array( | |
'factory' => array( | |
'adapter' => array( | |
'type' => false, | |
'required' => true, | |
), | |
'config' => array( | |
'type' => false, | |
'required' => false, | |
), | |
), | |
), | |
), | |
'Zend\Db\Adapter\AbstractAdapter' => array( | |
'instantiator' => array( | |
'Zend\Db\Db', | |
'factory', | |
), | |
), | |
), | |
), | |
'instance' => array( | |
'alias' => array( | |
//we just know it's an abstract adapter | |
'my-db-adapter' => 'Zend\Db\Adapter\AbstractAdapter', | |
), | |
//documentmanager | |
'my-db-adapter' => array( | |
'parameters' => array( | |
'adapter' => array( | |
// same db factory parameters you used in 1.x (I suppose) | |
), | |
), | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have multiple defined, yes. Otherwise, if you typehint your methods correctly, like following:
Then, if you defined an alias
'my-stuff'
for an instance of typeMy\Stuff
, you could just useZend\Di\Configuration
option'preference'
, like following, you should not be worried about defining injections manually every time:That is just an example config. You can find more examples about
Zend\Di
at https://github.com/ralphschindler/Zend_DI-Examples