Skip to content

Commit

Permalink
Added Method Call, Factory Class and File Include examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Webb authored and fabpot committed Apr 20, 2012
1 parent efc1a0d commit 23707bd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Symfony/Component/DependencyInjection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,51 @@ PHPUnit:

export SYMFONY_CONFIG=../path/to/Config
export SYMFONY_YAML=../path/to/Yaml

More Examples
-------------

Method Calls (Setter Injection):

$sc = new ContainerBuilder();

$sc
->register('bar', '%bar.class%')
->addMethodCall('setFoo', array(new Reference('foo')))
;
$sc->setParameter('bar.class', 'Bar');

$sc->get('bar');

Factory Class:

If your service is retrieved by calling a static method:

$sc = new ContainerBuilder();

$sc
->register('bar', '%bar.class%')
->setFactoryClass('%bar.class%')
->setFactoryMethod('getInstance')
->addArgument('Aarrg!!!')
;
$sc->setParameter('bar.class', 'Bar');

$sc->get('bar');

File Include:

For some services, especially those that are difficult or impossible to
autoload, you may need the container to include a file before
instantiating your class.

$sc = new ContainerBuilder();

$sc
->register('bar', '%bar.class')
->setFile('/path/to/file')
->addArgument('Aarrg!!!')
;
$sc->setParameter('bar.class', 'Bar');

$sc->get('bar');

0 comments on commit 23707bd

Please sign in to comment.