wirnex/arguments-check 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wirnex/arguments-check

最新稳定版本:1.0.0

Composer 安装命令:

composer require wirnex/arguments-check

包简介

Data validating PHP

README 文档

README

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

统计信息

  • 总下载量: 476
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-17