siriusphp/filtration

Data filtration library

Maintainers

👁 adrianmiu

Package info

github.com/siriusphp/filtration

pkg:composer/siriusphp/filtration

Statistics

Installs: 1 815

Dependents: 3

Suggesters: 0

Stars: 6

Open Issues: 1

2.0.0 2020-02-23 16:43 UTC

Requires

  • php: >=7.1

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 431e4cf057143d4a8f8033652cb55bca38e0b5f9

  • Adrian Miu <adrian.woop@adrianmiu.ro>

securityforminputsanitizationfiltration

This package is auto-updated.

Last update: 2026-06-24 20:21:21 UTC


README

#Sirius\Filtration

👁 Source Code
👁 Latest Version
👁 Software License
👁 Build Status
👁 Coverage Status
👁 Quality Score

PHP library for array filtering/sanitization

Sometimes you want to make sure the values pushed by a source (eg: a user when submits a form) follow some restrictions like

  • no space at the beginning or the end for the title of a page
  • no HTML code in a comment sent by a user
  • no spaces in the field which represents the URL
  • remove XSS attacks
  • etc...

Other times you want to make sure that the data you send to the user is parsed before displaying. For example you may want to:

  • convert markdown into HTML
  • convert URLs into links
  • apply a localized format to dates
  • etc ()

To achieve this end result you need to filter the values. This is where SiriusFiltration comes into place

Elevator pitch

use Sirius\Filtration\Filtrator;

$filtrator = new Filtrator();

// add filters for title
$filtrator->add('title', 'trim');
$filtrator->add('title', 'strip_tags');
$filtrator->add('title', 'nullify');

// add filters for content in one go
$filtrator->add('content', [
	'trim'
]);

$result = $filtrator->filter(array(
	'title' => ' <h1>My title has tags and is awesome</h1>',
	'content' => ' My content was trimmed'
));

/* $result is
array(
	'title' => NULL ,
	'content' => 'My content was trimmed'
)
*/

Links