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.
super-gear-directus/app/Repositories/Manager.php

52 lines
1.1 KiB

5 years ago
<?php
namespace App\Repositories;
5 years ago
use Exception;
/**
* Manager Class to create Repository Objects that
* are located in App\Repositories\
5 years ago
*
*
* @author Björn Hase, Tentakelfabrik
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
*
5 years ago
*/
5 years ago
class Manager
{
/**
* naming of Repository
* @var string
*/
const NAMESPACE = 'App\Repositories\\';
/**
* naming of Repository
* @var string
*/
const REPOSITORY_SUFFIX = 'Repository';
/**
* getting repository object
*
* @param string $repositoryClass
* @return AbstractRepository
*/
public static function get($repositoryName)
{
$repositoryClass = self::NAMESPACE.$repositoryName.self::REPOSITORY_SUFFIX;
if (!class_exists($repositoryClass)) {
throw new Exception('Repository Class '.$repositoryClass.' not exists!');
}
// create respository object
$repository = new $repositoryClass();
return $repository;
}
}