From 1fba99168dcbd919f6b970217766aa23c96d73e5 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 21 Feb 2014 15:52:21 +0100 Subject: [PATCH] - Added the option to disable pluralizing. - Modified the unit tests. - Changed the order of constructors parameters. --- lib/Phactory/Mongo/Blueprint.php | 4 ++-- lib/Phactory/Mongo/Collection.php | 2 +- lib/Phactory/Mongo/Phactory.php | 12 ++++++------ tests/Phactory/Mongo/PhactoryTest.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Phactory/Mongo/Blueprint.php b/lib/Phactory/Mongo/Blueprint.php index 2303f36..32b2d86 100644 --- a/lib/Phactory/Mongo/Blueprint.php +++ b/lib/Phactory/Mongo/Blueprint.php @@ -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(); diff --git a/lib/Phactory/Mongo/Collection.php b/lib/Phactory/Mongo/Collection.php index 3800b42..4c9cd37 100644 --- a/lib/Phactory/Mongo/Collection.php +++ b/lib/Phactory/Mongo/Collection.php @@ -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); diff --git a/lib/Phactory/Mongo/Phactory.php b/lib/Phactory/Mongo/Phactory.php index 866a5ee..aa842ee 100644 --- a/lib/Phactory/Mongo/Phactory.php +++ b/lib/Phactory/Mongo/Phactory.php @@ -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; } @@ -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); } /* @@ -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); } diff --git a/tests/Phactory/Mongo/PhactoryTest.php b/tests/Phactory/Mongo/PhactoryTest.php index 9690410..59d344d 100644 --- a/tests/Phactory/Mongo/PhactoryTest.php +++ b/tests/Phactory/Mongo/PhactoryTest.php @@ -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');