Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

FeatureChecker.php 1.5KB

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