GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Wirnex/arguments-check.php: PHP Class for validating an array passed as argument of any function

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
ArgumentsCheck.php
ArgumentsCheck.php
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
test.php
test.php
 
 

Repository files navigation

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.

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

About

PHP Class for validating an array passed as argument of any function

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.