2017 © Pedro Peláez
 

library modomo

Light, proxy centric, evented PHP ODM for MongoDB

image

jrschumacher/modomo

Light, proxy centric, evented PHP ODM for MongoDB

  • Monday, February 24, 2014
  • by jrschumacher
  • Repository
  • 1 Watchers
  • 1 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

THIS REPO IS NO LONGER MAINTAINED.

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

Modomo (mŏ-dŏ-mŏ)

Latest Stable Version Latest Unstable Version, (*1)

Modomo is a lightweight, event based PHP MongoDB ODM, (*2)

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., (*3)

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., (*4)

Composer

To add via Composer using Packagist[jrschumacher/modomo] add to your composer.json, (*5)

{
    "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., (*6)

Basic

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



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., (*8)

Warning: Due to it's dynamic nature it will change future states., (*9)


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., (*10)

Note: use a double slash \\ when implementing a sub namespace, (*11)

<?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), (*12)

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

<?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, (*14)

Notes:, (*15)

  • 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., (*16)

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:, (*17)

beforeCreateNew -> afterCreateNew -> beforeValidation -> afterValidation -> beforeSaveNew -> afterSaveNew -> beforeDestroy, (*18)


The Versions

24/02 2014

dev-master

9999999-dev https://github.com/jrschumacher/modomo

Light, proxy centric, evented PHP ODM for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

mongodb php odm

18/01 2013

v0.5.0

0.5.0.0 https://github.com/jrschumacher/modomo

Light, proxy centric, evented PHP ODM for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

mongodb php odm

18/01 2013

v0.6.0

0.6.0.0 https://github.com/jrschumacher/modomo

Light, proxy centric, evented PHP ODM for MongoDB

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

mongodb php odm