clean/repository 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

clean/repository

最新稳定版本:2.0.4

Composer 安装命令:

composer require clean/repository

包简介

README 文档

README

Build Status Code Climate Test Coverage Issue Count Latest Stable Version Total Downloads License

Use a repository to separate the logic that retrieves the data and maps it to the entity model from the business logic that acts on the model. The business logic should be agnostic to the type of data that comprises the data source layer. For example, the data source layer can be a database or a Web service.

Objectives

  • You access the data source from many locations and want to apply centrally managed, consistent access rules and logic.
  • You want to implement and centralize a caching strategy for the data source.
  • You want to improve the code's maintainability and readability by separating business logic from data or service access logic.

Installation

via Composer:

"require": {
  "clean/repository": "dev-master"
}

Idea and Implementation

Repository is and object that holds multiply criterias. Those criteria can represent query to database or GET request parameters or anything else that require creating some kind of request based on various parameters. The idea is to hide concrate implementation of generating queries or requests behind semantic layer e.g.:

/*
   get 
   4 'toyota' cars,
   not older than 10 year,
   only with diesel engine,
   with information about last 2 owners,
   include pictures of car
*/
$carRepository
    ->limit(4)
    ->filterByMark('toyota')
    ->notOlderThan(10)
    ->onlyDiesel()
    ->includeOwners([
        'getLatest' => 2,
    ])
    ->includePictures()
    ->assemble();

There are few rules worth to follow:

  • when you need to reduce result use filter..., or only... method
  • when you need to sort result use sortBy... method
  • when you need to extend result use with... method
  • when you need to include related entity use include... method
  • you can also define your own rules valid for your project like notOlderThan

Working example:

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-20