Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

78 lines
2.1KB

  1. <?php
  2. namespace common\components;
  3. use common\logic\Producer\Producer\ProducerContainer;
  4. use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer;
  5. use common\logic\User\CreditHistory\CreditHistoryContainer;
  6. use common\logic\User\User\UserContainer;
  7. use common\logic\User\UserProducer\UserProducerContainer;
  8. use yii\base\ErrorException;
  9. class BusinessLogic
  10. {
  11. public function getContainers()
  12. {
  13. return [
  14. $this->getCreditHistoryContainer(),
  15. $this->getProducerPriceRangeContainer(),
  16. $this->getUserProducerContainer(),
  17. $this->getUserContainer(),
  18. $this->getProducerContainer(),
  19. ];
  20. }
  21. public function getUserContainer(): UserContainer
  22. {
  23. return new UserContainer();
  24. }
  25. public function getProducerContainer(): ProducerContainer
  26. {
  27. return new ProducerContainer();
  28. }
  29. public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer
  30. {
  31. return new ProducerPriceRangeContainer();
  32. }
  33. public function getUserProducerContainer(): UserProducerContainer
  34. {
  35. return new UserProducerContainer();
  36. }
  37. public function getCreditHistoryContainer(): CreditHistoryContainer
  38. {
  39. return new CreditHistoryContainer();
  40. }
  41. /*
  42. * Hiérarchie des apps
  43. */
  44. public function getContainerLevelHierarchyByService($serviceClass): int
  45. {
  46. $containersArray = $this->getContainers();
  47. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  48. foreach($containersArray as $key => $container) {
  49. if($container->getEntityFqcn() == $entityFqcnService) {
  50. return $key;
  51. }
  52. }
  53. }
  54. public function getEntityFqcnByService(string $serviceClass): string
  55. {
  56. $containersArray = $this->getContainers();
  57. foreach($containersArray as $container) {
  58. if(in_array($serviceClass, $container->getServices())) {
  59. return $container->getEntityFqcn();
  60. }
  61. }
  62. throw new ErrorException('Service '.$serviceClass.' introuvable dans le container.');
  63. }
  64. }