Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Repositories;
  3. use Exception;
  4. /**
  5. * Manager Class to create Repository Objects that
  6. * are located in App\Repositories\
  7. *
  8. *
  9. * @author Björn Hase, Tentakelfabrik
  10. * @license http://opensource.org/licenses/MIT The MIT License
  11. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
  12. *
  13. */
  14. class Manager
  15. {
  16. /**
  17. * naming of Repository
  18. * @var string
  19. */
  20. const NAMESPACE = 'App\Repositories\\';
  21. /**
  22. * naming of Repository
  23. * @var string
  24. */
  25. const REPOSITORY_SUFFIX = 'Repository';
  26. /**
  27. * getting repository object
  28. *
  29. * @param string $repositoryClass
  30. * @return AbstractRepository
  31. */
  32. public static function get($repositoryName)
  33. {
  34. $repositoryClass = self::NAMESPACE.$repositoryName.self::REPOSITORY_SUFFIX;
  35. if (!class_exists($repositoryClass)) {
  36. throw new Exception('Repository Class '.$repositoryClass.' not exists!');
  37. }
  38. // create respository object
  39. $repository = new $repositoryClass();
  40. return $repository;
  41. }
  42. }