2017 © Pedro Peláez
 

library moa

The rightweight data mapper for mongoDB and PHP 5.3+

image

99designs/moa

The rightweight data mapper for mongoDB and PHP 5.3+

  • Thursday, November 21, 2013
  • by lwc
  • Repository
  • 31 Watchers
  • 4 Stars
  • 9,445 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 5 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Moa: the rightweight mongoDB ODM

Moa is an Object - Document Mapper, built to persist business domain objects in mongoDB., (*1)

Build Status, (*2)

Why?

  • Does the bare minimum to be useful
  • Mongo query methods are already pretty good, all that's missing is some validation and typed de/serialisation
  • Built to integrate easily into existing applications
  • Zero dependencies
  • Well tested
  • Easy to create custom types with de/serialisation behaviours and validation rules

Installation

  • Install via composer: composer require 99designs/moa
  • via github https://github.com/99designs/moa

Getting Started

In your app start up code, add something that looks like the following:, (*3)

<?php

$connection = new Mongo(); // or whatever
Moa::setup($connection->mydatabase);

Optionally, a callback can be provided to lazily connect on demand:, (*4)

<?php

Moa::setup(function() {
    $connection = new Mongo();
    return $connection->someDb; 
});

Also, extra databases can be configured:, (*5)

<?php

$connection = new Mongo(); // or whatever
Moa::setup($connection->mydatabase);
Moa::instance()->addDatabase('anotherDb', $connection->differentDb); // also takes a callback

Defining Models

Model classes can be defined like so:, (*6)

<?php

class TestDocument extends Moa\DomainObject
{
    public function properties()
    {
        return array(
            'myInt' => new Moa\Types\IntegerField(array('required' => true)),            
            'myString' => new Moa\Types\StringField(),
            'myArray' => new Moa\Types\ArrayField(),
            'myOwnSelf' => new Moa\Types\EmbeddedDocumentField(array('type'=>'TestDocument')),
        );
    }
}
  • For a full list of field types and their behaviours, see the Moa\Types namespace
  • Indexes may also be defined (override DomainObject::indexes())
  • Domain objects can also specify the database they want to persist to (override DomainObject::getDatabaseName())

Querying

The query syntax is the same as the default PHP mongo driver, but accessed statically from the domain object you hope to query, eg, (*7)

<?php

$docs = TestDocument::find(array('myString'=>'value'));

// it is also possible to use cursor methods
$docs = TestDocument::find(array('myString'=>'value'))->skip(20)->limit(10);

// findOne also works
$doc = TestDocument::findOne(array('myString'=>'value')); // this could except

// Documents may be saved via a call to save()
$doc->myInt = 123;
$doc->save();

// Documents can be deleted
TestDocument::remove(array('myString' => 'value')); // Deletes all documents with a field 'myString' with value of 'value'

The Versions

21/11 2013

dev-master

9999999-dev

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

21/11 2013

1.0.5

1.0.5.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

21/11 2013

1.0.5.x-dev

1.0.5.9999999-dev

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

08/11 2013

dev-clone-domainobject

dev-clone-domainobject

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

08/11 2013

dev-to-array-method

dev-to-array-method

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

17/07 2013

1.0.4

1.0.4.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

17/07 2013

dev-add-new-property

dev-add-new-property

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

11/04 2013

1.0.3

1.0.3.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

26/03 2013

1.0.2

1.0.2.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

25/02 2013

1.0.1

1.0.1.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

23/01 2013

1.0.0

1.0.0.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

12/12 2012

1.0.0-b2

1.0.0.0-beta2

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

11/12 2012

1.0.0-b

1.0.0.0-beta

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

18/10 2012

1.0.0-a

1.0.0.0-alpha

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

17/10 2012

0.0.9

0.0.9.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper

26/09 2012

0.0.1

0.0.1.0

The rightweight data mapper for mongoDB and PHP 5.3+

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Luke Cawood

orm mongodb 99designs mongo activerecord odm datamapper