[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/webauthn-lib/src/ -> PublicKeyCredentialUserEntity.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  /*
   6   * The MIT License (MIT)
   7   *
   8   * Copyright (c) 2014-2019 Spomky-Labs
   9   *
  10   * This software may be modified and distributed under the terms
  11   * of the MIT license.  See the LICENSE file for details.
  12   */
  13  
  14  namespace Webauthn;
  15  
  16  use Assert\Assertion;
  17  
  18  class PublicKeyCredentialUserEntity extends PublicKeyCredentialEntity
  19  {
  20      /**
  21       * @var string
  22       */
  23      protected $id;
  24  
  25      /**
  26       * @var string
  27       */
  28      protected $displayName;
  29  
  30      public function __construct(string $name, string $id, string $displayName, ?string $icon = null)
  31      {
  32          parent::__construct($name, $icon);
  33          $this->id = $id;
  34          $this->displayName = $displayName;
  35      }
  36  
  37      public function getId(): string
  38      {
  39          return $this->id;
  40      }
  41  
  42      public function getDisplayName(): string
  43      {
  44          return $this->displayName;
  45      }
  46  
  47      public static function createFromString(string $data): self
  48      {
  49          $data = json_decode($data, true);
  50          Assertion::eq(JSON_ERROR_NONE, json_last_error(), 'Invalid data');
  51          Assertion::isArray($data, 'Invalid data');
  52  
  53          return self::createFromArray($data);
  54      }
  55  
  56      public static function createFromArray(array $json): self
  57      {
  58          Assertion::keyExists($json, 'name', 'Invalid input. "name" is missing.');
  59          Assertion::keyExists($json, 'id', 'Invalid input. "id" is missing.');
  60          Assertion::keyExists($json, 'displayName', 'Invalid input. "displayName" is missing.');
  61          $id = base64_decode($json['id'], true);
  62          Assertion::string($id, 'Invalid parameter "id".');
  63  
  64          return new self(
  65              $json['name'],
  66              $id,
  67              $json['displayName'],
  68              $json['icon'] ?? null
  69          );
  70      }
  71  
  72      public function jsonSerialize(): array
  73      {
  74          $json = parent::jsonSerialize();
  75          $json['id'] = base64_encode($this->id);
  76          $json['displayName'] = $this->displayName;
  77  
  78          return $json;
  79      }
  80  }


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