Last active
December 9, 2015 23:39
-
-
Save Djuki/4345622 to your computer and use it in GitHub Desktop.
Primer korišćenja IoC containera
This file contains 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 | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\DependencyInjection\Reference; | |
// Create IoC container | |
$container = new ContainerBuilder(); | |
// Register Engine object and parameter for constructor | |
$container->register('my.engine', '\\Model\\Engine') | |
->addArgument(1800); | |
//Register Tractor object and Engine object for his constructor | |
$container->register('my.tractor', '\\Model\\Tractor') | |
->addArgument(new Reference('my.engine')); | |
// IoC container will return Tractor object | |
$tractor = $container->get('my.tractor'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment