2
0

ContainerMock.php 610 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Test\Michel\Framework\Core\Mock;
  3. use Psr\Container\ContainerInterface;
  4. class ContainerMock implements ContainerInterface
  5. {
  6. private array $definitions;
  7. public function __construct(array $definitions = [])
  8. {
  9. $this->definitions = $definitions;
  10. }
  11. public function get(string $id)
  12. {
  13. $value = $this->definitions[$id] ?? null;
  14. if ($value instanceof \Closure) {
  15. return $value($this);
  16. }
  17. return $value;
  18. }
  19. public function has(string $id): bool
  20. {
  21. return array_key_exists($id, $this->definitions);
  22. }
  23. }