telkins/laravel-inquiry
Composer 安装命令:
composer require telkins/laravel-inquiry
包简介
A (somewhat opinionated) Laravel package to help make asking questions and getting answers a little easier and more uniform.
README 文档
README
From time to time you may need to make inquiries of your application or different parts of your code. You may need to know whether or not something was done or you may need to build a collection of key value pairs. Sometimes this iss provided easily via model attributes or database queries. Sometimes, however, getting this information isn't quite as tidy as you might like it.
The goal of this package is to provide a (somewhat opinionated) way to make inquiries. You can create Inquiry classes. When you want to make a specific inquiry, then you "ask" that class: $myInquiry = MyInquiry::ask();. You get back a "details" object, which you define, that allows you to provide the details of your inquiry. Then, you ask for the answer. Here's a simple example:
$isAllowed = CanChildPlayPS4::ask() ->child($junior) ->onDateTime(now()) ->answer();
Installation
You can install the package via composer:
composer require telkins/laravel-inquiry
Usage
For now, one must manually create Inquiry and Details classes.
Create an Inquiry
To create an inquiry class, simply extend Inquiry like so:
use Telkins\LaravelInquiry\Inquiry; use Telkins\LaravelInquiry\Contracts\Details; class CanChildPlayPS4 extends Inquiry { public function provideAnswer(Details $details) { if (! $details->child->areChoresDone()) { return false; } if ($details->child->isGrounded()) { return false; } if (! $details->child->isDoneWithHomework()) { return false; } return $this->isItAGoodTimeToPlay($details->dateTime); } // supporting methods, if needed... }
Create Inquiry Details
To create an inquiry detail classs, simply extend Details like so:
use App\Child; use Carbon\CarbonImmutable; use Telkins\LaravelInquiry\Details; class CanChildPlayPS4Details extends Details { public $child; public $dateTime; public function child(Child $child): self { $this->child = $child; return $this; } public function onDateTime(CarbonImmutable $dateTime): self { $this->dateTime = $dateTime; return $this; } }
"Ask" Your Question, Get an Answer
Once you have built your inquiry and inquiry details classes, then you can begin to use them. There are three main steps to asking your question and getting an answer:
- Call the static
ask()method on yourInquiryclass. This returns the inquiry's details object. - Using the details object, provide the details of the inquiry.
- Finally, request the answer by calling the
answer()method on the details object.
Here is an example of asking and getting an answer all at once:
$isAllowed = CanChildPlayPS4::ask() ->child($junior) ->onDateTime(now()) ->answer();
Here is an example of using the details object to provide different details to get different answers for different scenarios:
$inquiryDetails = CanChildPlayPS4::ask(); $canGregPlay = $inquiryDetails ->child($greg) ->onDateTime(now()) ->answer(); $canPeterPlay = $inquiryDetails ->child($peter) ->answer();
Conventions
By default, each Inquiry class will look for a "details" class that has the same FQCN with Details appended. So, for our example CanChildPlayPS4 class, it will look for CanChildPlayPS4Details.
To override this behavior, you can specify the "details" class name in your Inquiry class like so:
use Telkins\LaravelInquiry\Inquiry; use Telkins\LaravelInquiry\Contracts\Details; use My\Custom\Namespace\UnconventionalNameDetails; class CanChildPlayPS4 extends Inquiry { protected static $detailsClass = UnconventionalNameDetails::class; // override default "details" class public function provideAnswer(Details $details) { // ... } // ... }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please use the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
telkins/laravel-inquiry 适用场景与选型建议
telkins/laravel-inquiry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「query」 「laravel」 「ask」 「question」 「answer」 「inquiry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 telkins/laravel-inquiry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 telkins/laravel-inquiry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 telkins/laravel-inquiry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library containing a PHP implementation of the Ask query language
Query filtering in your frontend
Anax Database Active Record module for model classes.
Database/ORM-agnostic query construction helper
VV database abstraction layer with query builder and DB structure models
Alfabank REST API integration
统计信息
- 总下载量: 74
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-25