src/Activator/AdminActivator.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Activator;
  3. use App\Entity\Feature;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\Query\QueryException;
  6. use Flagception\Activator\FeatureActivatorInterface;
  7. use Flagception\Model\Context;
  8. class AdminActivator implements FeatureActivatorInterface
  9. {
  10.     /**
  11.      * @var EntityManagerInterface
  12.      */
  13.     private $manager;
  14.     /**
  15.      * @var array
  16.      */
  17.     private $features = [];
  18.     public function __construct(
  19.         EntityManagerInterface $manager
  20.     ) {
  21.         $this->manager $manager;
  22.     }
  23.     /**
  24.      * Get unique activator name.
  25.      *
  26.      * @return string
  27.      */
  28.     public function getName()
  29.     {
  30.         return 'admin';
  31.     }
  32.     /**
  33.      * Check if the given feature name is active
  34.      * Optional the context object can contain further options to check.
  35.      *
  36.      * @param string $name
  37.      */
  38.     public function isActive($nameContext $context): bool
  39.     {
  40.         if (!isset($this->getFeatures()[$name]) || !$this->getFeatures()[$name]) {
  41.             return false;
  42.         }
  43.         return true;
  44.     }
  45.     /**
  46.      * @throws QueryException
  47.      */
  48.     public function isExternalATSEnabled(): bool
  49.     {
  50.         $enabledAtsFeatures $this->manager->getRepository(Feature::class)->findEnabledExternalATSFeatures();
  51.         return \count($enabledAtsFeatures) > 0;
  52.     }
  53.     public function getFeatures(): array
  54.     {
  55.         if ([] === $this->features) {
  56.             $featureCandidates $this->manager->getRepository(Feature::class)->getAdminActivatorCandidates();
  57.             foreach ($featureCandidates as $feature) {
  58.                 $this->features[$feature['name']] = $feature['active'];
  59.             }
  60.         }
  61.         return $this->features;
  62.     }
  63. }