[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/lcobucci/jwt/src/ -> Configuration.php (source)

   1  <?php
   2  
   3  namespace Lcobucci\JWT;
   4  
   5  use Closure;
   6  use Lcobucci\JWT\Parsing\Decoder;
   7  use Lcobucci\JWT\Parsing\Encoder;
   8  use Lcobucci\JWT\Signer\Key;
   9  use Lcobucci\JWT\Signer\Key\InMemory;
  10  use Lcobucci\JWT\Signer\None;
  11  use Lcobucci\JWT\Validation\Constraint;
  12  
  13  /**
  14   * Configuration container for the JWT Builder and Parser
  15   *
  16   * Serves like a small DI container to simplify the creation and usage
  17   * of the objects.
  18   */
  19  final class Configuration
  20  {
  21      /** @var Parser */
  22      private $parser;
  23  
  24      /** @var Signer */
  25      private $signer;
  26  
  27      /** @var Key */
  28      private $signingKey;
  29  
  30      /** @var Key */
  31      private $verificationKey;
  32  
  33      /** @var Validator */
  34      private $validator;
  35  
  36      /** @var Closure(): Builder */
  37      private $builderFactory;
  38  
  39      /** @var Constraint[] */
  40      private $validationConstraints = [];
  41  
  42      private function __construct(
  43          Signer $signer,
  44          Key $signingKey,
  45          Key $verificationKey,
  46          Encoder $encoder = null,
  47          Decoder $decoder = null
  48      ) {
  49          $this->signer          = $signer;
  50          $this->signingKey      = $signingKey;
  51          $this->verificationKey = $verificationKey;
  52          $this->parser          = new Parser($decoder ?: new Decoder());
  53          $this->validator       = new Validation\Validator();
  54  
  55          $this->builderFactory = static function () use ($encoder) {
  56              return new Builder($encoder ?: new Encoder());
  57          };
  58      }
  59  
  60      /** @return self */
  61      public static function forAsymmetricSigner(
  62          Signer $signer,
  63          Key $signingKey,
  64          Key $verificationKey,
  65          Encoder $encoder = null,
  66          Decoder $decoder = null
  67      ) {
  68          return new self(
  69              $signer,
  70              $signingKey,
  71              $verificationKey,
  72              $encoder,
  73              $decoder
  74          );
  75      }
  76  
  77      /** @return self */
  78      public static function forSymmetricSigner(
  79          Signer $signer,
  80          Key $key,
  81          Encoder $encoder = null,
  82          Decoder $decoder = null
  83      ) {
  84          return new self(
  85              $signer,
  86              $key,
  87              $key,
  88              $encoder,
  89              $decoder
  90          );
  91      }
  92  
  93      /** @return self */
  94      public static function forUnsecuredSigner(
  95          Encoder $encoder = null,
  96          Decoder $decoder = null
  97      ) {
  98          $key = InMemory::plainText('');
  99  
 100          return new self(
 101              new None(),
 102              $key,
 103              $key,
 104              $encoder,
 105              $decoder
 106          );
 107      }
 108  
 109      /** @param callable(): Builder $builderFactory */
 110      public function setBuilderFactory(callable $builderFactory)
 111      {
 112          if (! $builderFactory instanceof Closure) {
 113              $builderFactory = static function() use ($builderFactory) {
 114                  return $builderFactory();
 115              };
 116          }
 117          $this->builderFactory = $builderFactory;
 118      }
 119  
 120      /** @return Builder */
 121      public function builder()
 122      {
 123          $factory = $this->builderFactory;
 124  
 125          return $factory();
 126      }
 127  
 128      /** @return Parser */
 129      public function parser()
 130      {
 131          return $this->parser;
 132      }
 133  
 134      public function setParser(Parser $parser)
 135      {
 136          $this->parser = $parser;
 137      }
 138  
 139      /** @return Signer */
 140      public function signer()
 141      {
 142          return $this->signer;
 143      }
 144  
 145      /** @return Key */
 146      public function signingKey()
 147      {
 148          return $this->signingKey;
 149      }
 150  
 151      /** @return Key */
 152      public function verificationKey()
 153      {
 154          return $this->verificationKey;
 155      }
 156  
 157      /** @return Validator */
 158      public function validator()
 159      {
 160          return $this->validator;
 161      }
 162  
 163      public function setValidator(Validator $validator)
 164      {
 165          $this->validator = $validator;
 166      }
 167  
 168      /** @return Constraint[] */
 169      public function validationConstraints()
 170      {
 171          return $this->validationConstraints;
 172      }
 173  
 174      public function setValidationConstraints(Constraint ...$validationConstraints)
 175      {
 176          $this->validationConstraints = $validationConstraints;
 177      }
 178  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer