承接 jrschumacher/modomo 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jrschumacher/modomo

Composer 安装命令:

composer require jrschumacher/modomo

包简介

Light, proxy centric, evented PHP ODM for MongoDB

README 文档

README

PLEASE USE https://github.com/purekid/mongodm

Modomo (mŏ-dŏ-mŏ)

Latest Stable Version Latest Unstable Version

Modomo is a lightweight, event based PHP MongoDB ODM

Designed for the benefits of ODMs (getters and setters, validation and helpers) while maintaining a quick development and low entry level. All the while proxying MongoDB Core PHP classes for direct access to the MongoDB driver; no custom routines here.

Features

  • Basic ODM features
  • Simple document classes
  • Simple collection classes
  • Validations
  • Events and callbacks
  • Direct access to MongoDB driver

Requirements

  • PHP 5.3+
  • MongoDB Driver

Installation

Manual

Extract the source files into a directory in your application library path. Either autoload or require all classes.

Composer

To add via Composer using Packagist[jrschumacher/modomo] add to your composer.json

{
    "require": {
        "jrschumacher/modomo": "0.6.*"
    }
}

Usage

Using Modomo is very simple. As a basic rule of thumb, if you use the Modomo\MongoClient() everything else will fall in place. Yet it isn't limited to that, at any point you can turn a Mongo Core Class object into a Modomo object.

Basic

Using MongoDM is as simple as declaring classes that are extensions of the base ODM class and specifying a namespace.

<?php
    namespace Collections;

    class Person {}
?>
<?php
    namespace Documents;

    class Person {}
?>
<?php
    use Modomo\MongoClient;
    use Documents\Person;

    $m = new MongoClient();
    $db = $m->test;
    $coll = $db->person;

    $bob = new Person(array(), $coll);
    $bob->name = "Bob";
    $bob->save();

    $people = $coll->find();
    $bob = $people->getNext();
    $bob->getDoc; // array('name' => 'Bob', '_id' => array('$id' => '12345....'));
?>

Configuration

Modomo supports some configuration for storing your collections and documents. This can simply be changed via Modomo\Config class which has some static variables to help you out.

Warning: Due to it's dynamic nature it will change future states.

<?php
    // Assuming MongoDB collection is "people"

    // For collections
    Modomo\Config::$collectionNS;                                   // \Collections\People.php
    Modomo\Config::$collectionNS = 'App\\Collection';               // \App\Collection\People.php
    Modomo\Config::$collectionClass = '{{mongo.coll}}Collection';   // \App\Collection\PeopleCollection.php

    // For documents
    Modomo\Config::$documentNS;                                     // \Documents\People.php
    Modomo\Config::$documentNS = 'App\\Document';                   // \App\Document\People.php
    Modomo\Config::$documentClass = '{{mongo.coll}}Document';       // \App\Document\PeopleDocument.php
?>

Namespaces

The namespace for the collections or documents may be changed via the $collecionNS and $documentNS variables. By default they resolve to \Collections and '\Documents' respectively.

Note: use a double slash \\ when implementing a sub namespace

<?php
    // To change the name space to \XYZ
    Modomo\Config::$collectionNS = 'XYZ';
    // To change the namespace to \XYZ\ABC
    Modomo\Config::$collectionNS = 'XYZ\\ABC';
?>

Class Names

The class names for collections and documents may be changed via the $collectionClass and $documentClass variables. By default they resolve to the name of the MongoDB collection in StudlyCaps (see PSR-1)

A string replace is executed to provide more flexibility with your class names. Following is a list of supported patterns:

<?php
    // To change the class name to XYZ (not a good idea)
    Modomo\Config::$collectionClass = 'XYZ';
    // To change the class name to AwesomePeopleCollection
    Modomo\Config::$collectionClass = 'Awesome{{mongo.coll}}Collection';
?>
 Pattern                Description
-------------------------------------------------------------------------
{{mongo.coll}}          Replaced with the collection name StudlyCapped

Other replacements will be added upon request and discussion

Notes:

  • mongo is reserved for MongoDB related replacements

Document

CRUD Methods

Other Methods

Validators

Events / Callbacks

A number of events exist throughout Modomo. You can hook into these events by registering your callable method with your collection.

Event Hooks

  • beforeCreate
  • beforeCreateNew
  • afterCreate
  • afterCreateNew
  • beforeSave
  • beforeSaveNew
  • afterSave
  • afterSaveNew
  • beforeValidation
  • afterValidation
  • beforeDestroy

In a new, save, destroy cycle, the validations are called in the following order:

beforeCreateNew -> afterCreateNew -> beforeValidation -> afterValidation -> beforeSaveNew -> afterSaveNew -> beforeDestroy

<?php
    namespace Collections;

    class Person {}

    $beforeSaveCallback = function() {};

    Person::registerEvent('beforeSave', $beforeSaveCallback, array('param1', 'param2'));
?>

jrschumacher/modomo 适用场景与选型建议

jrschumacher/modomo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mongodb」 「php」 「odm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 jrschumacher/modomo 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-18