承接 mwayi/expression 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mwayi/expression

Composer 安装命令:

composer require mwayi/expression

包简介

A multi-purpose php condition parser.

README 文档

README

status

A multi-purpose expression parser.

The expression parser allows developers to pass in a plain text statement that can be resolved to one of the following:-

  • An iterable conditions object
  • A boolean (true or false) statement
  • A MySql PDO object

Here is a sample use case:

$expression = new \Smrtr\Expression('a = b');
$conditions = $expression->execute()->toArray();
print_r($conditions);

Would resolve to:

Array
(
	[0] => Smrtr\Expression\Condition Object
		(
			[attributes:protected] => Array
				(
					[key] => a
					[value] => b
					[original_value] => b
					[operator] => =
				)

		)

)

You can now iterate the object recurrsively using a callback

$result = $expression->solve(function($condition) {

	return $this->myCustomAssertionEngine(
		$condition->key,
		$condition->operator, 
		$condition->value
	);

});

Where $this->myCustomAssertionEngine would be built to recognise keys and operators. The handlers would contain logic that would be able to return falsey and truthy results based upon the value supplied.

protected function myCustomAssertionEngine($key, $operator, $value) 
{
	$handler = 'handle' . ucfirst($key) . 'Key'; 

	if(method_exists($handler, $this)) {
		return $this->{$handler}($operator, $value);
	}

	return false;
}

The result would be a boolean value.

var_dump($result); // bool(true) or bool(false)

Definitions

Condition Elements

A condition consists of a key and value that are connected by an operator such as = that return true or false.

[key] [operator] [value]
  a        =        b

Compound conditions

A compound condition combines two or more conditions that are connected by logical operators (for example, AND) that return true or false.

a = b AND c = d

Nested conditions

A nested condition uses parentheses to group conditions that are contained in another condition and are connected using AND and OR.

a = b AND (c = d OR e = f)

Logical operators

Logical operators combines two conditions together to return a set of results

AND 
OR

Todo

  • Allow condition elements value and key to be extended.
  • Pass responsiblity of creating an expression object to an expression interface.

Tests

php vendor/bin/phpunit

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固