Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

91 linhas
3.5KB

  1. <?php
  2. namespace common\components;
  3. use common\logic\Config\TaxRate\TaxRateContainer;
  4. use common\logic\Distribution\Distribution\DistributionContainer;
  5. use common\logic\Distribution\PointSaleDistribution\PointSaleDistributionContainer;
  6. use common\logic\Distribution\ProductDistribution\ProductDistributionContainer;
  7. use common\logic\Document\Document\DocumentContainer;
  8. use common\logic\Order\Order\OrderContainer;
  9. use common\logic\Order\Order\OrderManager;
  10. use common\logic\Order\OrderStatusHistory\OrderStatusHistoryContainer;
  11. use common\logic\Order\ProductOrder\ProductOrderContainer;
  12. use common\logic\PointSale\PointSale\PointSaleContainer;
  13. use common\logic\Producer\Producer\ProducerContainer;
  14. use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer;
  15. use common\logic\Product\Product\ProductContainer;
  16. use common\logic\Product\ProductCategory\ProductCategoryContainer;
  17. use common\logic\Product\ProductPointSale\ProductPointSaleContainer;
  18. use common\logic\Product\ProductPrice\ProductPriceContainer;
  19. use common\logic\Subscription\ProductSubscription\ProductSubscriptionContainer;
  20. use common\logic\Subscription\Subscription\SubscriptionContainer;
  21. use common\logic\User\CreditHistory\CreditHistoryContainer;
  22. use common\logic\User\User\UserContainer;
  23. use common\logic\User\UserGroup\UserGroupContainer;
  24. use common\logic\User\UserProducer\UserProducerContainer;
  25. use common\logic\User\UserUserGroup\UserUserGroupContainer;
  26. use yii\base\ErrorException;
  27. class BusinessLogic
  28. {
  29. use BusinessLogicContainerTrait;
  30. public function getContainers()
  31. {
  32. return [
  33. $this->getTaxRateContainer(),
  34. $this->getUserUserGroupContainer(),
  35. $this->getUserGroupContainer(),
  36. $this->getDocumentContainer(),
  37. $this->getCreditHistoryContainer(),
  38. $this->getProducerPriceRangeContainer(),
  39. $this->getUserProducerContainer(),
  40. $this->getOrderSatusHistoryContainer(),
  41. $this->getPointSaleDistributionContainer(),
  42. $this->getProductDistributionContainer(),
  43. $this->getProductCategoryContainer(),
  44. $this->getProductPointSaleContainer(),
  45. $this->getProductOrderContainer(),
  46. $this->getProductPriceContainer(),
  47. $this->getProductSubscriptionContainer(),
  48. $this->getUserPointSaleContainer(),
  49. $this->getPointSaleContainer(),
  50. $this->getUserContainer(),
  51. $this->getSubscriptionContainer(),
  52. $this->getProductContainer(),
  53. $this->getDistributionContainer(),
  54. $this->getProducerContainer(),
  55. $this->getOrderContainer(),
  56. ];
  57. }
  58. /*
  59. * Hiérarchie des apps
  60. */
  61. public function getContainerLevelHierarchyByService($serviceClass): int
  62. {
  63. $containersArray = $this->getContainers();
  64. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  65. foreach($containersArray as $key => $container) {
  66. if($container->getEntityFqcn() == $entityFqcnService) {
  67. return $key;
  68. }
  69. }
  70. }
  71. public function getEntityFqcnByService(string $serviceClass): string
  72. {
  73. $containersArray = $this->getContainers();
  74. foreach($containersArray as $container) {
  75. if(in_array($serviceClass, $container->getServices())) {
  76. return $container->getEntityFqcn();
  77. }
  78. }
  79. throw new ErrorException('Service '.$serviceClass.' introuvable dans le container.');
  80. }
  81. }