vendor/roothirsch/core-bundle/EventSubscriber/FeatureSubscriber.php line 36

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\CoreBundle\EventSubscriber;
  3. use ApiPlatform\Core\EventListener\EventPriorities;
  4. use Flagception\Manager\FeatureManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\Yaml\Yaml;
  8. final class FeatureSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var FeatureManagerInterface
  12.      */
  13.     private $featureManager;
  14.     /**
  15.      * @var string
  16.      */
  17.     private $configDir;
  18.     public function __construct(FeatureManagerInterface $featureManager$configDir)
  19.     {
  20.         $this->featureManager $featureManager;
  21.         $this->configDir $configDir;
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             KernelEvents::VIEW => ['load'EventPriorities::PRE_SERIALIZE],
  27.         ];
  28.     }
  29.     public function load(\Symfony\Component\HttpKernel\Event\ViewEvent $event)
  30.     {
  31.         if ($event->getRequest()->getPathInfo() == '/api/users/current') {
  32.             $event->getControllerResult()->setFeatures($this->getFeatures());
  33.         }
  34.     }
  35.     private function getFeatures()
  36.     {
  37.         $config Yaml::parse(file_get_contents($this->configDir 'packages/flagception.yaml'));
  38.         $features = [];
  39.         foreach (array_keys($config['flagception']['features']) as $featureName) {
  40.             $features[$featureName] = $this->featureManager->isActive($featureName);
  41.         }
  42.         return $features;
  43.     }
  44. }