定制 djordje/li3_validators 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

djordje/li3_validators

Composer 安装命令:

composer require djordje/li3_validators

包简介

Collection of lithium validators

README 文档

README

Table of content:

Installation adn usage:

Git clone:

	cd path/to/libraries
	git clone git://github.com/djordje/li3_validators.git

Or trough composer:

Add this to your composer.json file:

	{
		"minimum-stability": "dev",
		"require": {
			"djordje/li3_validators": "dev-master"
		}
	}

After either of these two steps open app/config/bootstrap/libraries.php with your editor and add this to bootom of the file:

Libraries::add('li3_validators')

Now you can use this validators in your model just as any other bundled or added validator!

Custom validators:

Unique validator

Name: 'unique'

Ensure that entered value is unique in database. If 'events' is update do query with provided options

Options:

'key' string - Database table key that will be used as condition key if 'events' is update, by default 'id'

'keyValue' string - Setup key value if you don't want to fetch it from 'values' field, by default null which means that field fetch value of $options['values']['id'] if you don't change 'key'

Confirm validator

Name: 'confirm'

Confirm that this field is equal to field against we compare.

Options:

'strategy' string (direct|password) - Default is 'direct' which means we compare value against desired field directly 'string' === 'string'. If we set this to 'password' validator use Password::check() for comparing value against desired field

'against' string - By default this is null which means we will compare this field against same named field with confirm_ prefix, eg. email against confirm_email, or we can set field name against we want to compare

Dependencies validator

Name: 'dependencies'

Check field dependencies. Evaluate conditions to see if all dependencies are correct

Options:

'conditions' array - Eval comparation builder compatible conditions array

Example:

	$options = array('conditions' => array(
		array('gender', '===', 'M')
	));

This field will require 'gender' field equal to 'M'

Compare with old db value validator

Name: 'compareWithOldDbValue'

Compare value with existing value in database

Options:

'strategy' string (direct|password) - Default is 'direct' which means we compare value against desired field directly 'string' === 'string'. If we set this to 'password' validator use Password::check() for comparing value against desired field

'findBy' string - Field name that will be used as condition for finding original value, default is 'id'

'field' string - Original field name

Example:

	$options = array(
		'strategy' => 'password',
		'field' => 'password'
	);

This validator will assume that value of this field, for example 'old_password' is equal to the value of 'password' field where 'id' is equal to current 'id'

Conditional in range validator

Name: 'condtionalInRange'

This validator is very similar to Lithium's 'inRange' validator, but require conditions to be true as well

Options:

'upper' integer

'lower' integer

'conditions' array - Eval comparation builder compatible conditions array

Example:

	$options = array(
		'lower' => 169, 'upper' => '206',
		'conditions' => array(
        	array('gender', '===', 'M')
        )
	);

This assume that value of this field (for example 'height') is greater than 169 and smaller than 206 just if 'gender' field exists and is equal to 'M'

Overridden validators:

Email validator

Name: 'email'

Options:

'pattern' mixed (false|regex) - If false use php filter_var() function (default in Lithium) to check value, or regex to match against.

'mx' boolean that enable validator to check if MX DNS record exists

You can achieve lithium's default behavior with options 'mx' => false, 'pattern' => false.

By default this filter check against custom regex that doesn't match all RFC 5322 valid emails, but will match against most correct emails, and doesn't check domain against MX DNS record. 'mx' => false, 'pattern' => '/^[a-z0-9][a-z0-9_.-]*@[a-z0-9.-]{3,}\.[a-z]{2,4}$/i'

Eval comparation builder:

li3_validators\extensions\util\EvalComparation::build(array $options)

Options:

conditions array - This array will be converted to eval string

values array - Associative array of values that will be used in generated condition

Best way to understand this utility method is example:

	$options = array(
		'conditions' => array(array('name', '===', 'diff_test_name')),
		'values' => array('name' => 'test_name')
	);

	$eval_one = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name'));'


	$options = array(
		'conditions' => array(
			array('name', '===', 'diff_test_name'), '||', array('name', '===', 'test_name')
		),
		'values' => array('name' => 'test_name')
	);

	$eval_two = EvalComparation::build($options); // 'return (('test_name' === 'diff_test_name') || ('test_name' === 'test_name'));'

eval($eval_one) will evaluate false

eval($eval_two) will evaluate true

You can build nested conditions as well:

	$options = array(
		'conditions' => array(
			array('name', '===', 'diff_test_name'), '&&',
			array(
				array('other_field', '===', null), '||', array('other_field', '===', 'correct')
			)
		),
		'values' => array('name' => 'test_name', 'other_field' => 'other_field_val')
	);

	$eval_tree = EvalComparation::build($options);
	// 'return (('test_name' === 'diff_test_name') && (('other_field_val' === null) || ('other_field_val' === 'correct')));'

Project status

[Build Status] (https://travis-ci.org/djordje/li3_validators) [project status] (http://stillmaintained.com/djordje/li3_validators)

djordje/li3_validators 适用场景与选型建议

djordje/li3_validators 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 67 次下载、GitHub Stars 达 2, 最近一次更新时间为 2012 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「validators」 「lithium」 「li3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 djordje/li3_validators 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 djordje/li3_validators 我们能提供哪些服务?
定制开发 / 二次开发

基于 djordje/li3_validators 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2012-11-18