vendor/league/oauth2-server-bundle/src/EventListener/AddClientDefaultScopesListener.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace League\Bundle\OAuth2ServerBundle\EventListener;
  4. use League\Bundle\OAuth2ServerBundle\Event\PreSaveClientEvent;
  5. use League\Bundle\OAuth2ServerBundle\Model\Scope;
  6. /**
  7.  * Sets default scopes to the client before being saved by a ClientManager if no scope is specified.
  8.  *
  9.  * @author Mathias Arlaud <mathias.arlaud@gmail.com>
  10.  */
  11. class AddClientDefaultScopesListener
  12. {
  13.     /**
  14.      * @var list<string>
  15.      */
  16.     private $defaultScopes;
  17.     /**
  18.      * @param list<string> $defaultScopes
  19.      */
  20.     public function __construct(array $defaultScopes)
  21.     {
  22.         $this->defaultScopes $defaultScopes;
  23.     }
  24.     public function __invoke(PreSaveClientEvent $event): void
  25.     {
  26.         $client $event->getClient();
  27.         if ([] !== $client->getScopes()) {
  28.             return;
  29.         }
  30.         $client->setScopes(...array_map(static function (string $scope): Scope {
  31.             return new Scope($scope);
  32.         }, $this->defaultScopes));
  33.     }
  34. }