2017 © Pedro Peláez
 

library input

Input Handling.

image

netherphp/input

Input Handling.

  • Sunday, August 20, 2017
  • by bobmajdakjr
  • Repository
  • 0 Watchers
  • 0 Stars
  • 123 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 10 % Grown

The README.md

Nether Input

nether.io Code Climate Build Status Packagist Packagist, (*1)

An input filtering interface. It allows you to define a set of dynamic filters for input to be run applied just-in-time on your specified data source., (*2)

Super simple example:

$input = (new Nether\Input\Filter)
->Email(function($t){ return filter_var($t,FILTER_VALIDATE_EMAIL); });

// ... some time later...

$input->SetDataset($_POST);
if(!$input->Email) {
    throw new Exception('valid email address is required.');
}

To pull this off, things like your HTML form field names will need to follow the same rules as properties in PHP (alphanumeric and _ starting with a letter). By default it is case insensitive, so you can send all lowercase from your URL if you want and then reference them in whateverCase YouChoose to use. That can be disabled if you are on a performance powertrip., (*3)

You can pass any array or object to the constructor or use SetDataset(). Typical uses would be for _GET and _POST but you could apply it to any named dataset that needs looked at. You can also change datasets at will, keeping any predefined filters intact., (*4)

Another Simple Example:

Lets say we want to dump our POST data back into our form because there was some sort of validation error. This is the time where it is very easy to accidentally open yourself up to cross-site scripting problems. Input Filter can take care of that for you though by defining a default filter that all fields which do not have their own special filters for, get run through., (*5)

$data = (new Nether\Input\Filter($_POST))
->SetDefaultFunction(function($v){ return htmlspecialchars($v) });

// ... some time later...

<input type="text" name="Username" value="<?php echo $data->Username ?>" />

Creating a new interface.

Wrap any object or array in the OOP interface., (*6)

$input = new Nether\Input\Filter($_POST);

Retrieve a value.

Fetch the value from $_POST['myfield'], after running it through any filters we assigned to the field., (*7)

$val = $input->MyField

Set a value.

Note, this will not update the original source array. Writing back to the dataset will prompt the copy-on-write, so now you have your own unique dataset and in this example, will not affect the original $_POST['myfield']., (*8)

$input->MyField = 'ten';

Set a filter.

You call the field as a method, passing it a callable function with one argument which is the value., (*9)

$input->MyField(function($t){
    return str_repalce('a','@',$t);
});

Retrieve a filter.

You invoke the object directly, passing it a string that was the name of the field you originally defined the callback on. Here is an example reusing an existing callback on another field., (*10)

$input->MyOtherField($input('MyField'));

Installing

Require this package in your composer.json., (*11)

require {
    "netherphp/input": "~1.0.0"
}

Then install it or update into it., (*12)

$ composer install --no-dev
$ composer update --no-dev

Testing

This library uses Codeception for testing. Composer will handle it for you. Install or Update into it., (*13)

$ composer install --dev
$ composer update --dev

Then run the tests., (*14)

$ php vendor/bin/codecept run unit
$ vendor\bin\codecept run unit

The Versions

20/08 2017

dev-master

9999999-dev

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

20/08 2017

v3.0.0

3.0.0.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

02/05 2016

v2.0.3

2.0.3.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

02/05 2016

v2.0.2

2.0.2.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

04/04 2016

v2.0.1

2.0.1.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

26/02 2016

v2.0.0

2.0.0.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

php filter input sanitisation

05/01 2016

v1.0.4

1.0.4.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

php filter input sanitisation

07/08 2015

v1.0.3

1.0.3.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

php filter input sanitisation

27/05 2015

v1.0.2

1.0.2.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

php filter input sanitisation

20/05 2015

v1.0.1

1.0.1.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

php filter input sanitisation

13/05 2015

v1.0.0

1.0.0.0

Input Handling.

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

php filter input sanitisation