Created
December 19, 2018 13:11
-
-
Save BerezhniyDmitro/8e2cf18f40579cf841cf3a784db14618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class DocumentRepositoryMap { | |
private static $map = [ | |
'Nakladnaya' => DocumentServiceProviderNakladnaya::class, | |
]; | |
public static function getRepositoryProvider(string $providerKey) :string | |
{ | |
if (! in_array($providerKey, self::$map)) { | |
throw new InvalidArgumentException('Not serviceProvider by key' . $providerKey); | |
} | |
return self::$map[$providerKey]; | |
} | |
} | |
// для каждой репы делаешь свой сервис провайдер и в сервис провайдере в регистре делаешь такой финт | |
// DocumentServiceProviderNakladnaya => retrun new DocumentNakladnayaRepository($modelDB); ну и соответственно создаешь такую репу и инжектишь в кострукктор модель | |
// в клиентском коде | |
$aliasForRepo = DocumentRepositoryMap::getRepositoryProvider('Nakladnaya'); | |
$repository = Container::getInstance()->make($aliasForRepo); | |
$documents = $repository->findAllDocumentByPeriod($dateperiod, $contragent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment