|
<h1>Pimple</h1> |
|
|
|
<?php |
|
$container['cookie_name'] = 'SESSION_ID'; |
|
|
|
$container['session_storage'] = function ($c) { |
|
return new $c['session_storage_class']($c['cookie_name']); |
|
}; |
|
?> |
|
|
|
|
|
<h1>Symfony</h1> |
|
|
|
YAML: |
|
parameters: |
|
# ... |
|
mailer.transport: sendmail |
|
|
|
services: |
|
mailer: |
|
class: Mailer |
|
arguments: [%mailer.transport%] |
|
newsletter_manager: |
|
class: NewsletterManager |
|
calls: |
|
- [ setMailer, [ @mailer ] ] |
|
|
|
PHP: |
|
<?php |
|
$container->setParameter('mailer.transport', 'sendmail'); |
|
$container |
|
->register('mailer', 'Mailer') |
|
->addArgument('%mailer.transport%'); |
|
|
|
$container |
|
->register('newsletter_manager', 'NewsletterManager') |
|
->addMethodCall('setMailer', array(new Reference('mailer'))); |
|
?> |
|
|
|
|
|
<h1>Zend Framework</h1> |
|
|
|
<?php |
|
$config = array( |
|
'definition' => array( |
|
'compiler' => array(/* @todo compiler information */), |
|
'runtime' => array(/* @todo runtime information */), |
|
'class' => array( |
|
'instantiator' => '', // the name of the instantiator, by default this is __construct |
|
'supertypes' => array(), // an array of supertypes the class implements |
|
'methods' => array( |
|
'setSomeParameter' => array( // a method name |
|
'parameterName' => array( |
|
'name', // string parameter name |
|
'type', // type or null |
|
'is-required' // bool |
|
) |
|
) |
|
|
|
) |
|
) |
|
) |
|
); |
|
?> |
|
|
|
|
|
<h1>Aura.DI</h1> |
|
|
|
<?php |
|
$di->set('database', function() use ($di) { |
|
return $di->newInstance('Example\Package\Database', [ |
|
'hostname' => 'localhost', |
|
'username' => 'user', |
|
'password' => 'passwd', |
|
]); |
|
}); |
|
|
|
$di->params['Example\Package\Database'] = [ |
|
'hostname' => 'localhost', |
|
'username' => 'user', |
|
'password' => 'passwd', |
|
]; |
|
|
|
$di->set('database', function() use ($di) { |
|
return $di->newInstance('Example\Package\Database'); |
|
}); |
|
|
|
// default params for the model factory |
|
$di->params['Example\Package\ModelFactory'] = [ |
|
// a map of model names to model factories |
|
'map' => [ |
|
'blog' => $di->newFactory('Example\Package\BlogModel'), |
|
'wiki' => $di->newFactory('Example\Package\WikiModel'), |
|
], |
|
]; |
|
|
|
$di->set('database', $di->lazyNew('Example\Package\Database')); |
|
|
|
// Setter injection |
|
$di->setter['Example\Package\Foo']['setDb'] = $di->lazyNew('Example\Package\Database', [ |
|
'hostname' => 'example.com', |
|
]); |
|
?> |
|
|
|
|
|
<h1>Ding</h1> |
|
|
|
beans: !!map |
|
aDependencyBean: |
|
class: DependencyBean |
|
scope: singleton |
|
aspectBean: |
|
class: AspectBean |
|
scope: singleton |
|
parentBean: |
|
abstract: true |
|
properties: !!map |
|
someProperty: |
|
ref: aDependencyBean |
|
aspects: |
|
aspectA: |
|
pointcuts: |
|
pointcutA: |
|
method: invoke |
|
expression: ^get.* |
|
type: method |
|
ref: aspectBean |
|
childBean: |
|
parent: parentBean |
|
class: MyBean |
|
scope: singleton |
|
properties: !!map |
|
someOtherProperty: |
|
value: blah |
|
|
|
Or annotations |
|
|
|
|
|
<h1>Orno DI</h1> |
|
|
|
<?php |
|
$container->register('session', 'Session') |
|
->withArguments([new Storage, 'my_session_key']); |
|
$container->register('session', 'Session') |
|
->withMethodCall('setStorage', [new Storage]) |
|
->withMethodCall('setSessionKey', ['my_session_key']); |
|
?> |