Ionizer PHP Filter Input: Filter input values by chaining filter objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (32)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-07-30 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 46 This week: 16All time: 10,127 This week: 14Up
Version License PHP version Categories
ionizer 1.0.0MIT/X Consortium ...5HTTP, PHP 5, Validation
Description Author

This package can filter input values by chaining filter objects.

It provides a general filter container class that can queue a list of filter objects to apply to each expected filter value.

The container filter class take an associative array of values for instance from PHP $_POST or $_GET and then it calls all the queued filter objects to check if the values they match all the filter conditions.

If one filter condition fails, the container filter class triggers an exception.

Innovation Award
PHP Programming Innovation award nominee
July 2021
Number 11
One of the most important security measures of Web applications is to validate and filter the input users passed to the application from external systems.

There are many solutions to validate and filter values of common types.

This package provides a solution that developers can adapt to validate filter any value by using classes that can perform any verification of the input values.

Manuel Lemos
Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 31 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 23x

Winner: 1x

Details

Ionizer

Build Status Latest Stable Version Latest Unstable Version License Downloads

Input filtering system used in CMS Airship, now available for use in any project. Requires PHP 7 or higher.

What is Ionizer?

Ionizer is a structured input filtering system ideal for HTTP form data.

Installing

Get Composer, then run the following:

composer require paragonie/ionizer

Usage

<?php

use ParagonIE\Ionizer\GeneralFilterContainer;
use ParagonIE\Ionizer\Filter\{
    StringFilter,
    AllowList
};

// Define properties to filter:
$ic = new GeneralFilterContainer();
$ic->addFilter(
        'username',
        (new StringFilter())->setPattern('^[A-Za-z0-9_\-]{3,24}$')
    )
    ->addFilter('passphrase', new StringFilter())
    ->addFilter(
        'domain',
        new AllowList('US-1', 'US-2', 'EU-1', 'EU-2')
    );

// Invoke the filter container on the array to get the filtered result:
try {
    // $post passed all of our filters.
    $post = $ic($_POST);
} catch (\TypeError $ex) {
    // Invalid data provided.
}

Ionizer can even specify structured input with some caveats.

<?php

use ParagonIE\Ionizer\GeneralFilterContainer;
use ParagonIE\Ionizer\Filter\{
    IntFilter,
    IntArrayFilter,
    StringArrayFilter,
    StringFilter
};

$ic = new GeneralFilterContainer();
    // You can type entire arrays at once:
$ic->addFilter('numbers', new IntArrayFilter())
    ->addFilter('strings', new StringArrayFilter())
    
    // You can also specify subkeys, separated by a period:
    ->addFilter('user.name', new StringFilter())
    ->addFilter('user.unixtime', new IntFilter());

$input = [
    'numbers' => [1, 2, 3],
    'strings' => ['a', 'b'],
    'user' => [
        'name' => 'test',
        'unixtime' => time()
    ]    
];

try {
    $valid = $ic($input);
} catch (\TypeError $ex) {
}

Support Contracts

If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises.

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (5 files, 2 directories)
Files folder imagetests (4 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file ci.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageContract (2 files)
Files folder imageFilter (11 files, 1 directory)
  Accessible without login Plain text file GeneralFilterContainer.php Class Class source
  Accessible without login Plain text file InputFilter.php Class Class source
  Accessible without login Plain text file InputFilterContainer.php Class Class source
  Accessible without login Plain text file InvalidDataException.php Class Class source
  Accessible without login Plain text file Util.php Class Class source

  Files folder image Files  /  src  /  Contract  
File Role Description
  Accessible without login Plain text file FilterContainerInterface.php Class Class source
  Accessible without login Plain text file FilterInterface.php Class Class source

  Files folder image Files  /  src  /  Filter  
File Role Description
Files folder imageSpecial (3 files)
  Accessible without login Plain text file AllowList.php Class Class source
  Accessible without login Plain text file ArrayFilter.php Class Class source
  Accessible without login Plain text file BoolArrayFilter.php Class Class source
  Accessible without login Plain text file BoolFilter.php Class Class source
  Accessible without login Plain text file FloatArrayFilter.php Class Class source
  Accessible without login Plain text file FloatFilter.php Class Class source
  Accessible without login Plain text file IntArrayFilter.php Class Class source
  Accessible without login Plain text file IntFilter.php Class Class source
  Accessible without login Plain text file StrictArrayFilter.php Class Class source
  Accessible without login Plain text file StringArrayFilter.php Class Class source
  Accessible without login Plain text file StringFilter.php Class Class source

  Files folder image Files  /  src  /  Filter  /  Special  
File Role Description
  Accessible without login Plain text file CreditCardNumberFilter.php Class Class source
  Accessible without login Plain text file DateTimeFilter.php Class Class source
  Accessible without login Plain text file EmailAddressFilter.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageErrata (1 file)
  Accessible without login Plain text file AllowListTest.php Class Class source
  Accessible without login Plain text file ArrayFilterTest.php Class Class source
  Accessible without login Plain text file FilterTest.php Class Class source
  Accessible without login Plain text file SpecialTest.php Class Class source

  Files folder image Files  /  tests  /  Errata  
File Role Description
  Accessible without login Plain text file GenericFilterContainer.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:46
This week:16
All time:10,127
This week:14Up
For more information send a message to info at phpclasses dot org.