PHP Classes

REST Normalizer: Validate and filter parameters based on JSON rules

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 65%Total: 323 All time: 7,211 This week: 36Up
Version License PHP version Categories
rest-normalizer 1.0.1BSD License5.0PHP 5, Validation
Description 

Author

This class can validate and filter parameters based on JSON rules.

It can take a list of request parameters passed as an array or as a JSON string and validates it according to rules defined in an external files in the JSON format.

The class can traverse the parameter data and check if the entries match the types and validation rules defined in the rules file for the specific type of request.

Invalid values may be discard and logged to a given log file.

The class may also call callback functions before and after the normalization process.

Picture of Dmitry Mamontov
  Performance   Level  
Name: Dmitry Mamontov <contact>
Classes: 16 packages by
Country: Russian Federation Russian Federation
Age: 33
All time rank: 77925 in Russian Federation Russian Federation
Week rank: 180 Up9 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 6x

Details

Latest Stable Version License Total Downloads

REST Normalizer

This class can validate and filter parameters based on JSON rules.

It can take a list of request parameters passed as an array or as a JSON string and validates it according to rules defined in an external files in the JSON format.

The class can traverse the parameter data and check if the entries match the types and validation rules defined in the rules file for the specific type of request.

Invalid values may be discard and logged to a given log file.

The class may also call callback functions before and after the normalization process.

More information.

Requirements

  • PHP version >5.0

Installation

1) Install composer

2) Follow in the project folder:

composer require dmamontov/restnormalizer ~1.0.1

In config composer.json your project will be added to the library dmamontov/restnormalizer, who settled in the folder vendor/. In the absence of a config file or folder with vendors they will be created.

If before your project is not used composer, connect the startup file vendors. To do this, enter the code in the project:

require 'path/to/vendor/autoload.php';

Data types and values to be formatted

The data type "string"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default
  • max - The maximum allowable length of the string
  • min - The minimum allowable length of the string
  • pad - Supplemented with the symbol (default: " ")
"example": {
        "type": "string",
        "required": false,
        "default": "example",
        "max": 15,
        "min": 4,
        "pad": "+"
}

The data type "int"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default
  • max - The maximum allowable value
  • min - The minimum allowable value
"example": {
        "type": "int",
        "required": true,
        "default": 55,
        "max": 203,
        "min": 10
}

The data type "double"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default
  • max - The maximum allowable value
  • min - The minimum allowable value
  • decimals - The number of digits after the decimal point
"example": {
        "type": "double",
        "required": true,
        "default": 5,
        "max": 20.5,
        "min": 1.1,
        "decimals": 5
}

The data type "bool"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default
"example": {
        "type": "bool",
        "required": true,
        "default": true
}

The data type "datetime"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default (default: "now")
  • format - Date and time format
"example": {
        "type": "datetime",
        "required": true,
        "default": "now",
        "format": "Y-m-d H:i:s"
}

The data type "enum"

  • required - Checking the mandatory values, accepts parameters (true, false)
  • default - Default
  • values - An array of enumerated values
"example": {
        "type": "enum",
        "required": true,
        "default": 999,
        "values": [1, 5, 999]
    }

The data type "skip"

"example": {
        "type": "skip"
}

Example of work

require_once 'RestNormalizer.php';
$n = new RestNormalizer();
$n->logFile = 'valid.log';
$n->setValidation('you-valid.json');

$data = array(
	'key1' => 'value1',
	'key2' => 'value2',
	'key3' => 'value3'
);
$data = $n->normalize($data)

  Files folder image Files (6)  
File Role Description
Files folder imageexample (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file RestNormalizer.php Class Class source

  Files folder image Files (6)  /  example  
File Role Description
  Accessible without login Plain text file retailcrm.json Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:323
This week:0
All time:7,211
This week:36Up
User Ratings User Comments (1)
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:582
 
Good class, can be useful.
9 years ago (Vasiliy Trutov)
80%StarStarStarStarStar