Server IP : 66.29.132.122 / Your IP : 3.145.12.181 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/proc/self/root/proc/thread-self/root/proc/thread-self/root/proc/self/root/proc/thread-self/root/proc/self/root/proc/self/root/proc/self/root/proc/thread-self/root/opt/alt/php55/usr/share/doc/pear/DependencyInjection/Symfony/Component/DependencyInjection/ |
Upload File : |
DependencyInjection Component ============================= DependencyInjection manages your services via a robust and flexible Dependency Injection Container. Here is a simple example that shows how to register services and parameters: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; $sc = new ContainerBuilder(); $sc ->register('foo', '%foo.class%') ->addArgument(new Reference('bar')) ; $sc->setParameter('foo.class', 'Foo'); $sc->get('foo'); 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'); Resources --------- You can run the unit tests with the following command: $ cd path/to/Symfony/Component/DependencyInjection/ $ composer.phar install $ phpunit