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/

YAMAOKA Hiroyuki

March 26, 2021
Tweet

More Decks by YAMAOKA Hiroyuki

Other Decks in Programming

Transcript

  1. - 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
  2. DI

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

    function __construct(private Service $service) {} 
 }
  4. 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
  5. DI - execute($request) 
 
 : - show(Request $request) 


    
 : routing - show(ServerRequestInterface $request) 
 
 interface :
  6. Symfony - Service Container 
 
 https://symfony.com/doc/ 5 . 2

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

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

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

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

    beta - Attributes - PHP 8 PHP-DI 6
  10. 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) ⬇
  11. #[Inject] - PHP 8 Attributes namespace DI\Attribute; use Attribute; #[Attribute(Attribute::TARGET_PROPERTY

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