mongator/behaviors

Bahaviors for Mongator, the Simple, powerful and ultrafast Object Document Mapper (ODM) for PHP and MongoDB

v1.5.0 2014-05-22 15:59 UTC

This package is not auto-updated.

Last update: 2024-11-18 12:44:44 UTC


README

These are the official behaviors of Mongator.

  • Timestampable: Saves the creation and/or update date in the documents.
  • Ipable: Saves the IP from where documents are created and/or saved.
  • Sluggable: Saves the slug of a field in the documents.
  • Archivable: Saves a document copy from one collection to another.
  • Tokenizable: Generates a token on creation.
  • Hasable: Generates a hash for given fields/rels/embs from the given document, on update and/or creation.
  • AutoIncrementable: Auto incrementable field like AUTO_INCREMENT in MySQL
  • Identifiable: Automatically saves an identifier in the document.
  • Stringifiable: Add to the document the magic method __toString, so any document can be converted to string.
  • EmbeddedUniquable: Ensure unique embeddeds document in a embeddedsMany relation.

Requirements

  • PHP 5.3.x;
  • mongator/mongator

Installation

The recommended way of installing Mongator Behaviors is through composer. You can see package information on Packagist.

{
    "require": {
        "mongator/behaviors": "1.4.*"
    }
}

Examples

On your document definition just add a new array named behaviors, just like this:

'Model\MyCollecion' => array(
    'fields' => array(
        'title' => 'string',
    ),
    'behaviors' => array(
        array('class' => 'Mongator\Behavior\Tokenizable'),
        array('class' => 'Mongator\Behavior\Archivable'),
    ),
),

Tests

Tests are in the tests folder. To run them, you need PHPUnit. Example:

$ phpunit --configuration phpunit.xml.dist

License

MIT, see LICENSE