Payment
1 year ago
Support
11 months ago
Application.php
1 year ago
Container.php
1 year ago
Factory.php
1 year ago
Container.php
42 lines
| 1 | <?php |
| 2 | namespace Ollyo\PaymentHub\Core; |
| 3 | |
| 4 | use Ollyo\PaymentHub\Contracts\Core\ContainerContract; |
| 5 | |
| 6 | final class Container implements ContainerContract |
| 7 | { |
| 8 | protected $services = []; |
| 9 | |
| 10 | public function __construct() |
| 11 | { |
| 12 | } |
| 13 | |
| 14 | public function has($id): bool |
| 15 | { |
| 16 | return isset($this->services[$id]); |
| 17 | } |
| 18 | |
| 19 | public function get($id) |
| 20 | { |
| 21 | if (!$this->has($id)) { |
| 22 | return null; |
| 23 | } |
| 24 | |
| 25 | return $this->services[$id]; |
| 26 | } |
| 27 | |
| 28 | public function set($id, $service): void |
| 29 | { |
| 30 | if (is_callable($service)) { |
| 31 | $serviceValue = $service(); |
| 32 | } elseif (is_object($service)) { |
| 33 | $serviceValue = $service; |
| 34 | } elseif (is_string($service)) { |
| 35 | $serviceValue = class_exists($service) ? new $service(): $service; |
| 36 | } else { |
| 37 | $serviceValue = $service; |
| 38 | } |
| 39 | |
| 40 | $this->services[$id] = $serviceValue; |
| 41 | } |
| 42 | } |