PHPackages                             jrschumacher/modomo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jrschumacher/modomo

ActiveLibrary[Database &amp; ORM](/categories/database)

jrschumacher/modomo
===================

Light, proxy centric, evented PHP ODM for MongoDB

v0.6.0(13y ago)140MITPHPPHP &gt;=5.3.2

Since Jan 18Pushed 12y ago1 watchersCompare

[ Source](https://github.com/jrschumacher/modomo)[ Packagist](https://packagist.org/packages/jrschumacher/modomo)[ Docs](https://github.com/jrschumacher/modomo)[ RSS](/packages/jrschumacher-modomo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

THIS REPO IS NO LONGER MAINTAINED.
==================================

[](#this-repo-is-no-longer-maintained)

PLEASE USE
-----------------------------------------------

[](#please-use-httpsgithubcompurekidmongodm)

Modomo (mŏ-dŏ-mŏ)
=================

[](#modomo-mŏ-dŏ-mŏ)

[![Latest Stable Version](https://camo.githubusercontent.com/6af1370978bc2a60a67bd59de3e3c33c76cd45a2866151ff71a97eaa994b1cf1/68747470733a2f2f706f7365722e707567782e6f72672f6a72736368756d61636865722f6d6f646f6d6f2f76657273696f6e2e706e67)](https://packagist.org/packages/jrschumacher/modomo)[![Latest Unstable Version](https://camo.githubusercontent.com/12ab460823118a2fc8abdba2c965dbe7df4a4e3ffdf7ec277d0d393c87c624b6/68747470733a2f2f706f7365722e707567782e6f72672f6a72736368756d61636865722f6d6f646f6d6f2f762f756e737461626c652e706e67)](https://packagist.org/packages/jrschumacher/modomo)

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
--------

[](#features)

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

Requirements
------------

[](#requirements)

- PHP 5.3+
- MongoDB Driver

Installation
------------

[](#installation)

### Manual

[](#manual)

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

### Composer

[](#composer)

To add via Composer using Packagist\[[jrschumacher/modomo](https://packagist.org/packages/jrschumacher/modomo)\] add to your composer.json

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

Usage
-----

[](#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

[](#basic)

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

```

```

```

```

```

```

### Configuration

[](#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.*

```

```

#### Namespaces

[](#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*

```

```

#### Class Names

[](#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](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md))

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

```

```

```
 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

[](#document)

### CRUD Methods

[](#crud-methods)

### Other Methods

[](#other-methods)

### Validators

[](#validators)

### Events / Callbacks

[](#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

[](#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`

```
