TestInjectSelf.php 932 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: LinFei
  5. * Created time 2022/12/15 15:11:21
  6. * E-mail: fly@eyabc.cn
  7. */
  8. declare (strict_types=1);
  9. namespace LinFly\Example;
  10. class TestInjectSelf
  11. {
  12. /**
  13. * @param TestInjectSelf $testInjectSelf The injected circular dependency can only be a single instance
  14. * @param int $id
  15. */
  16. public function __construct(private TestInjectSelf $testInjectSelf, private int $id = 1)
  17. {
  18. // var_dump($this->testInjectSelf->getId() === $id);
  19. }
  20. /**
  21. * @return int
  22. */
  23. public function getId(): int
  24. {
  25. return $this->id;
  26. }
  27. /**
  28. * @return TestInjectSelf
  29. */
  30. public function getTestInjectSelf(): TestInjectSelf
  31. {
  32. return $this->testInjectSelf;
  33. }
  34. /*public static function main(): void
  35. {
  36. FacadeContainer::getSingle(static::class);
  37. FacadeContainer::newInstance(static::class, [2]);
  38. }*/
  39. }