lukaszmakuch/lmcondition
Composer 安装命令:
composer require lukaszmakuch/lmcondition
包简介
Condition library
README 文档
README
This library allows to build complex conditions connected with AND/OR statements with subconditions support and then check them in some context.
Usage
Getting objects
Building conditions
Let's say we want to match books that are hard to read or those ones with titles longer than 50 characters:
$wiseBookCondition = (new ConditionComposite()) ->addOR(new Difficulty(Difficulty::HARD)) ->addOR(new TitleOfMoreCharsThan(50));
Or easy books with short titles for children:
$booksForChildrenCondition = (new ConditionComposite()) ->addAND(new Difficulty(Difficulty::EASY)) ->addAND((new TitleOfMoreCharsThan(15))->negate());
Or those with really long titles:
$titleLogerThan99Condition = new TitleOfMoreCharsThan(99);
Building context
An easy to read book with a long title:
$easyBookWithLongTitle = (new Book()) ->setTitle("A really long title of some book that must be wise.") ->markAsEasy();
A hard to read book with short title:
$hardBookWithShortTitle = (new Book()) ->markAsHard() ->setTitle("How?");
An easy to read book with a short title:
$easyBookWithShortTitle = (new Book()) ->markAsEasy() ->setTitle("Cats");
Checking
Is a condition true?
Is this book wise?
$wiseBookCondition->isTrueIn($easyBookWithLongTitle); //true $wiseBookCondition->isTrueIn($hardBookWithShortTitle); //true $wiseBookCondition->isTrueIn($easyBookWithShortTitle); //false
Is it for children?
$booksForChildrenCondition->isTrueIn($easyBookWithLongTitle); //false $booksForChildrenCondition->isTrueIn($hardBookWithShortTitle); //false $booksForChildrenCondition->isTrueIn($easyBookWithShortTitle); //true
Is the title longer than 99 characters?
$titleLogerThan99Condition->isTrueIn($easyBookWithLongTitle); //false $titleLogerThan99Condition->isTrueIn($hardBookWithShortTitle); //false $titleLogerThan99Condition->isTrueIn($easyBookWithShortTitle);//false
Does intersection exist between two conditions?
A title of a wise book may be longer than 99 characters.
/* @var $intersectDetector IntersectDetector */ $intersectDetector->intersectExists( $wiseBookCondition, $titleLogerThan99Condition ); //true
But books for children have no titles that long.
/* @var $intersectDetector IntersectDetector */ $intersectDetector->intersectExists( $booksForChildrenCondition, $titleLogerThan99Condition ); //false
Are two conditions equal?
Two condition objects may be equal.
/* @var $comparator EqualityComparator */ $comparator->equal( $titleLogerThan99Condition, new TitleOfMoreCharsThan(99) ); //true
Installation
Use composer to get the latest version:
$ composer require lukaszmakuch/lmcondition
Example
The above code is taken from an example code located in ./examples. You can check there all files needed to provide this functionality.
Documentation
For more information check the best documentation - unit tests in ./tests. There's also documentation generated in ./doc.
lukaszmakuch/lmcondition 适用场景与选型建议
lukaszmakuch/lmcondition 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lukaszmakuch/lmcondition 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lukaszmakuch/lmcondition 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-22