PHP Classes

File: src/ConstraintTrait.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   PASERK PHP   src/ConstraintTrait.php   Download  
File: src/ConstraintTrait.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PASERK PHP
Extend PASETO to wrap and serialize keys
Author: By
Last change:
Date: 2 years ago
Size: 1,069 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Paserk;

use
ParagonIE\Paseto\ProtocolCollection;
use
ParagonIE\Paseto\ProtocolInterface;

trait
ConstraintTrait
{
   
/** @var ?ProtocolCollection $collection */
   
protected ?ProtocolCollection $collection = null;

   
/**
     * Specify the allowed protocols for this PASERK type.
     *
     * @param ProtocolCollection|null $collection
     * @return static
     */
   
public function setProtocolsAllowed(?ProtocolCollection $collection = null): static
    {
       
$this->collection = $collection;
        return
$this;
    }

   
/**
     * Throw a PASERK exception if the given PASETO version isn't permitted.
     *
     * @param ProtocolInterface $given
     * @return void
     *
     * @throws PaserkException
     */
   
public function throwIfInvalidProtocol(ProtocolInterface $given): void
   
{
        if (
is_null($this->collection)) {
            return;
        }
        if (!
$this->collection->has($given)) {
            throw new
PaserkException("Invalid protocol version");
        }
    }
}