gnugat/query-bus
最新稳定版本:v2.0.1
Composer 安装命令:
composer require gnugat/query-bus
包简介
A PHP library for Interrogatory Messages.
README 文档
README
A PHP library for Interrogatory Messages.
Interrogatory Messages are passed
to the QueryBus service which returns the result of the first QueryMatcher
that supports it.
Installation
QueryBus can be installed using Composer:
composer require "gnugat/query-bus:~2.0"
Simple conversion
Let's take the following table:
CREATE TABLE article ( id int, title VARCHAR(255), content TEXT );
If we want to execute the following query:
SELECT id, title, content FROM article WHERE id = 42;
Then we have first to create a Query, which is a simple
DTO:
<?php require __DIR__.'/vendor/autoload.php'; use Gnugat\QueryBus\QueryBus; class GetArticle { public $id; public function __construct($id) { if (null === $id) { throw new \InvalidArgumentException('Required parameter ID is missing'); } $this->id = (int) $id; } }
Note: Queries can contain simple validation, for example to check for
nullvalues.
Then we have to create a QueryMatcher:
// ... use Gnugat\QueryBus\QueryMatcher; class GetArticleMatcher implements QueryMatcher { private $connection; public function __construct($connection) { $this->connection = $connection; pg_prepare($this->connection, 'get_article', 'SELECT id, title, content FROM articles WHERE id = $1'); } public function supports($query) { return $query instanceof GetArticle; } public function match($query) { $result = pg_execute($this->connection, 'get_article', array($query->id)); return pg_fetch_array($result, NULL, PGSQL_ASSOC); } }
Next we need to register it in QueryBus:
// ... use Gnugat\QueryBus\QueryBus; $connection = pg_pconnect('dbname=blog'); $queryBus = new QueryBus(); $queryBus->add(new GetArticleMatcher($connection));
Finally we can actually execute the query:
// ... $articles = $queryBus->match(new GetArticle(42));
Further documentation
You can see the current and past versions using one of the following:
- the
git tagcommand - the releases page on Github
- the file listing the changes between versions
You can find more documentation at the following links:
gnugat/query-bus 适用场景与选型建议
gnugat/query-bus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「message」 「query」 「bus」 「interrogatory」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gnugat/query-bus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gnugat/query-bus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gnugat/query-bus 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
PHP AMQP Binding Library
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 89
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-26