Your SlideShare is downloading. ×
  • Like
Real World Dependency Injection SE - phpugrhh
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Real World Dependency Injection SE - phpugrhh

  • 1,837 views
Published

 

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,837
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
6
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Real WorldDependency Injection Special Edition :)
  • 2. Real World Dependency Injection – Special Edition Über mich  Stephan Hochdörfer, bitExpert AG  Department Manager Research Labs  PHP`ler seit 1999  S.Hochdoerfer@bitExpert.de  @shochdoerfer
  • 3. Real World Dependency Injection – Special Edition Was sind Dependencies?
  • 4. Real World Dependency Injection – Special Edition Sind Dependencies schlecht?
  • 5. Real World Dependency Injection – Special Edition Sind Dependencies schlecht? Normalerweise nicht...
  • 6. Real World Dependency Injection – Special Edition Sind Dependencies schlecht? …so lange Dependencies nicht hartcodiert sind!
  • 7. Real World Dependency Injection – Special Edition Starke Kopplung
  • 8. Real World Dependency Injection – Special Edition Keine Wiederverwendung!
  • 9. Real World Dependency Injection – Special Edition Keine Isolation, nicht testbar!
  • 10. Real World Dependency Injection – Special Edition Dependency Wahnsinn!
  • 11. Real World Dependency Injection – Special Edition s „new“ is evil!
  • 12. Real World Dependency Injection – Special Edition „new“ is evil! <?php class DeletePage extends Mvc_Action_AAction { private $pageManager; public function __construct() { $this->pageManager = new PageManager(); } protected function execute(Mvc_Request $request) { $this->pageManager->delete( (int) $request->get(pageId) ); } }
  • 13. Real World Dependency Injection – Special Edition „new“ is evil! <?php class DeletePage extends Mvc_Action_AAction { private $pageManager; public function __construct(PageManager $pm) { $this->pageManager = $pm; } protected function execute(Mvc_Request $request) { $this->pageManager->delete( (int) $request->get(pageId) ); } }
  • 14. Real World Dependency Injection – Special Edition "High-level modules should not depend on low-level modules. Both should depend on abstractions." Robert C. Martin
  • 15. Real World Dependency Injection – Special Edition Interfaces als Vertrag
  • 16. Real World Dependency Injection – Special Edition „new“ is evil! <?php class DeletePage extends Mvc_Action_AAction { private $pageManager; public function __construct(IPageManager $pm) { $this->pageManager = $pm; } protected function execute(Mvc_Request $request) { $this->pageManager->delete( (int) $request->get(pageId) ); } }
  • 17. Real World Dependency Injection – Special Edition Wie verwaltet man Dependencies?
  • 18. Real World Dependency Injection – Special Edition Händisch? Mit der heißen Nadel gestrickt...
  • 19. Real World Dependency Injection – Special Edition Automatismus notwendig! Einfacher Container vs. Fullstack DI Framework
  • 20. Real World Dependency Injection – Special Edition Was ist Dependency Injection? Consumer
  • 21. Real World Dependency Injection – Special Edition Was ist Dependency Injection? Consumer Dependencies
  • 22. Real World Dependency Injection – Special Edition Was ist Dependency Injection? Consumer Dependencies Container
  • 23. Real World Dependency Injection – Special Edition Was ist Dependency Injection? Consumer Dependencies Container
  • 24. Real World Dependency Injection – Special Edition Wie Dependencies injizieren?
  • 25. Real World Dependency Injection – Special Edition Constructor Injection <?php class MySampleService implements IMySampleService { /** * @var ISampleDao */ private $sampleDao; public function __construct(ISampleDao $sampleDao) { $this->sampleDao = $sampleDao; } }
  • 26. Real World Dependency Injection – Special Edition Setter Injection <?php class MySampleService implements IMySampleService { /** * @var ISampleDao */ private $sampleDao; public function setSampleDao(ISampleDao $sampleDao){ $this->sampleDao = $sampleDao; } }
  • 27. Real World Dependency Injection – Special Edition Interface Injection <?php interface IApplicationContextAware { public function setCtx(IApplicationContext $ctx); }
  • 28. Real World Dependency Injection – Special Edition Interface Injection <?php class MySampleService implements IMySampleService, IApplicationContextAware { /** * @var IApplicationContext */ private $ctx; public function setCtx(IApplicationContext $ctx) { $this->ctx = $ctx; } }
  • 29. Real World Dependency Injection – Special Edition Wie verbinden wir nun alles?
  • 30. Real World Dependency Injection – Special Edition Annotations <?php class MySampleService implements IMySampleService { private $sampleDao; /** * @Inject */ public function __construct(ISampleDao $sampleDao) { $this->sampleDao = $sampleDao; } }
  • 31. Real World Dependency Injection – Special Edition Annotations <?php class MySampleService implements IMySampleService { private $sampleDao; /** * @Inject * @Named(TheSampleDao) */ public function __construct(ISampleDao $sampleDao) { $this->sampleDao = $sampleDao; } }
  • 32. Real World Dependency Injection – Special Edition Externe Konfiguration - XML <?xml version="1.0" encoding="UTF-8" ?> <beans> <bean id="SampleDao" class="SampleDao"> <constructor-arg value="app_sample" /> <constructor-arg value="iSampleId" /> <constructor-arg value="BoSample" /> </bean> <bean id="SampleService" class="MySampleService"> <constructor-arg ref="SampleDao" /> </bean> </beans>
  • 33. Real World Dependency Injection – Special Edition Externe Konfiguration - YAML services: SampleDao: class: SampleDao arguments: [app_sample, iSampleId, BoSample] SampleService: class: SampleService arguments: [@SampleDao]
  • 34. Real World Dependency Injection – Special Edition Externe Konfiguration - PHP <?php class BeanCache extends Beanfactory_Container_PHP { protected function createSampleDao() { $oBean = new SampleDao(app_sample, iSampleId, BoSample); return $oBean; } protected function createMySampleService() { $oBean = new MySampleService( $this->getBean(SampleDao) ); return $oBean; } }
  • 35. Real World Dependency Injection – Special Edition Beispiele gefällig?
  • 36. Real World Dependency Injection – Special Edition Unittesting einfach gemacht
  • 37. Real World Dependency Injection – Special Edition Unittesting einfach gemacht <?php require_once PHPUnit/Framework.php; class ServiceTest extends PHPUnit_Framework_TestCase { public function testSampleService() { // set up dependencies $sampleDao = $this->getMock(ISampleDao); $service = new MySampleService($sampleDao); // run test case $return = $service->doWork(); // check assertions $this->assertTrue($return); } }
  • 38. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung
  • 39. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung Page Exporter Page Exporter
  • 40. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung Page Exporter Page Exporter Released / /Published Released Published Workingcopy Workingcopy Pages Pages Pages Pages
  • 41. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?php abstract class PageExporter { protected function setPageDao(IPageDao $pageDao) { $this->pageDao = $pageDao; } }
  • 42. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?php abstract class PageExporter { protected function setPageDao(IPageDao $pageDao) { $this->pageDao = $pageDao; } } Zur Erinnerung: Der Vertrag!
  • 43. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?php class PublishedPageExporter extends PageExporter { public function __construct() { $this->setPageDao(new PublishedPageDao()); } } class WorkingCopyPageExporter extends PageExporter { public function __construct() { $this->setPageDao(new WorkingCopyPageDao()); } }
  • 44. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung "Only deleted code is good code!" Oliver Gierke
  • 45. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?php class PageExporter { public function __construct(IPageDao $pageDao) { $this->pageDao = $pageDao; } }
  • 46. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?xml version="1.0" encoding="UTF-8" ?> <beans> <bean id="ExportLive" class="PageExporter"> <constructor-arg ref="PublishedPageDao" /> </bean> <bean id="ExportWorking" class="PageExporter"> <constructor-arg ref="WorkingCopyPageDao" /> </bean> </beans>
  • 47. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung <?php // create ApplicationContext instance $ctx = new ApplicationContext(); // retrieve live exporter $exporter = $ctx->getBean(ExportLive); // retrieve working copy exporter $exporter = $ctx->getBean(ExportWorking);
  • 48. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung II
  • 49. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung II http://editor.loc/page/[id]/headline/ http://editor.loc/page/[id]/content/ http://editor.loc/page/[id]/teaser/
  • 50. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung II <?php class EditPart extends Mvc_Action_AFormAction { private $pagePartsManager; private $type; public function __construct(IPagePartsManager $pm) { $this->pagePartsManager = $pm; } public function setType($ptype) { $this->type = (int) $type; } protected function process(Bo_ABo $formBackObj) { } }
  • 51. Real World Dependency Injection – Special Edition Eine Klasse, mehrfache Ausprägung II <?xml version="1.0" encoding="UTF-8" ?> <beans> <bean id="EditHeadline" class="EditPart"> <constructor-arg ref="PagePartDao" /> <property name="Type" const="PType::Headline" /> </bean> <bean id="EditContent" class="EditPart"> <constructor-arg ref="PagePartDao" /> <property name="Type" const="PType::Content" /> </bean> </beans>
  • 52. Real World Dependency Injection – Special Edition Externe Services mocken
  • 53. Real World Dependency Injection – Special Edition Externe Services mocken WS- WS- Bookingmanager Bookingmanager Webservice Webservice Connector Connector
  • 54. Real World Dependency Injection – Special Edition Externe Services mocken WS- WS- Bookingmanager Bookingmanager Webservice Webservice Connector Connector Zur Erinnerung: Der Vertrag!
  • 55. Real World Dependency Injection – Special Edition Externe Services mocken FS- FS- Bookingmanager Bookingmanager Filesystem Filesystem Connector Connector
  • 56. Real World Dependency Injection – Special Edition Externe Services mocken FS- FS- Bookingmanager Bookingmanager Filesystem Filesystem Connector Connector erfüllt den Vertrag!
  • 57. Real World Dependency Injection – Special Edition Sauberer, lesbarer Code
  • 58. Real World Dependency Injection – Special Edition Sauberer, lesbarer Code <?php class DeletePage extends Mvc_Action_AAction { private $pageManager; public function __construct(IPageManager $pm) { $this->pageManager = $pm; } protected function execute(Mvc_Request $request) { $this->pageManager->delete( (int) $request->get(pageId)); return new ModelAndView($this->getSuccessView()); } }
  • 59. Real World Dependency Injection – Special Edition Keine Framework Abhängigkeit
  • 60. Real World Dependency Injection – Special Edition Keine Framework Abhängigkeit <?php class MySampleService implements IMySampleService { private $sampleDao; public function __construct(ISampleDao $sampleDao) { $this->sampleDao = $sampleDao; } public function getSample($sampleId) { try { return $this->sampleDao->readById($sampleId); } catch(DaoException $exception) {} } }
  • 61. Real World Dependency Injection – Special Edition Wie sieht das nun in der Praxis aus?
  • 62. Real World Dependency Injection – Special Edition
  • 63. Real World Dependency Injection – Special Edition ZendDi – Erste Schritte <?php namespace Acme; class TalkService { public function __construct() { } public function getTalks() { } }
  • 64. Real World Dependency Injection – Special Edition ZendDi – Erste Schritte <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  • 65. Real World Dependency Injection – Special Edition 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() { } }
  • 66. Real World Dependency Injection – Special Edition ZendDi – Constructor Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  • 67. Real World Dependency Injection – Special Edition 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() { } }
  • 68. Real World Dependency Injection – Special Edition 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);
  • 69. Real World Dependency Injection – Special Edition 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() { } }
  • 70. Real World Dependency Injection – Special Edition ZendDi – Interface Injection <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); $service->getTalks();
  • 71. Real World Dependency Injection – Special Edition ZendDi – Grundsätzliches <?php $di = new ZendDiDi(); $service = $di->get(AcmeTalkService); var_dump($service); $service2 = $di->get(AcmeTalkService); var_dump($service2); // gleiche Instanz wie $service $service3 = $di->get( AcmeTalkService, array( repo => new phpbnl12TalkRepository() ) ); var_dump($service3); // neue Instanz
  • 72. Real World Dependency Injection – Special Edition ZendDi – Builder Definition <?php // Dependency beschreiben $dep = new ZendDiDefinitionBuilderPhpClass(); $dep->setName(AcmeTalkRepository); // Klasse beschreiben $class = new ZendDiDefinitionBuilderPhpClass(); $class->setName(AcmeTalkService); // Injection Methode beschreiben $im = new ZendDiDefinitionBuilderInjectionMethod(); $im->setName(__construct); $im->addParameter(repo, AcmeTalkRepository); $class->addInjectionMethod($im); // Builder konfigurieren $builder = new ZendDiDefinitionBuilderDefinition(); $builder->addClass($dep); $builder->addClass($class);
  • 73. Real World Dependency Injection – Special Edition ZendDi – Builder Definition <?php // zur DefinitionList hinzufügen $defList = new ZendDiDefinitionList($builder); $di = new ZendDiDi($defList); $service = $di->get(AcmeTalkService); var_dump($service);
  • 74. Real World Dependency Injection – Special Edition
  • 75. Real World Dependency Injection – Special Edition 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(); } }
  • 76. Real World Dependency Injection – Special Edition Symfony2 – Konfigurationsdatei Datei 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>
  • 77. Real World Dependency Injection – Special Edition 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>
  • 78. Real World Dependency Injection – Special Edition 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>
  • 79. Real World Dependency Injection – Special Edition 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>
  • 80. Real World Dependency Injection – Special Edition 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>
  • 81. Real World Dependency Injection – Special Edition Symfony2 – private / öffentliche 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>
  • 82. Real World Dependency Injection – Special Edition Symfony2 – Vererbung <?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>
  • 83. Real World Dependency Injection – Special Edition Symfony2 – 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>
  • 84. Real World Dependency Injection – Special Edition
  • 85. Real World Dependency Injection – Special Edition 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() { } }
  • 86. Real World Dependency Injection – Special Edition Flow3 – Setter Injection (manuell) <?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() { } }
  • 87. Real World Dependency Injection – Special Edition Flow3 – Setter Injection (manuell) Datei Objects.yaml in Packages/Application/Acme.Demo/Configuration # @package Acme AcmeDemoControllerStandardController: properties: talkService: object: AcmeDemoServiceTalkService
  • 88. Real World Dependency Injection – Special Edition Flow3 – Setter Injection (automatisch) <?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() { } }
  • 89. Real World Dependency Injection – Special Edition Flow3 – Setter Injection (automatisch) <?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() { } }
  • 90. Real World Dependency Injection – Special Edition Flow3 – Property Injection <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkService * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  • 91. Real World Dependency Injection – Special Edition Flow3 – Property Injection (mittels Interface) <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  • 92. Real World Dependency Injection – Special Edition Flow3 – Property Injection (mittels Interface) Datei Objects.yaml in Packages/Application/Acme.Demo/Configuration # @package Acme AcmeDemoServiceTalkServiceInterface: className: AcmeDemoServiceTalkService
  • 93. Real World Dependency Injection – Special Edition Flow3 – Scoping <?php namespace AcmeDemoController; use TYPO3FLOW3Annotations as FLOW3; /** * @FLOW3Scope("session") */ class StandardController extends TYPO3FLOW3MVCControllerActionController { /** * @var AcmeDemoServiceTalkServiceInterface * @FLOW3Inject */ protected $talkService; public function indexAction() { } }
  • 94. Real World Dependency Injection – Special Edition Vorteile
  • 95. Real World Dependency Injection – Special Edition Vorteile Lose Kopplung, gesteigerte Wiederverwendbarkeit !
  • 96. Real World Dependency Injection – Special Edition Vorteile Codeumfang reduzieren, Fokus auf das Wesentliche!
  • 97. Real World Dependency Injection – Special Edition Vorteile Hilft Entwicklern den Code besser zu verstehen!
  • 98. Real World Dependency Injection – Special Edition Nachteil – Kein JSR330 für PHP Bucket, Crafty, FLOW3, Imind_Context, PicoContainer, Pimple, Phemto, Stubbles, Symfony 2.0, Sphicy, Solar, Substrate, XJConf, Yadif, ZendDi , Lion Framework, Spiral Framework, Xyster Framework, …
  • 99. Real World Dependency Injection – Special Edition Nachteil – Entwickler müssen umdenken Konfiguration ↔ Laufzeit
  • 100. Real World Dependency Injection – Special Edition Nachteil – Keine IDE Unterstützung!
  • 101. Vielen Dank!
  • 102. Image Creditshttp://www.sxc.hu/photo/1028452