Skip to content
manchuck edited this page Dec 14, 2013 · 2 revisions

RFC Status: Open for Comments

RFC Author(s): Chuck "MANCHUCK" Reeves

Abstract

ZfcMongo will have many helpful features for working with Mongo. This module will contain hydrator strategies, validators and factories, and paginiator adapters. The module will add some native Mongo functionality to ZF2.

Proposed Features

  • Factories for creating collections and gridfs through the service locator
  • Hydrator Strategies for all the Mongo types: MongoId, MongoDate etc
  • A Validator for duplicate entires
  • Paginator adapter

Expected Dependencies

None

Hard Dependencies

None

Soft Dependencies

None

Existing / Similar Modules

PhlyMongo

Example(s)

Use case #1 -- Id Hydrator strategy

Namespace ZfcMongo;

use Zend\Stdlib\Hydrator\Strategy\StrategyInterface;

class MongoIdStrategy implements StrategyInterface
{
    protected $extractAsString = true;

    public function __construct($extractAsString = true)
    {
        $this->extractAsString = $extractAsString;
    }

    public function hydrate($value)
    {
        return new \MongoId($value);
    }

    public function extract($value)
    {
        return $this->extractAsString ? (string) $value : $value;
    }
}

Use case #2 -- No Record Exists

$userId = new \MongoId();
$validator = new ZfcMongo\Validator\NoRecordExists(
    array(
        'collection' => 'users',
        'field' => 'email',
        'exclude' => array(
            'field' => '_id',
            'value' => $userId
        )
    )
);

Votes

Comments

Click here to view comments and discussion for this RFC.