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

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

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

dealnews/repository

最新稳定版本:v4.1.0

Composer 安装命令:

composer require dealnews/repository

包简介

In Process/Request Data Repository

README 文档

README

This library provides a generic data repository which is capable of loading data on demand through registered callbacks and ensures the data is only loaded once while the repository object exists. This is useful if different parts of an application will need to use the same data for different purposes.

It also supports writing data through the repository.

Usage

Basic Example

<?php $repo = new \DealNews\Repository\Repository(); $dao = new My_Data_Object(); // assuming $dao has a load() method that takes // an array of ids $repo->register("my_data", [$dao, "load"]); // $data is returned as an array with keys matching the ids passed // in to the getMulti() method $data = $repo->getMulti("my_data", [1,2,3]); // Or, the get method can be used to return just on object $obj = $repo->get("my_data", 1);

Writing

<?php $repo = new \DealNews\Repository\Repository(); $dao = new My_Data_Object(); // assuming $dao has a load() method that takes // an array of ids $repo->register("my_data", [$dao, "load"], [$dao, "save"]); $foo = new Foo(); $foo->name = "example"; // save returns the data (possibly updated by the storage later) // that it is sent $foo = $repo->save("my_data", $foo);

Our Use Case

At DealNews, we use a singleton of the Repository with the needed handlers registered for the application.

Below is an example of how a Repository object could be built.

<?php namespace MyAPP; class DataRepository { public static function init() { static $repo; if (empty($repo)) { $repo = new \DealNews\Repository\Repository(); // All of these handlers are only setting read callbacks // There is no writing for this repository. $book = new Book(); $repo->register("book", [$book, "fetch"]); $author = new Author(); $repo->register("author", [$author, "fetch"]); } return $repo; } }

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固