Skip to content

Commit

Permalink
update licence and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jrschumacher committed Jan 18, 2013
1 parent f6cbb55 commit 0c4b12b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 27 deletions.
5 changes: 3 additions & 2 deletions LICENSE
@@ -1,3 +1,5 @@
Copyright (c) 2013 Ryan Hamilton-Schumacher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand All @@ -14,5 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

THE SOFTWARE.
82 changes: 57 additions & 25 deletions README.md
@@ -1,13 +1,15 @@
# MongoDM
# Modomo (mŏ-dŏ-mŏ)

MongoDM is a lightweight, event based PHP MongoDB ODM
Modomo is a lightweight, event based PHP MongoDB ODM

Designed for the benefits of ODMs while maintaining a low entry level and the most basic PHP classes. All the while direct access to the MongoDB driver; no wrapping here.
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
Expand All @@ -21,39 +23,57 @@ Designed for the benefits of ODMs while maintaining a low entry level and the mo

### Manual

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

### Composer

_Coming soon_

## 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
<?php // /app/documents/person.php
namespace MyApplication/Documents
<?php
namespace Collections;

class Person {}
?>
```

```php
<?php
namespace Documents;

class Person extends MongoDM {}
?>
class Person {}
?>
```

```
<?php // /app/app.php
// initialize connection and database name
MongoRecord::init(
"connection": "mongodb://localhost:21070",
"database": "myApp"
);
$bob = new 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....'));
?>
```

### Attributes
### Document

### CRUD Methods

Expand All @@ -63,25 +83,37 @@ Using MongoDM is as simple as declaring classes that are extensions of the base

### Events / Callbacks

A number of events exist throughout MongoDM. You can hook into these events by registering your callable method with the class.
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
- afterNew

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

`afterNew -> beforeValidation -> afterValidation -> beforeSave -> afterSave -> beforeDestroy`
`beforeCreateNew -> afterCreateNew -> beforeValidation -> afterValidation -> beforeSaveNew -> afterSaveNew -> beforeDestroy`

``` php
class Person extends MongoRecord {}
```php
<?php
namespace Collections;

class Person {}

$beforeSaveCallback = function() {};
$beforeSaveCallback = function() {};

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

Modomo is licensed under the MIT license.

0 comments on commit 0c4b12b

Please sign in to comment.