StubFactory.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. namespace TestApp\Datasource;
  4. use Cake\Datasource\Locator\LocatorInterface;
  5. use Cake\Datasource\RepositoryInterface;
  6. class StubFactory implements LocatorInterface
  7. {
  8. private $instances = [];
  9. /**
  10. * @inheritDoc
  11. */
  12. public function get(string $alias, array $options = [])
  13. {
  14. if (!isset($this->instances[$alias])) {
  15. return false;
  16. }
  17. return $this->instances[$alias];
  18. }
  19. /**
  20. * @inheritDoc
  21. */
  22. public function set(string $alias, RepositoryInterface $repository)
  23. {
  24. $this->instances[$alias] = $repository;
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. public function exists(string $alias): bool
  30. {
  31. return isset($this->instances[$alias]);
  32. }
  33. /**
  34. * @inheritDoc
  35. */
  36. public function remove(string $alias): void
  37. {
  38. unset($this->instances[$alias]);
  39. }
  40. /**
  41. * @inheritDoc
  42. */
  43. public function clear(): void
  44. {
  45. $this->instances = [];
  46. }
  47. }