You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
6.0KB

  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. }