src/Platform/SecurityBundle/Model/OAuth/OAuthOptions.php line 37

Open in your IDE?
  1. <?php
  2. namespace Platform\SecurityBundle\Model\OAuth;
  3. use JsonSerializable;
  4. use Symfony\Component\OptionsResolver\OptionsResolver;
  5. /**
  6.  * Class OAuthOptions
  7.  * @package Platform\SecurityBundle\Model\OAuth
  8.  */
  9. final class OAuthOptions implements JsonSerializable
  10. {
  11.     /**
  12.      * @var array|string[]
  13.      */
  14.     protected array $scopes;
  15.     /**
  16.      * @var string|null
  17.      */
  18.     protected ?string $callback;
  19.     /**
  20.      * @var array
  21.      */
  22.     protected array $state;
  23.     /**
  24.      * @param array $options
  25.      */
  26.     public function __construct(array $options = [])
  27.     {
  28.         $options $this->configureOptions($options);
  29.         $this->scopes $options['scopes'];
  30.         sort($this->scopes);
  31.         $this->callback trim($options['callback']);
  32.         if (empty($this->callback)) {
  33.             $this->callback null;
  34.         }
  35.         $this->state $options['state'];
  36.         ksort($this->state);
  37.     }
  38.     /**
  39.      * @param array $options
  40.      * @return array
  41.      */
  42.     private function configureOptions(array $options)
  43.     {
  44.         $resolver = new OptionsResolver();
  45.         $resolver->setDefaults([
  46.             'scopes' => [],
  47.             'callback' => null,
  48.             'state' => [],
  49.         ]);
  50.         $resolver->setAllowedTypes('scopes''array');
  51.         $resolver->setAllowedTypes('callback', ['string','null']);
  52.         $resolver->setAllowedTypes('state''array');
  53.         return $resolver->resolve($options);
  54.     }
  55.     /**
  56.      * @return array|string[]
  57.      */
  58.     public function getScopes(): array
  59.     {
  60.         return $this->scopes;
  61.     }
  62.     /**
  63.      * @return string|null
  64.      */
  65.     public function getCallback(): ?string
  66.     {
  67.         return $this->callback;
  68.     }
  69.     /**
  70.      * @return array
  71.      */
  72.     public function getState(): array
  73.     {
  74.         return $this->state;
  75.     }
  76.     public function jsonSerialize()
  77.     {
  78.         // TODO: Implement jsonSerialize() method.
  79.     }
  80. }