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.

BusinessLogic.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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\OrderStatusHistory\OrderStatusHistoryContainer;
  10. use common\logic\Order\ProductOrder\ProductOrderContainer;
  11. use common\logic\PointSale\PointSale\PointSaleContainer;
  12. use common\logic\Producer\Producer\ProducerContainer;
  13. use common\logic\Producer\ProducerPriceRange\ProducerPriceRangeContainer;
  14. use common\logic\Product\Product\ProductContainer;
  15. use common\logic\Product\ProductCategory\ProductCategoryContainer;
  16. use common\logic\Product\ProductPointSale\ProductPointSaleContainer;
  17. use common\logic\Product\ProductPrice\ProductPriceContainer;
  18. use common\logic\Subscription\ProductSubscription\ProductSubscriptionContainer;
  19. use common\logic\Subscription\Subscription\SubscriptionContainer;
  20. use common\logic\User\CreditHistory\CreditHistoryContainer;
  21. use common\logic\User\User\UserContainer;
  22. use common\logic\User\UserGroup\UserGroupContainer;
  23. use common\logic\User\UserProducer\UserProducerContainer;
  24. use common\logic\User\UserUserGroup\UserUserGroupContainer;
  25. use yii\base\ErrorException;
  26. class BusinessLogic
  27. {
  28. public function getContainers()
  29. {
  30. return [
  31. $this->getTaxRateContainer(),
  32. $this->getUserUserGroupContainer(),
  33. $this->getUserGroupContainer(),
  34. $this->getDocumentContainer(),
  35. $this->getCreditHistoryContainer(),
  36. $this->getProducerPriceRangeContainer(),
  37. $this->getUserProducerContainer(),
  38. $this->getOrderSatusHistoryContainer(),
  39. $this->getPointSaleDistributionContainer(),
  40. $this->getProductDistributionContainer(),
  41. $this->getProductCategoryContainer(),
  42. $this->getProductPointSaleContainer(),
  43. $this->getProductOrderContainer(),
  44. $this->getProductPriceContainer(),
  45. $this->getProductSubscriptionContainer(),
  46. $this->getUserContainer(),
  47. $this->getSubscriptionContainer(),
  48. $this->getProductContainer(),
  49. $this->getDistributionContainer(),
  50. $this->getProducerContainer(),
  51. $this->getOrderContainer(),
  52. ];
  53. }
  54. public function getUserContainer(): UserContainer
  55. {
  56. return new UserContainer();
  57. }
  58. public function getProducerContainer(): ProducerContainer
  59. {
  60. return new ProducerContainer();
  61. }
  62. public function getProducerPriceRangeContainer(): ProducerPriceRangeContainer
  63. {
  64. return new ProducerPriceRangeContainer();
  65. }
  66. public function getUserProducerContainer(): UserProducerContainer
  67. {
  68. return new UserProducerContainer();
  69. }
  70. public function getCreditHistoryContainer(): CreditHistoryContainer
  71. {
  72. return new CreditHistoryContainer();
  73. }
  74. public function getDocumentContainer(): DocumentContainer
  75. {
  76. return new DocumentContainer();
  77. }
  78. public function getUserGroupContainer(): UserGroupContainer
  79. {
  80. return new UserGroupContainer();
  81. }
  82. public function getUserUserGroupContainer(): UserUserGroupContainer
  83. {
  84. return new UserUserGroupContainer();
  85. }
  86. public function getDistributionContainer(): DistributionContainer
  87. {
  88. return new DistributionContainer();
  89. }
  90. public function getTaxRateContainer(): TaxRateContainer
  91. {
  92. return new TaxRateContainer();
  93. }
  94. public function getOrderContainer(): OrderContainer
  95. {
  96. return new OrderContainer();
  97. }
  98. public function getOrderSatusHistoryContainer(): OrderStatusHistoryContainer
  99. {
  100. return new OrderStatusHistoryContainer();
  101. }
  102. public function getPointSaleContainer(): PointSaleContainer
  103. {
  104. return new PointSaleContainer();
  105. }
  106. public function getProductOrderContainer(): ProductOrderContainer
  107. {
  108. return new ProductOrderContainer();
  109. }
  110. public function getProductContainer(): ProductContainer
  111. {
  112. return new ProductContainer();
  113. }
  114. public function getProductCategoryContainer(): ProductCategoryContainer
  115. {
  116. return new ProductCategoryContainer();
  117. }
  118. public function getProductPointSaleContainer(): ProductPointSaleContainer
  119. {
  120. return new ProductPointSaleContainer();
  121. }
  122. public function getProductPriceContainer(): ProductPriceContainer
  123. {
  124. return new ProductPriceContainer();
  125. }
  126. public function getSubscriptionContainer(): SubscriptionContainer
  127. {
  128. return new SubscriptionContainer();
  129. }
  130. public function getProductSubscriptionContainer(): ProductSubscriptionContainer
  131. {
  132. return new ProductSubscriptionContainer();
  133. }
  134. public function getPointSaleDistributionContainer(): PointSaleDistributionContainer
  135. {
  136. return new PointSaleDistributionContainer();
  137. }
  138. public function getProductDistributionContainer(): ProductDistributionContainer
  139. {
  140. return new ProductDistributionContainer();
  141. }
  142. /*
  143. * Hiérarchie des apps
  144. */
  145. public function getContainerLevelHierarchyByService($serviceClass): int
  146. {
  147. $containersArray = $this->getContainers();
  148. $entityFqcnService = $this->getEntityFqcnByService($serviceClass);
  149. foreach($containersArray as $key => $container) {
  150. if($container->getEntityFqcn() == $entityFqcnService) {
  151. return $key;
  152. }
  153. }
  154. }
  155. public function getEntityFqcnByService(string $serviceClass): string
  156. {
  157. $containersArray = $this->getContainers();
  158. foreach($containersArray as $container) {
  159. if(in_array($serviceClass, $container->getServices())) {
  160. return $container->getEntityFqcn();
  161. }
  162. }
  163. throw new ErrorException('Service '.$serviceClass.' introuvable dans le container.');
  164. }
  165. }