ServiceItem.class.php 903 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Holds the PMA\DI\ServiceItem class
  5. *
  6. * @package PMA
  7. */
  8. namespace PMA\DI;
  9. require_once 'libraries/di/ReflectorItem.class.php';
  10. /**
  11. * Service manager
  12. *
  13. * @package PMA\DI
  14. */
  15. class ServiceItem extends ReflectorItem
  16. {
  17. /** @var mixed */
  18. protected $instance;
  19. /**
  20. * Constructor
  21. *
  22. * @param Container $container Container
  23. * @param mixed $definition Definition
  24. */
  25. public function __construct(Container $container, $definition)
  26. {
  27. parent::__construct($container, $definition);
  28. }
  29. /**
  30. * Get the instance of the service
  31. *
  32. * @param array $params Parameters
  33. * @return mixed
  34. */
  35. public function get($params = array())
  36. {
  37. if (!isset($this->instance)) {
  38. $this->instance = $this->invoke();
  39. }
  40. return $this->instance;
  41. }
  42. }