承接 cornford/logical 相关项目开发

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

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

cornford/logical

Composer 安装命令:

composer require cornford/logical

包简介

An easy way execute logical statements over a none persisted results set in Laravel.

README 文档

README

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality

For Laravel 5.x, check version 2.6.0

For Laravel 4.x, check version 1.6.0

Think of Logical as an easy way to execute logical statements over a none persisted results set with Laravel, providing a way to reduce a results set against a logical sentence. These include:

  • Logical::setLogicalStatementInstance
  • Logical::getLogicalStatementInstance
  • Logical::setInput
  • Logical::getInput
  • Logical::setLogic
  • Logical::getLogic
  • Logical::execute
  • Logical::getResults
  • Logical::reset

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require cornford/logical.

"require": {
    "cornford/logical": "2.*"
}

Next, update Composer from the Terminal:

composer update

Once this operation completes, the next step is to add the service provider. Open app/config/app.php, and add a new item to the providers array.

'Cornford\Logical\Providers\LogicalServiceProvider',

The final step is to introduce the facade. Open app/config/app.php, and add a new item to the aliases array.

'LogicalFacade'         => 'Cornford\Logical\Facades\Logical',

That's it! You're all set to go.

Usage

It's really as simple as using the Logical class in any Controller / Model / File you see fit with:

Logical::

This will give you access to

Set Logical Statement Instance

The setLogicalStatementInstance method allows a custom Logical Statement Instance to be passed to after construction.

Logical::setLogicalStatementInstance(new LogicalStatement);
Logical::setLogicalStatementInstance(new MyLogicalStatement);

Get Logical Statement Instance

The getLogicalStatementInstance method returns the set Logical Statement Instance.

Logical::getLogicalStatementInstance();
Logical::getLogicalStatementInstance()->defineCustomStatement('test', function ($input, $expected) { return true; });

Set Input

The setInput method sets a input array set.

Logical::setInput([['name' => 'tom'], ['name' => 'jerry']]);

Get Input

The getInput method returns the set input array set.

Logical::getInput();

Set Logic

The setLogic method allows a logic statement string to be set. The available logical methods are within the Logical Statement class.

Logical::setLogic('where("name").equals("tom")');

Get Logic

The getLogic method returns the set logic statement string.

Logical::getLogic();

Execute

The execute method decodes the logic string into callable methods and then executes those methods against the input array.

Logical::execute();

Get Results

The getResults method returns the items matching the logic statement sting from the input array set.

Logical::getResults();

Reset

The reset method resets input, logic and results.

Logical::reset();

Building Logic Statement Strings

Logic statement strings are built by defining as follows:

  • A field that should be conditioned against where("field").
  • A statement method that can executed where("field").equals("tom").
  • A conditions and methods are separated with a ..
  • Multiple conditions and methods can be attached using AND or OR such as where("field").equals("tom").OR.where("field").equals("jerry").

Logic Statement String Methods

Below is a list of available logic statement string methods:

Equals

The equals method returns true if the input value equals the expected value.

equals(1)

The notEquals method returns true if the input value doesn't equals the expected value.

notEquals(1)

Is Length

The isLength method returns true if the input value equals the expected length value.

isLength(1)

The isNotLength method returns true if the input value doesn't equals the expected length value.

isNotLength(1)

Is

The is method returns true if the input value is the same type the expected value.

is("boolean")

The isNot method returns true if the input value isn't the same type the expected value.

isNot("boolean")

Contains

The contains method returns true if the input value contains the expected value.

contains("o")

The notContains method returns true if the input value doesn't contain the expected value.

notContains("o")

Contained In

The containedIn method returns true if the input value contains an item of the expected values.

containedIn(["a", "b", "c"])

The notContainedIn method returns true if the input value doesn't contain an item of the expected values.

notContainedIn(["a", "b", "c"])

In

The in method returns true if the input value is an item of the expected values.

in(["a", "b", "c"])

The notIn method returns true if the input value is not an item of the expected values.

notIn(["a", "b", "c"])

Between

The between method returns true if the input value is between the expected values.

between(1, 10)

The notBetween method returns true if the input value is not between the expected values.

notBetween(1, 10)

Null

The null method returns true if the input value is null.

null()

The notNull method returns true if the input value is not null.

notNull()

Less Than

The lessThan method returns true if the input value is less than the expected value.

lessThan(10)

The notLessThan method returns true if the input value is not less than the expected value.

notLessThan(10)

Greater Than

The greaterThan method returns true if the input value is greater than the expected value.

greaterThan(10)

The notGreaterThan method returns true if the input value is not greater than the expected value.

notGreaterThan(10)

Less Than Or Equal

The lessThanOrEqual method returns true if the input value is less than or equal to the expected value.

lessThanOrEqual(10)

The notLessThanOrEqual method returns true if the input value is not less than or not equal to the expected value.

notLessThanOrEqual(10)

Greater Than Or Equal

The greaterThanOrEqual method returns true if the input value is greater than or equal to the expected value.

greaterThanOrEqual(10)

The notGreaterThanOrEqual method returns true if the input value is not greater than or not equal to the expected value.

notGreaterThanOrEqual(10)

Starts With

The startsWith method returns true if the input value starts with the expected value.

startsWith('hello')

The notStartsWith method returns true if the input value doesn't start with the expected value.

notStartsWith('hello')

Ends With

The endsWith method returns true if the input value ends with the expected value.

endsWith('goodbye')

The notEndsWith method returns true if the input value doesn't end with the expected value.

notEndsWith('goodbye')

License

Logical is open-sourced software licensed under the MIT license

cornford/logical 适用场景与选型建议

cornford/logical 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 588 次下载、GitHub Stars 达 5, 最近一次更新时间为 2014 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-25