colinmollenhour/mongodb-php-odm 问题修复 & 功能扩展

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

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

colinmollenhour/mongodb-php-odm

最新稳定版本:1.0

Composer 安装命令:

composer require colinmollenhour/mongodb-php-odm

包简介

MongoDb PHP ODM is a simple object wrapper for the Mongo PHP driver classes which makes using Mongo in your PHP application more like an ORM. It is designed for use with Kohana 3 but will integrate equally well with any PHP application.

README 文档

README

(for lack of a better title)

Overview

MongoDb PHP ODM is a simple object wrapper for the Mongo PHP driver classes which makes using Mongo in your PHP application more like ORM, but without the suck. It is designed for use with Kohana 3 but will also integrate easily with any PHP application with almost no additional effort.

Design Principles

  • Don’t become overly complex. There are some features that could be implemented, but if they are not it is because they would increase the complexity too much, sacrificing elegance and usability.
  • Keep Mongo schema-less. I like schema-less. Requiring schema’s in your model definitions is not schema-less. This library let’s you be schema-less.
  • Follow Mongo driver convention. In many ways, using this library will be pretty similar to using the official driver.
  • Do not add unnecessary overhead. Sure, it is not as fast as using the driver directly, but I’m quite sure you won’t notice the difference.
  • Don’t Repeat Yourself. Very little code will be repeated while using this library.
  • Reduce the number of database requests/updates. Prevent redundant requests and multiple updates to the same document.
  • Choose your favorite design pattern. This library now supports using Mongo_Collection directly as a convenience wrapper, or choose between two ActiveRecord like patterns that resemble either the Table Data Gateway pattern or the Row Data Gateway pattern

Basic Idea

The basic idea is to boil the usage of the Mongo PHP library down to three classes:

  • Mongo_Database
  • Mongo_Collection
  • Mongo_Document

Mongo_Database

This class encapsulates the functionality of the Mongo connection and the MongoDb class into one since in most cases an application will interface with only one database. Interfacing with more than one database is still possible, but they will not share a single connection. Features afforded by this class:

  • Configurations are described with names such as ‘default’. Kohana loads this configuration in the typical Kohana fashion, other frameworks can simply specify it as an argument to Mongo_Database::instance('default',array(...)) to set the default configuration.
  • Database names are never used in your code other than when supplying the configuration the first time. Easily deploy the same application on different database names.
  • When used with Kohana, all important database operations can easily have profiling enabled. Profiling output mimics Mongo shell syntax for easy copy/paste debugging in the shell.
  • Lazy database connections.

Mongo_Collection

This class accomplishes the following:

  • Allows query results to be accessed as an iterator of models rather than arrays when used in conjunction with Mongo_Document.
  • Combines the functionality of MongoCollection, MongoGridFS and MongoCursor into one base class.
  • Allows query building by aggregating query parameters, cursor options, requested fields, etc..
  • When used with Kohana, all database requests can easily be profiled.
  • Debugging can be made easier by using the __toString() method to get a string representing the full query, again mimicking the syntax of the MongoDb shell.

Mongo_Document

This class objectifies a document (or row) in the database. Extend the base class for each of your data models, typically one per collection and enjoy some very simple CRUD operations with niceties like:

  • before_* and after_* methods for you to implement for transparently added functionality such as updating timestamps, validation, etc..
  • helpers for all of the Mongo update operations which are aggregated until the next save()
  • aliased field names so you can use short field names in the database and long names in the code. Take it or leave it.
  • auto-loading of referenced documents. E.g. echo $post->user->email
  • lazy-loading of documents and referenced documents. E.g. the above is two requests, this would only be one: echo $post->user->id

See the wiki for more detail.

More Information

@copyright Copyright © 2013 Colin Mollenhour (http://colin.mollenhour.com) This project is licensed under the “New BSD” license (see LICENSE.txt).

Contributors

  • @panrafal
  • @sergeyklay
  • @Xobb
  • @sebicas
  • @kanema
  • @semalead
  • @bbedwell
  • @kohenkatz

colinmollenhour/mongodb-php-odm 适用场景与选型建议

colinmollenhour/mongodb-php-odm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.09k 次下载、GitHub Stars 达 209, 最近一次更新时间为 2014 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 colinmollenhour/mongodb-php-odm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 colinmollenhour/mongodb-php-odm 我们能提供哪些服务?
定制开发 / 二次开发

基于 colinmollenhour/mongodb-php-odm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 209
  • Watchers: 26
  • Forks: 50
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-07-16