PHP Classes

File: src/Exception/FormPostException.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   Anti-CSRF   src/Exception/FormPostException.php   Download  
File: src/Exception/FormPostException.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Anti-CSRF
Generate tokens to protect against CSRF exploits
Author: By
Last change:
Date: 8 months ago
Size: 1,295 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

namespace
ParagonIE\AntiCSRF\Exception;

/**
 * Class TokenNotInSessionException
 *
 * @package ParagonIE\AntiCSRF
 */
class FormPostException extends AntiCSRFException
{
    const
CODE_MISSING_INDEX = 1;
    const
CODE_MISSING_TOKEN = 2;
    const
CODE_TYPE_INDEX = 3;
    const
CODE_TYPE_TOKEN = 4;

    public static function
missingIndex(string $formFieldName): self
   
{
        return new
self(
            \
sprintf('Missing index form post with name "%s"', $formFieldName),
           
self::CODE_MISSING_INDEX
       
);
    }

    public static function
missingToken(string $formFieldName): self
   
{
        return new
self(
            \
sprintf('Missing token form post with name "%s"', $formFieldName),
           
self::CODE_MISSING_TOKEN
       
);
    }

    public static function
indexTypeError(string $value): self
   
{
        return new
self(
            \
sprintf('Index form post value expected to be string, "%s" given', \gettype($value)),
           
self::CODE_TYPE_INDEX
       
);
    }

    public static function
tokenTypeError(string $value): self
   
{
        return new
self(
            \
sprintf('Token form post value expected to be string, "%s" given', \gettype($value)),
           
self::CODE_TYPE_TOKEN
       
);
    }
}