2017 © Pedro Peláez
 

library arguments-check

Data validating PHP

image

wirnex/arguments-check

Data validating PHP

  • Tuesday, February 17, 2015
  • by Ingvaar
  • Repository
  • 1 Watchers
  • 0 Stars
  • 467 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

arguments-check.php

Usage

Assume we have some function which takes an array as argument and then reads this array with some keys. In some situations the array may not contain specific keys. This class is to validate an input array passed into the function., (*1)

require 'ArgumentsCheck.php';

function feedMeWithAnArray(array $data)
{
    $balance = 0;
    // Using ArgumentsCheck class we describe what array we expect
    ArgumentsCheck::CheckArguments(array('userId', 'sum', 'timestamp'),  $data);
    //
    // here we sure that all arguments were passed to function
    // and we don't need any extra validation code
    $userId  = $data['userId'];
    $balance += $data['sum'];
    $time    = $data['timestamp'];
}

// calling this function with not exactly what is wants
feedMeWithAnArray(array(
  'userId'=>130,
  'sum'=>1000,
  'timestam'=>'2014-06-29 13:44' // we have mistake here in key "timestam" while the function expects "timestamp"
                                 // <- and here comes an exception
)); 

Run tests

phpunit test.php

Install

composer require wirnex/arguments-check

The Versions

17/02 2015

dev-master

9999999-dev https://github.com/Wirnex

Data validating PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

check arguments

17/02 2015

1.0.0

1.0.0.0 https://github.com/Wirnex

Data validating PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

check arguments

17/02 2015

1.0.0-alpha

1.0.0.0-alpha https://github.com/Wirnex

Data validating PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

check arguments