|
- <?php
-
- namespace common\components;
-
- use common\containers\UserProducerContainer;
- use common\logic\CreditHistory\CreditHistoryContainer;
- use common\logic\Producer\ProducerContainer;
- use common\logic\ProducerPriceRange\ProducerPriceRangeContainer;
- use common\logic\User\UserContainer;
- use yii\base\ErrorException;
-
- class BusinessLogic
- {
- public function getContainers()
- {
- return [
- $this->getUserContainer(),
- $this->getProducerContainer(),
- $this->getCreditHistoryContainer(),
- $this->getProducerPriceRangeContainer(),
- $this->getUserProducerContainer(),
- ];
- }
-
- public function getUserContainer(): UserContainer
- {
- return new UserContainer();
- }
-
- public function getProducerContainer(): ProducerContainer
- {
- return new ProducerContainer();
- }
-
- public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer
- {
- return new ProducerPriceRangeContainer();
- }
-
- public function getUserProducerContainer(): UserProducerContainer
- {
- return new UserProducerContainer();
- }
-
- public function getCreditHistoryContainer(): CreditHistoryContainer
- {
- return new CreditHistoryContainer();
- }
-
- /*
- * Hiérarchie des apps
- */
-
- public function getContainerLevelHierarchyByService($serviceClass): int
- {
- $containersArray = $this->getContainers();
- $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
-
- foreach($containersArray as $key => $container) {
- if($container->getEntityFqcn() == $entityFqcnService) {
- return $key;
- }
- }
- }
-
- public function getEntityFqcnByService(string $serviceClass): string
- {
- $containersArray = $this->getContainers();
-
- foreach($containersArray as $container) {
- if(in_array($serviceClass, $container->getServices())) {
- return $container->getEntityFqcn();
- }
- }
-
- throw new ErrorException('Service '.$serviceClass.' introuvable dans le container.');
- }
- }
|