您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

52 行
1.5KB

  1. <?php
  2. namespace domain\Feature\Feature;
  3. use domain\Feature\FeatureProducer\FeatureProducerRepository;
  4. use domain\_\AbstractChecker;
  5. use yii\base\ErrorException;
  6. class FeatureChecker extends AbstractChecker
  7. {
  8. protected FeatureRepository $featureRepository;
  9. protected FeatureProducerRepository $featureProducerRepository;
  10. public function loadDependencies(): void
  11. {
  12. $this->featureRepository = $this->loadService(FeatureRepository::class);
  13. $this->featureProducerRepository = $this->loadService(FeatureProducerRepository::class);
  14. }
  15. public function isEnabled(string $aliasFeature): bool
  16. {
  17. $feature = $this->featureRepository->findOneFeatureByAlias($aliasFeature);
  18. if(!$feature) {
  19. throw new ErrorException("Fonctionnalité avec l'alias '".$aliasFeature."' non trouvée");
  20. }
  21. if(!$feature->status) {
  22. return false;
  23. }
  24. $featureProducer = null;
  25. if($this->getProducerContext(false)) {
  26. $featureProducer = $this->featureProducerRepository->findOneFeatureProducer($feature);
  27. }
  28. if(!$featureProducer || is_null($featureProducer->status)) {
  29. if($feature->is_paid_feature || $feature->only_for_selected_producers) {
  30. return false;
  31. }
  32. return $feature->status;
  33. }
  34. else {
  35. return $featureProducer->status;
  36. }
  37. }
  38. public function isDisabled(string $aliasFeature): bool
  39. {
  40. return !$this->isEnabled($aliasFeature);
  41. }
  42. }