Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHPのDI、attributesとこれから / PHP DI with attributes

PHPのDI、attributesとこれから / PHP DI with attributes

2021年3月28日、PHPerKaigi 2021・Day 2での発表資料です。
https://phperkaigi.jp/2021/

325afd2c9db540c83485f509f2845acb?s=128

Hiroyuki Yamaoka

March 26, 2021
Tweet

Transcript

  1. PHP DI attributes 2021 3 28 / PHPerKaigi 2 0

    2 1 Day 2
  2. - / @hiro_y - PHP Node.js Web - - CTO

  3. - - - - iruca mimemo 👨💻👨💻

  4. - PHPerKaigi 2 0 20 Day 0 - 2020 2

    9 - PHP 
 
 
 https://speakerdeck.com/hiro_y/about-php-annotations 
 
 https://www.youtube.com/watch?v=TdHDqOeCUW 4
  5. 🎉 PHP 8 . 0 🎉 2020 11

  6. https://www.php.net/releases/ 8 . 0 /ja.php

  7. DI

  8. DI - Dependency: - Injection: class Client { 
 public

    function __construct(private Service $service) {} 
 }
  9. PHP DI

  10. DI - Maple https://ja.osdn.net/projects/maple/ - S 2 Container.PHP 5
 


    http://s 2 container.php 5 .seasar.org/ 2 . 0 /ja/index.html - PHP 5
  11. - Java DI - Struts 1 Spring Seasar 2 -

    PHP 5 - DI
  12. PHP DI - PHP DI - - Web : -

    TDD CI :
  13. PHP 8

  14. PHP - - interface - autoload require - TDD CI

  15. DI - execute($request) 
 
 : - show(Request $request) 


    
 : routing - show(ServerRequestInterface $request) 
 
 interface :
  16. - IDE PhpStorm VSCode - interface - APC OPcache -

  17. - Symfony Laravel CakePHP - DI - 🕵

  18. - URL - - -

  19. Symfony - Service Container 
 
 https://symfony.com/doc/ 5 . 2

    /components/dependency_injection.html - Dependencyinjection component - PSR- 1 1 - 2
  20. Laravel - Service Container 
 
 https://laravel.com/docs/ 8 .x/container -

    Illuminate\Container\Container - PSR- 1 1 - Facades
  21. : PSR- 1 1 - PSR- 1 1 : Container

    Interface 
 
 https://www.php- fi g.org/psr/psr- 1 1 / - - : 
 

  22. PHP-DI - DI https://php-di.org/ - PSR- 1 1 - Slim

    middleware 
 

  23. PHP-DI 7 - 2021 3 10 : beta 3 -

    beta - Attributes - PHP 8 PHP-DI 6
  24. PHP-DI 7 - @Inject disabled #[Inject] - - - PhpDocReader

  25. Attributes /** * @Inject({"db.host", "db.name"}) */ public function __construct($param1, $param2)

    use DI\Attribute\Inject; #[Inject('db.host', 'db.name')] public function __construct($param1, $param2) ⬇
  26. @Inject - doctrine/annotations - Re fl ection DocComment - DocLexer

    -
  27. #[Inject] - PHP 8 Attributes namespace DI\Attribute; use Attribute; #[Attribute(Attribute::TARGET_PROPERTY

    | Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)] final class Inject {...
  28. DI

  29. Inject - - Inject - Autowire -

  30. Autowire - Inject - - Zero Con fi guration -

    PHP-DI DI
  31. Autowire - - class_exists / interface_exists - - interface

  32. autowire DI

  33. None
  34. DI - - - Service -

  35. - - - -

  36. None
  37. DI - - PSR - attributes 
 


  38. None