定制 monii/specification-sql-adapter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

monii/specification-sql-adapter

Composer 安装命令:

composer require monii/specification-sql-adapter

包简介

Specification SQL Adapter

README 文档

README

A SQL Adapter for Monii's implementation of the Specification pattern. It provides the tools to render a Specification into a SQL query.

Latest Stable Version Total Downloads Latest Unstable Version License
Build Status

Requirements

Installation

$> composer require monii/specification-sql-adapter

Until a stable version has been released or if a development version is preferred, use:

$> composer require monii/specification-sql-adapter:@dev

Limitations

This library does not currently support joins and it may never do so. The underlying SqlQuery class is very simple and needs more testing. It works well for what we've designed it to do but it could still use a lot of work.

If you need something far more robust you could consider writing your own implementation. The Specification library is intended to support specialized rendering adapters to suite specific needs.

Example Usage

Repository

An easy example of how this renderer can be used with Monii's Specification package is by looking at an example Doctrine DBAL repository implementation. In this case, our query builder is setup to know how to map two properties to their corresponding table columns. We also assume that objectsFromRows is shared such that it can take an array of plain arrays to construct the objects that were selected.

class DbalContactRepository implements ContactRepository
{
    /**
     * @var Connection
     */
    private $connection;

    /**
     * @var SqlSpecificationQueryBuilder
     */
    private $sqlSpecificationQueryBuilder;

    /**
     * @var string
     */
    private $tableName;

    /**
     * @param string $tableName
     */
    public function __construct(
        Connection $connection,
        SqlSpecificationQueryBuilder $sqlSpecificationQueryBuilder,
        $tableName = 'terse_contact'
    ) {
        $this->connection = $connection;
        $this->sqlSpecificationQueryBuilder = $sqlSpecificationQueryBuilder;
        $this->tableName = $tableName;
    }

    /**
     * {@inheritdoc}
     */
    public function findMatching(Specification $specification)
    {
        $sqlQuery = $this->sqlSpecificationQueryBuilder->buildQuery($specification, [
            'person.firstName' => 'person_first_name',
            'person.lastName' => 'person_last_name',
        ]);

        $statement = $this->connection->prepare($sqlQuery->getSql($this->tableName));
        $statement->execute($sqlQuery->getValues());
        $results = $statement->fetchAll();

        return $this->objectsFromRows($results);
    }
}

License

MIT, see LICENSE.

Community

Want to get involved? Here are a few ways:

  • Find us in the #monii IRC channel on irc.freenode.org.
  • Mention @moniidev on Twitter.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-23