Skip to content

Commit

Permalink
add support for dynamic location of Collections and Models plus the c…
Browse files Browse the repository at this point in the history
…lass names

Use: (assuming MongoDB collection is "people")

    // For collecitons
    Modomo\Config::$collectionNS;                                   // \Collection\People.php
    Modomo\Config::$collectionNS = 'App\\Collection';               // \App\Collection\People.php
    Modomo\Config::$collectionClass = '{{mongo.coll}}Collection';   // \App\Collection\PeopleCollection.php

    // For documents
    Modomo\Config::$documentNS;                                     // \Document\People.php
    Modomo\Config::$documentNS = 'App\\Document';                   // \App\Document\People.php
    Modomo\Config::$documentClass = '{{mongo.coll}}Document';       // \App\Document\PeopleDocument.php
  • Loading branch information
jrschumacher committed Mar 6, 2013
1 parent 7aa0eaf commit 5969449
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/Modomo/Adapters/MongoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Modomo\Adapters;

use Modomo\Config;
use Modomo\Helpers\Inflector;

class MongoCollection
Expand Down Expand Up @@ -54,13 +55,23 @@ public function __construct()

$name = Inflector::getInstance()->camelize($this->_collection->getName());

$this->_collectionModel = '\\Collections\\'.Inflector::getInstance()->camelize($name);
$searchKeys = array(
'{{mongo.coll}}'
);
$searchVars = array(
Inflector::getInstance()->camelize($name)
);

$collectionClass = str_replace($searchKeys, $searchVars, Config::$collectionClass);
$documentClass = str_replace($searchKeys, $searchVars, Config::$documentClass);

$this->_collectionModel = '\\'.Config::$collectionNS.'\\'.$collectionClass;
if(!class_exists($this->_collectionModel))
{
throw new \RuntimeException($this->_collectionModel.' was not found. Must have a collection model.');
}

$this->_documentModel = '\\Documents\\'.Inflector::getInstance()->camelize($name);
$this->_documentModel = '\\'.Config::$documentNS.'\\'.$documentClass;
if(!class_exists($this->_documentModel))
{
$this->_documentModel = false;
Expand Down

0 comments on commit 5969449

Please sign in to comment.