FactoryDefinition.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Di\Definition;
  12. class FactoryDefinition implements DefinitionInterface
  13. {
  14. private bool $needProxy = false;
  15. /**
  16. * @param callable|string $factory
  17. */
  18. public function __construct(private string $name, private mixed $factory, private array $parameters = [])
  19. {
  20. }
  21. public function __toString(): string
  22. {
  23. return 'Factory';
  24. }
  25. public function getName(): string
  26. {
  27. return $this->name;
  28. }
  29. public function setName(string $name): self
  30. {
  31. $this->name = $name;
  32. return $this;
  33. }
  34. public function getFactory(): callable|string
  35. {
  36. return $this->factory;
  37. }
  38. public function getParameters(): array
  39. {
  40. return $this->parameters;
  41. }
  42. /**
  43. * Determine if the definition need to transfer to a proxy class.
  44. */
  45. public function isNeedProxy(): bool
  46. {
  47. return $this->needProxy;
  48. }
  49. public function setNeedProxy($needProxy): self
  50. {
  51. $this->needProxy = $needProxy;
  52. return $this;
  53. }
  54. }