[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/web-auth/webauthn-lib/src/ -> PublicKeyCredentialDescriptorCollection.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 ArrayIterator;
  17  use Assert\Assertion;
  18  use Countable;
  19  use Iterator;
  20  use IteratorAggregate;
  21  use JsonSerializable;
  22  
  23  class PublicKeyCredentialDescriptorCollection implements JsonSerializable, Countable, IteratorAggregate
  24  {
  25      /**
  26       * @var PublicKeyCredentialDescriptor[]
  27       */
  28      private $publicKeyCredentialDescriptors = [];
  29  
  30      public function add(PublicKeyCredentialDescriptor $publicKeyCredentialDescriptor): void
  31      {
  32          $this->publicKeyCredentialDescriptors[$publicKeyCredentialDescriptor->getId()] = $publicKeyCredentialDescriptor;
  33      }
  34  
  35      public function has(string $id): bool
  36      {
  37          return \array_key_exists($id, $this->publicKeyCredentialDescriptors);
  38      }
  39  
  40      public function remove(string $id): void
  41      {
  42          if (!$this->has($id)) {
  43              return;
  44          }
  45  
  46          unset($this->publicKeyCredentialDescriptors[$id]);
  47      }
  48  
  49      public function getIterator(): Iterator
  50      {
  51          return new ArrayIterator($this->publicKeyCredentialDescriptors);
  52      }
  53  
  54      public function count(int $mode = COUNT_NORMAL): int
  55      {
  56          return \count($this->publicKeyCredentialDescriptors, $mode);
  57      }
  58  
  59      public function jsonSerialize(): array
  60      {
  61          return array_values($this->publicKeyCredentialDescriptors);
  62      }
  63  
  64      public static function createFromString(string $data): self
  65      {
  66          $data = json_decode($data, true);
  67          Assertion::eq(JSON_ERROR_NONE, json_last_error(), 'Invalid data');
  68          Assertion::isArray($data, 'Invalid data');
  69  
  70          return self::createFromArray($data);
  71      }
  72  
  73      public static function createFromArray(array $json): self
  74      {
  75          $collection = new self();
  76          foreach ($json as $item) {
  77              $collection->add(PublicKeyCredentialDescriptor::createFromArray($item));
  78          }
  79  
  80          return $collection;
  81      }
  82  }


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