<?php
namespace Platform\SecurityBundle\Model\OAuth;
use JsonSerializable;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class OAuthOptions
* @package Platform\SecurityBundle\Model\OAuth
*/
final class OAuthOptions implements JsonSerializable
{
/**
* @var array|string[]
*/
protected array $scopes;
/**
* @var string|null
*/
protected ?string $callback;
/**
* @var array
*/
protected array $state;
/**
* @param array $options
*/
public function __construct(array $options = [])
{
$options = $this->configureOptions($options);
$this->scopes = $options['scopes'];
sort($this->scopes);
$this->callback = trim($options['callback']);
if (empty($this->callback)) {
$this->callback = null;
}
$this->state = $options['state'];
ksort($this->state);
}
/**
* @param array $options
* @return array
*/
private function configureOptions(array $options)
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
'scopes' => [],
'callback' => null,
'state' => [],
]);
$resolver->setAllowedTypes('scopes', 'array');
$resolver->setAllowedTypes('callback', ['string','null']);
$resolver->setAllowedTypes('state', 'array');
return $resolver->resolve($options);
}
/**
* @return array|string[]
*/
public function getScopes(): array
{
return $this->scopes;
}
/**
* @return string|null
*/
public function getCallback(): ?string
{
return $this->callback;
}
/**
* @return array
*/
public function getState(): array
{
return $this->state;
}
public function jsonSerialize()
{
// TODO: Implement jsonSerialize() method.
}
}