Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Phactory/Mongo/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Blueprint {
protected $_defaults;
protected $_sequence;

public function __construct($name, $defaults, $associations = array(), Phactory $phactory) {
$this->_collection = new Collection($name, true, $phactory);
public function __construct($name, $defaults, Phactory $phactory, $associations = array(), $pluralize = true) {
$this->_collection = new Collection($name, $phactory, $pluralize);
$this->_defaults = $defaults;
$this->_sequence = new Sequence();

Expand Down
2 changes: 1 addition & 1 deletion lib/Phactory/Mongo/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Collection {
protected $_name;
protected $_collection;

public function __construct($singular_name, $pluralize = true, Phactory $phactory) {
public function __construct($singular_name, Phactory $phactory, $pluralize = true) {
$this->_singular = $singular_name;
if($pluralize) {
$this->_name = Inflector::pluralize($singular_name);
Expand Down
12 changes: 6 additions & 6 deletions lib/Phactory/Mongo/Phactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function getDb() {
* @param array $defaults key => value pairs of field => value, or a phactory_blueprint
* @param array $associations array of phactory_associations
*/
public function define($blueprint_name, $defaults, $associations = array()) {
public function define($blueprint_name, $defaults, $associations = array(), $pluralize = true) {
if($defaults instanceof Blueprint) {
$blueprint = $defaults;
} else {
$blueprint = new Blueprint($blueprint_name, $defaults, $associations, $this);
$blueprint = new Blueprint($blueprint_name, $defaults, $this, $associations, $pluralize);
}
$this->_blueprints[$blueprint_name] = $blueprint;
}
Expand All @@ -61,8 +61,8 @@ public function define($blueprint_name, $defaults, $associations = array()) {
* alias for define per @jblotus pull request
* eventually we should just rename the original function
*/
public function defineBlueprint($blueprint_name, $defaults, $associations = array()) {
$this->define($blueprint_name, $defaults, $associations);
public function defineBlueprint($blueprint_name, $defaults, $associations = array(), $pluralize = true) {
$this->define($blueprint_name, $defaults, $associations, $pluralize);
}

/*
Expand Down Expand Up @@ -134,12 +134,12 @@ public function buildWithAssociations($blueprint_name, $associations = array(),
* @param array $query a MongoDB query
* @return array
*/
public function get($collection_name, $query) {
public function get($collection_name, $query) {
if(!is_array($query)) {
throw new \Exception("\$query must be an associative array of 'field => value' pairs");
}

$collection = new Collection($collection_name, true, $this);
$collection = new Collection($collection_name, $this);

return $collection->findOne($query);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Phactory/Mongo/PhactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testDefine()

public function testDefineWithBlueprint()
{
$blueprint = new Blueprint('user', array('name' => 'testuser'), array(), $this->phactory);
$blueprint = new Blueprint('user', array('name' => 'testuser'), $this->phactory);
$this->phactory->define('user', $blueprint);

$user = $this->phactory->create('user');
Expand Down