Brak opisu

ContainerAwareTrait.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php declare(strict_types=1);
  2. namespace Automattic\WooCommerce\Vendor\League\Container;
  3. use Automattic\WooCommerce\Vendor\League\Container\Exception\ContainerException;
  4. use Psr\Container\ContainerInterface;
  5. trait ContainerAwareTrait
  6. {
  7. /**
  8. * @var ContainerInterface
  9. */
  10. protected $container;
  11. /**
  12. * @var Container
  13. */
  14. protected $leagueContainer;
  15. /**
  16. * Set a container.
  17. *
  18. * @param ContainerInterface $container
  19. *
  20. * @return self
  21. */
  22. public function setContainer(ContainerInterface $container) : ContainerAwareInterface
  23. {
  24. $this->container = $container;
  25. return $this;
  26. }
  27. /**
  28. * Get the container.
  29. *
  30. * @return ContainerInterface
  31. */
  32. public function getContainer() : ContainerInterface
  33. {
  34. if ($this->container instanceof ContainerInterface) {
  35. return $this->container;
  36. }
  37. throw new ContainerException('No container implementation has been set.');
  38. }
  39. /**
  40. * Set a container.
  41. *
  42. * @param Container $container
  43. *
  44. * @return self
  45. */
  46. public function setLeagueContainer(Container $container) : ContainerAwareInterface
  47. {
  48. $this->container = $container;
  49. $this->leagueContainer = $container;
  50. return $this;
  51. }
  52. /**
  53. * Get the container.
  54. *
  55. * @return Container
  56. */
  57. public function getLeagueContainer() : Container
  58. {
  59. if ($this->leagueContainer instanceof Container) {
  60. return $this->leagueContainer;
  61. }
  62. throw new ContainerException('No container implementation has been set.');
  63. }
  64. }