2017 © Pedro Peláez
 

library mango

A MongoDB object document mapper for PHP

image

webcodr/mango

A MongoDB object document mapper for PHP

  • Friday, December 20, 2013
  • by MadCatme
  • Repository
  • 1 Watchers
  • 4 Stars
  • 99 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 29 Versions
  • 0 % Grown

The README.md

Mango

Build Status, (*1)

PHP version, (*2)

A MongoDB object document mapper for PHP

Inspired by Mongoid for Ruby

Requirements

  • PHP 5.4
  • MongoDB driver for PHP (min. 1.2.0)
  • Composer

Setup

Add Mango to your project

~~~ bash $ php composer.phar require webcodr/mango:*, (*3)


#### Create a document class ~~~ php <?php namespace Mango\Tests\Document; use Mango\Document; use Mango\DocumentInterface; class User implements DocumentInterface { use Document; private function addFields() { $this->addField('name', ['type' => 'String']); $this->addField('email', ['type' => 'String']); $this->addField( 'created_at', [ 'type' => 'DateTime', 'index' => true, 'default' => 'now' ] ); $this->addField( 'updated_at', [ 'type' => 'DateTime', 'index' => true, 'default' => 'now' ] ); } }

You don't have to set a collection name. Mango uses the class name in lower case as collection name., (*4)

If you want to set a custom collection name, just override the method getCollectionName() in your own document classes., (*5)

There's no need to provide an id. Mango's document base class adds automatically the property '_id' with a fresh MongoId object., (*6)

Save a document

~~~ php <?php, (*7)

use Mango\Mango; use Mango\DocumentManager;, (*8)

use Document\User;, (*9)

$mango = new Mango('mongodb://devserver:27017/galactica-actual'); $dm = new DocumentManager($mango); $user = new User(); $user->name = 'William Adama'; $user->email 'william.adama@galactica.colonial-forces.gov'; $user->store();, (*10)


#### Remove a document ~~~ php $user->remove();

Querying

The methods find and where return a \Mango\Persistence\Cursor object or an object of the class \Collection\MutableMap. It depends on which method is called., (*11)

MutableMap is part of another WebCodr project called Collection. It provides several classes to replace PHP arrays and is much more fun to use. Check it out here., (*12)

Mango uses object hydration to automatically provide a result with document objects., (*13)

Find documents by id
One id

~~~ php $user = User::find('abc')->first();, (*14)


###### Multiple ids ~~~ php $user = User::find('abc', 'def', 'ghi')->first();
Find all documents in collection

~~~ php User::where()->each(function($user) { echo $user->name; });, (*15)


##### Find a document with certain field value ~~~ php $user = User::where(['name' => 'William Adama']); echo $user->count(); // result = 1 echo $user->first()->email; // result = william.adama@galactica.colonial-forces.gov

The Versions

20/12 2013

dev-master

9999999-dev https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

14/04 2013

0.6.13

0.6.13.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

14/04 2013

0.6.12

0.6.12.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

14/04 2013

0.6.11

0.6.11.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

14/04 2013

0.6.10

0.6.10.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

14/04 2013

0.6.9

0.6.9.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

13/04 2013

0.6.8

0.6.8.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

13/04 2013

0.6.7

0.6.7.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

13/04 2013

0.6.6

0.6.6.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

02/04 2013

0.6.5

0.6.5.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

02/04 2013

0.6.4

0.6.4.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.6.3

0.6.3.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.6.2

0.6.2.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.6.1

0.6.1.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.6.0

0.6.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.5.1

0.5.1.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

01/04 2013

0.5.0

0.5.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

23/03 2013

0.4.3

0.4.3.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

23/03 2013

0.4.2

0.4.2.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

19/03 2013

0.4.1

0.4.1.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

19/03 2013

0.4.0

0.4.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

18/03 2013

0.3.0

0.3.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

17/03 2013

0.2.5

0.2.5.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

17/03 2013

0.2.4

0.2.4.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

17/03 2013

0.2.3

0.2.3.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

16/03 2013

0.2.2

0.2.2.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

16/03 2013

0.2.1

0.2.1.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

16/03 2013

0.2.0

0.2.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm

16/03 2013

0.1.0

0.1.0.0 https://github.com/WebCodr/Mango

A MongoDB object document mapper for PHP

  Sources   Download

MIT

The Requires

 

mongodb mongo odm