[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  /**
   3   * This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS
   4   *
   5   * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
   6   */
   7  
   8  namespace Lcobucci\JWT\Claim;
   9  
  10  use DateTimeImmutable;
  11  use Lcobucci\JWT\Claim;
  12  use Lcobucci\JWT\Token\RegisteredClaims;
  13  use function current;
  14  use function in_array;
  15  use function is_array;
  16  
  17  /**
  18   * Class that create claims
  19   *
  20   * @deprecated This class will be removed on v4
  21   *
  22   * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
  23   * @since 2.0.0
  24   */
  25  class Factory
  26  {
  27      /**
  28       * The list of claim callbacks
  29       *
  30       * @var array
  31       */
  32      private $callbacks;
  33  
  34      /**
  35       * Initializes the factory, registering the default callbacks
  36       *
  37       * @param array $callbacks
  38       */
  39      public function __construct(array $callbacks = [])
  40      {
  41          $this->callbacks = array_merge(
  42              [
  43                  'iat' => [$this, 'createLesserOrEqualsTo'],
  44                  'nbf' => [$this, 'createLesserOrEqualsTo'],
  45                  'exp' => [$this, 'createGreaterOrEqualsTo'],
  46                  'iss' => [$this, 'createEqualsTo'],
  47                  'aud' => [$this, 'createEqualsTo'],
  48                  'sub' => [$this, 'createEqualsTo'],
  49                  'jti' => [$this, 'createEqualsTo']
  50              ],
  51              $callbacks
  52          );
  53      }
  54  
  55      /**
  56       * Create a new claim
  57       *
  58       * @param string $name
  59       * @param mixed $value
  60       *
  61       * @return Claim
  62       */
  63      public function create($name, $value)
  64      {
  65          if ($value instanceof DateTimeImmutable && in_array($name, RegisteredClaims::DATE_CLAIMS, true)) {
  66              $value = $value->getTimestamp();
  67          }
  68  
  69          if ($name === RegisteredClaims::AUDIENCE && is_array($value)) {
  70              $value = current($value);
  71          }
  72  
  73          if (!empty($this->callbacks[$name])) {
  74              return call_user_func($this->callbacks[$name], $name, $value);
  75          }
  76  
  77          return $this->createBasic($name, $value);
  78      }
  79  
  80      /**
  81       * Creates a claim that can be compared (greator or equals)
  82       *
  83       * @param string $name
  84       * @param mixed $value
  85       *
  86       * @return GreaterOrEqualsTo
  87       */
  88      private function createGreaterOrEqualsTo($name, $value)
  89      {
  90          return new GreaterOrEqualsTo($name, $value);
  91      }
  92  
  93      /**
  94       * Creates a claim that can be compared (greator or equals)
  95       *
  96       * @param string $name
  97       * @param mixed $value
  98       *
  99       * @return LesserOrEqualsTo
 100       */
 101      private function createLesserOrEqualsTo($name, $value)
 102      {
 103          return new LesserOrEqualsTo($name, $value);
 104      }
 105  
 106      /**
 107       * Creates a claim that can be compared (equals)
 108       *
 109       * @param string $name
 110       * @param mixed $value
 111       *
 112       * @return EqualsTo
 113       */
 114      private function createEqualsTo($name, $value)
 115      {
 116          return new EqualsTo($name, $value);
 117      }
 118  
 119      /**
 120       * Creates a basic claim
 121       *
 122       * @param string $name
 123       * @param mixed $value
 124       *
 125       * @return Basic
 126       */
 127      private function createBasic($name, $value)
 128      {
 129          return new Basic($name, $value);
 130      }
 131  }


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