The state of DI in PHP
The state of DI in PHP About me  Stephan Hochdörfer, bitExpert AG  Department Manager Research Labs  enjoying PHP since...
The state of DI in PHP What are Dependencies?
The state of DI in PHP Are Dependencies bad?
The state of DI in PHP Are Dependencies bad?                         Not at all!
The state of DI in PHP Are Dependencies bad?     Hard-coded dependencies are bad!
The state of DI in PHP Tightly coupled code
The state of DI in PHP No reuse of components
The state of DI in PHP No isolation, not testable!
The state of DI in PHP Dependency madness!
The state of DI in PHP What`s DI about?
The state of DI in PHP What`s DI about?  new TalkService(new TalkRepository());
The state of DI in PHP What`s DI about?    Consumer
The state of DI in PHP What`s DI about?    Consumer             Dependencies
The state of DI in PHP What`s DI about?    Consumer             Dependencies   Container
The state of DI in PHP What`s DI about?    Consumer             Dependencies   Container
The state of DI in PHP A little bit of history...
The state of DI in PHP 1988         „Designing Reusable Classes“                   Ralph E. Johnson & Brian Foote
The state of DI in PHP 1996  „The Dependency Inversion Principle“                         Robert C. Martin
The state of DI in PHP 2004   „Inversion of Control Containers and    the Dependency Injection pattern“                   ...
The state of DI in PHP 2005 / 2006               Garden, a lightweight               DI container for PHP.
The state of DI in PHP 2006                First PHP5 framework                    with DI support
The state of DI in PHP 2007    International PHP Conference 2007         features 2 talks about DI.
The state of DI in PHP 2011            Zend Framework 2 (beta),              Symfony2, Flow3, ...
The state of DI in PHP Choose wisely!     Simple Container    vs.    Full stacked                               DI Framework
The state of DI in PHP                         Pimple
The state of DI in PHP Pimple – First steps <?php class TalkService {     public function __construct() {     }     public...
The state of DI in PHP Pimple – First steps <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.php;...
The state of DI in PHP Pimple – Constructor Injection <?php interface GenericRepository {     public function readTalks();...
The state of DI in PHP Pimple – Constructor Injection <?php require_once /path/to/Pimple.php; require_once /path/to/TalkSe...
The state of DI in PHP Pimple – Setter Injection <?php class Logger {     public function doLog($logMsg) {     } } class T...
The state of DI in PHP Pimple – Setter Injection <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService...
The state of DI in PHP Pimple – General usage <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.ph...
The state of DI in PHP                         Bucket
The state of DI in PHP Bucket – Constructor Injection <?php interface GenericRepository {     public function readTalks();...
The state of DI in PHP Bucket – Constructor Injection <?php require_once /path/to/bucket.inc.php; require_once /path/to/Ta...
The state of DI in PHP
The state of DI in PHP ZendDi – First steps <?php namespace Acme; class TalkService {     public function __construct() { ...
The state of DI in PHP ZendDi – First steps <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->ge...
The state of DI in PHP ZendDi – Constructor Injection <?php namespace Acme; interface GenericRepository {     public funct...
The state of DI in PHP ZendDi – Constructor Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $s...
The state of DI in PHP ZendDi – Setter Injection <?php namespace Acme; class Logger {     public function doLog($logMsg) {...
The state of DI in PHP ZendDi – Setter Injection <?php $di = new ZendDiDi(); $di->configure(     new ZendDiConfiguration( ...
The state of DI in PHP ZendDi – Interface Injection <?php namespace Acme; class Logger {     public function doLog($logMsg...
The state of DI in PHP ZendDi – Interface Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $ser...
The state of DI in PHP ZendDi – General usage <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); var_dump($...
The state of DI in PHP ZendDi – Builder Definition <?php // describe dependency $dep = new ZendDiDefinitionBuilderPhpClass...
The state of DI in PHP ZendDi – Builder Definition <?php // add to Di $defList = new ZendDiDefinitionList($builder); $di =...
The state of DI in PHP
The state of DI in PHP Symfony2 <?php namespace AcmeTalkBundleController; use SymfonyBundleFrameworkBundleControllerContro...
The state of DI in PHP Symfony2 – Configuration file File services.xml in src/Acme/DemoBundle/Resources/config <?xml versi...
The state of DI in PHP Symfony2 – Constructor Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema...
The state of DI in PHP Symfony2 – Setter Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/...
The state of DI in PHP Symfony2 – Setter Injection (optional) <?xml version="1.0" ?> <container xmlns="http://symfony.com/...
The state of DI in PHP Symfony2 – Property Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/di...
The state of DI in PHP Symfony2 – Interface Injection                         Not supported!
The state of DI in PHP Symfony2 – private/public Services <?xml version="1.0" ?> <container xmlns="http://symfony.com/sche...
The state of DI in PHP Symfony2 – Service inheritance <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/d...
The state of DI in PHP Symfony2 – Service scoping <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/s...
The state of DI in PHP
The state of DI in PHP Flow3 – Constructor Injection <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW...
The state of DI in PHP Flow3 – Setter Injection (manually) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations a...
The state of DI in PHP Flow3 – Setter Injection (manually) File Objects.yaml in Packages/Application/Acme.Demo/Configurati...
The state of DI in PHP Flow3 – Setter Injection (Automagic) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations ...
The state of DI in PHP Flow3 – Setter Injection (Automagic) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations ...
The state of DI in PHP Flow3 – Property Injection <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; ...
The state of DI in PHP Flow3 – Property Injection (with Interface) <?php namespace AcmeDemoController; use TYPO3FLOW3Annot...
The state of DI in PHP Flow3 – Property Injection (with Interface) File Objects.yaml in Packages/Application/Acme.Demo/Con...
The state of DI in PHP Flow3 – Scoping <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /**  * @FLO...
Real World Dependency Injection Benefits
Real World Dependency Injection Benefits  Loose coupling, reuse of components!
Real World Dependency Injection Benefits       Can reduce the amount of code!
Real World Dependency Injection Benefits               Helps developers to               understand the code!
Real World Dependency Injection Cons – Developers need mindshift            Configuration ↔ Runtime
The state of DI in PHP Cons - PSR for DI container missing!
The state of DI in PHP Lack of IDE support
Thank you!
http://joind.in/6250
Upcoming SlideShare
Loading in...5
×

The state of DI - DPC12

1,102

Published on

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,102
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
18
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

The state of DI - DPC12

  1. 1. The state of DI in PHP
  2. 2. The state of DI in PHP About me  Stephan Hochdörfer, bitExpert AG  Department Manager Research Labs  enjoying PHP since 1999  7 years of DI experience (in PHP)  S.Hochdoerfer@bitExpert.de  @shochdoerfer
  3. 3. The state of DI in PHP What are Dependencies?
  4. 4. The state of DI in PHP Are Dependencies bad?
  5. 5. The state of DI in PHP Are Dependencies bad? Not at all!
  6. 6. The state of DI in PHP Are Dependencies bad? Hard-coded dependencies are bad!
  7. 7. The state of DI in PHP Tightly coupled code
  8. 8. The state of DI in PHP No reuse of components
  9. 9. The state of DI in PHP No isolation, not testable!
  10. 10. The state of DI in PHP Dependency madness!
  11. 11. The state of DI in PHP What`s DI about?
  12. 12. The state of DI in PHP What`s DI about? new TalkService(new TalkRepository());
  13. 13. The state of DI in PHP What`s DI about? Consumer
  14. 14. The state of DI in PHP What`s DI about? Consumer Dependencies
  15. 15. The state of DI in PHP What`s DI about? Consumer Dependencies Container
  16. 16. The state of DI in PHP What`s DI about? Consumer Dependencies Container
  17. 17. The state of DI in PHP A little bit of history...
  18. 18. The state of DI in PHP 1988 „Designing Reusable Classes“ Ralph E. Johnson & Brian Foote
  19. 19. The state of DI in PHP 1996 „The Dependency Inversion Principle“ Robert C. Martin
  20. 20. The state of DI in PHP 2004 „Inversion of Control Containers and the Dependency Injection pattern“ Martin Fowler
  21. 21. The state of DI in PHP 2005 / 2006 Garden, a lightweight DI container for PHP.
  22. 22. The state of DI in PHP 2006 First PHP5 framework with DI support
  23. 23. The state of DI in PHP 2007 International PHP Conference 2007 features 2 talks about DI.
  24. 24. The state of DI in PHP 2011 Zend Framework 2 (beta), Symfony2, Flow3, ...
  25. 25. The state of DI in PHP Choose wisely! Simple Container vs. Full stacked DI Framework
  26. 26. The state of DI in PHP Pimple
  27. 27. The state of DI in PHP Pimple – First steps <?php class TalkService { public function __construct() { } public function getTalks() { } }
  28. 28. The state of DI in PHP Pimple – First steps <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.php; // create the Container $container = new Pimple(); // define talkService object in container $container[talkService] = function ($c) { return new TalkService(); }; // instantiate talkService from container $talkService = $container[talkService];
  29. 29. The state of DI in PHP Pimple – Constructor Injection <?php interface GenericRepository { public function readTalks(); } class TalkRepository implements GenericRepository { public function readTalks() { } } class TalkService { public function __construct(TalkRepository $repo) { } public function getTalks() { } }
  30. 30. The state of DI in PHP Pimple – Constructor Injection <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.php; // create the Container $container = new Pimple(); // define services in container $container[talkRepository] = function ($c) { return new TalkRepository(); }; $container[talkService] = function ($c) { return new TalkService($c[talkRepository]); }; // instantiate talkService from container $talkService = $container[talkService];
  31. 31. The state of DI in PHP Pimple – Setter Injection <?php class Logger { public function doLog($logMsg) { } } class TalkService { public function __construct(TalkRepository $repo) { } public function setLogger(Logger $logger) { } public function getTalks() { } }
  32. 32. The state of DI in PHP Pimple – Setter Injection <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.php; // create the Container $container = new Pimple(); // define services in container $container[logger] = function ($c) { return new Logger(); }; $container[talkRepository] = function ($c) { return new TalkRepository(); }; $container[talkService] = function ($c) { $service = new TalkService($c[talkRepository]); $service->setLogger($c[logger]); return $service; }; // instantiate talkService from container $talkService = $container[talkService];
  33. 33. The state of DI in PHP Pimple – General usage <?php require_once /path/to/Pimple.php; require_once /path/to/TalkService.php; // create the Container $container = new Pimple(); // define services in container $container[loggerShared] = $c->share(function ($c) { return new Logger(); )}; $container[logger] = function ($c) { return new Logger(); }; // instantiate logger from container $logger = $container[logger]; // instantiate shared logger from container (same instance!) $logger2 = $container[loggerShared]; $logger3 = $container[loggerShared];
  34. 34. The state of DI in PHP Bucket
  35. 35. The state of DI in PHP Bucket – Constructor Injection <?php interface GenericRepository { public function readTalks(); } class TalkRepository implements GenericRepository { public function readTalks() { } } class TalkService { public function __construct(TalkRepository $repo) { } public function getTalks() { } }
  36. 36. The state of DI in PHP Bucket – Constructor Injection <?php require_once /path/to/bucket.inc.php; require_once /path/to/TalkService.php; // create the Container $container = new bucket_Container(); // instantiate talkService from container $talkService = $container->create(TalkService); // instantiate shared instances from container $talkService2 = $container->get(TalkService); $talkService3 = $container->get(TalkService);
  37. 37. The state of DI in PHP
  38. 38. The state of DI in PHP ZendDi – First steps <?php namespace Acme; class TalkService { public function __construct() { } public function getTalks() { } }
  39. 39. The state of DI in PHP ZendDi – First steps <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  40. 40. The state of DI in PHP ZendDi – Constructor Injection <?php namespace Acme; interface GenericRepository { public function readTalks(); } class TalkRepository implements GenericRepository { public function readTalks() { } } class TalkService { public function __construct(TalkRepository $repo) { } public function getTalks() { } }
  41. 41. The state of DI in PHP ZendDi – Constructor Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  42. 42. The state of DI in PHP ZendDi – Setter Injection <?php namespace Acme; class Logger { public function doLog($logMsg) { } } class TalkService { public function __construct(TalkRepository $repo) { } public function setLogger(Logger $logger) { } public function getTalks() { } }
  43. 43. The state of DI in PHP ZendDi – Setter Injection <?php $di = new ZendDiDi(); $di->configure( new ZendDiConfiguration( array( definition => array( class => array( AcmeTalkService => array( setLogger => array(required => true) ) ) ) ) ) ); $service = $di->get(AcmeTalkService); var_dump($service);
  44. 44. The state of DI in PHP ZendDi – Interface Injection <?php namespace Acme; class Logger { public function doLog($logMsg) { } } interface LoggerAware { public function setLogger(Logger $logger); } class TalkService implements LoggerAware { public function __construct(TalkRepository $repo) { } public function setLogger(Logger $logger) { } public function getTalks() { } }
  45. 45. The state of DI in PHP ZendDi – Interface Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  46. 46. The state of DI in PHP ZendDi – General usage <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); var_dump($service); $service2 = $di->get(AcmeTalkService); var_dump($service2); // same instance as $service $service3 = $di->get( AcmeTalkService, array( repo => new phpbnl12TalkRepository() ) ); var_dump($service3); // new instance
  47. 47. The state of DI in PHP ZendDi – Builder Definition <?php // describe dependency $dep = new ZendDiDefinitionBuilderPhpClass(); $dep->setName(AcmeTalkRepository); // describe class $class = new ZendDiDefinitionBuilderPhpClass(); $class->setName(AcmeTalkService); // add injection method $im = new ZendDiDefinitionBuilderInjectionMethod(); $im->setName(__construct); $im->addParameter(repo, AcmeTalkRepository); $class->addInjectionMethod($im); // configure builder $builder = new ZendDiDefinitionBuilderDefinition(); $builder->addClass($dep); $builder->addClass($class);
  48. 48. The state of DI in PHP ZendDi – Builder Definition <?php // add to Di $defList = new ZendDiDefinitionList($builder); $di = new ZendDiDi($defList); $service = $di->get(AcmeTalkService); var_dump($service);
  49. 49. The state of DI in PHP
  50. 50. The state of DI in PHP Symfony2 <?php namespace AcmeTalkBundleController; use SymfonyBundleFrameworkBundleControllerController; use SensioBundleFrameworkExtraBundleConfigurationRoute; use SensioBundleFrameworkExtraBundleConfigurationTemplate; class TalkController extends Controller { /** * @Route("/", name="_talk") * @Template() */ public function indexAction() { $service = $this->get(acme.talk.service); return array(); } }
  51. 51. The state of DI in PHP Symfony2 – Configuration file File services.xml in src/Acme/DemoBundle/Resources/config <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> </container>
  52. 52. The state of DI in PHP Symfony2 – Constructor Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService"> <argument type="service" id="acme.talk.repo" /> </service> </services> </container>
  53. 53. The state of DI in PHP Symfony2 – Setter Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.logger" class="AcmeTalkBundleServiceLogger" /> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService"> <argument type="service" id="acme.talk.repo" /> <call method="setLogger"> <argument type="service" id="acme.talk.logger" /> </call> </service> </services> </container>
  54. 54. The state of DI in PHP Symfony2 – Setter Injection (optional) <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.logger" class="AcmeTalkBundleServiceLogger" /> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService"> <argument type="service" id="acme.talk.repo" /> <call method="setLogger"> <argument type="service" id="acme.talk.logger" on-invalid="ignore" /> </call> </service> </services> </container>
  55. 55. The state of DI in PHP Symfony2 – Property Injection <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService"> <property name="talkRepository" type="service" id="acme.talk.repo" /> </service> </services> </container>
  56. 56. The state of DI in PHP Symfony2 – Interface Injection Not supported!
  57. 57. The state of DI in PHP Symfony2 – private/public Services <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.logger" class="AcmeTalkBundleServiceLogger" public="false" /> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService"> <argument type="service" id="acme.talk.repo" /> <call method="setLogger"> <argument type="service" id="acme.talk.logger" /> </call> </service> </services> </container>
  58. 58. The state of DI in PHP Symfony2 – Service inheritance <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.serviceparent" class="AcmeTalkBundleServiceTalkService" abstract="true"> <property name="talkRepository" type="service" id="acme.talk.repo" /> </service> <service id="acme.talk.service" parent="acme.talk.serviceparent" /> <service id="acme.talk.service2" parent="acme.talk.serviceparent" /> </services> </container>
  59. 59. The state of DI in PHP Symfony2 – Service scoping <?xml version="1.0" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <services> <service id="acme.talk.repo" class="AcmeTalkBundleServiceTalkRepository" /> <service id="acme.talk.service" class="AcmeTalkBundleServiceTalkService" scope="prototype"> <property name="talkRepository" type="service" id="acme.talk.repo" /> </service> </services> </container>
  60. 60. The state of DI in PHP
  61. 61. The state of DI in PHP Flow3 – Constructor Injection <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface */ protected $talkService; public function __construct( AcmeDemoServiceTalkService $talkService) { $this->talkService = $talkService; } public function indexAction() { } }
  62. 62. The state of DI in PHP Flow3 – Setter Injection (manually) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface */ protected $talkService; public function setTalkService( AcmeDemoServiceTalkService $talkService) { $this->talkService = $talkService; } public function indexAction() { } }
  63. 63. The state of DI in PHP Flow3 – Setter Injection (manually) File Objects.yaml in Packages/Application/Acme.Demo/Configuration # @package Acme AcmeDemoControllerStandardController: properties: talkService: object: AcmeDemoServiceTalkService
  64. 64. The state of DI in PHP Flow3 – Setter Injection (Automagic) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface */ protected $talkService; public function injectTalkService( AcmeDemoServiceTalkService $talkService) { $this->talkService = $talkService; } public function indexAction() { } }
  65. 65. The state of DI in PHP Flow3 – Setter Injection (Automagic) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface */ protected $talkService; public function injectSomethingElse( AcmeDemoServiceTalkService $talkService) { $this->talkService = $talkService; } public function indexAction() { } }
  66. 66. The state of DI in PHP Flow3 – Property Injection <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkService * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  67. 67. The state of DI in PHP Flow3 – Property Injection (with Interface) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  68. 68. The state of DI in PHP Flow3 – Property Injection (with Interface) File Objects.yaml in Packages/Application/Acme.Demo/Configuration # @package Acme AcmeDemoServiceTalkServiceInterface: className: AcmeDemoServiceTalkService
  69. 69. The state of DI in PHP Flow3 – Scoping <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  70. 70. Real World Dependency Injection Benefits
  71. 71. Real World Dependency Injection Benefits Loose coupling, reuse of components!
  72. 72. Real World Dependency Injection Benefits Can reduce the amount of code!
  73. 73. Real World Dependency Injection Benefits Helps developers to understand the code!
  74. 74. Real World Dependency Injection Cons – Developers need mindshift Configuration ↔ Runtime
  75. 75. The state of DI in PHP Cons - PSR for DI container missing!
  76. 76. The state of DI in PHP Lack of IDE support
  77. 77. Thank you!
  78. 78. http://joind.in/6250
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×