PHP Class Phactory\Mongo\Phactory

Afficher le fichier Open project: chriskite/phactory Class Usage Examples

Protected Properties

Свойство Type Description
$_blueprints * Array of collection name => Blueprint
$_db * Mongo database object

Méthodes publiques

Méthode Description
__construct ( MongoDB $mongo ) Constructs a Phactory object for testing MongoDB databases
build ( $blueprint_name, $overrides = [] ) * Build a document as an array, optionally overriding some or all of the default values.
buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Build a document as an array, optionally overriding some or all of the default values.
create ( $blueprint_name, $overrides = [] ) * Instantiate a document in the specified collection, optionally overriding some or all of the default values.
createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Instantiate a document in the specified collection, optionally overriding some or all of the default values.
define ( $blueprint_name, $defaults, $associations = [] ) * Define the default values to use when constructing a document in the specified collection.
defineBlueprint ( $blueprint_name, $defaults, $associations = [] ) * alias for define per @jblotus pull request eventually we should just rename the original function
embedsMany ( $collection_name ) * Create an embeds-many association object for use in define().
embedsOne ( $collection_name ) * Create an embeds-one association object for use in define().
get ( $collection_name, $query ) * Get a document from the database as an array.
getAll ( $collection_name, $query = [] ) * Get results from the database as a cursor.
getDb ( ) * Get the Mongo database object.
recall ( ) * Delete created documents from the database.
reset ( ) * Delete created objects from the database, clear defined blueprints, and clear stored inflection exceptions.
setDb ( MongoDB $db ) * Set the Mongo object to use for database connection.
setInflection ( $singular, $plural ) * Specify an exception for collection name inflection.

Method Details

__construct() public méthode

Constructs a Phactory object for testing MongoDB databases
public __construct ( MongoDB $mongo )
$mongo MongoDB A MongoDB database connection to test with

build() public méthode

The document is not saved to the database.
public build ( $blueprint_name, $overrides = [] )
$blueprint_name name of the blueprint
$overrides key => value pairs of column => value

buildWithAssociations() public méthode

The document is not saved to the database.
public buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [collection name] => [array]
$overrides key => value pairs of field => value

create() public méthode

The document is saved to the database and returned as an array.
public create ( $blueprint_name, $overrides = [] )
$blueprint_name name of the blueprint
$overrides key => value pairs of column => value

createWithAssociations() public méthode

The document is saved to the database, and returned as an array.
public createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [collection name] => [array]
$overrides key => value pairs of field => value

define() public méthode

* Define the default values to use when constructing a document in the specified collection.
public define ( $blueprint_name, $defaults, $associations = [] )
$blueprint_name singular name of the collection in the database
$defaults key => value pairs of field => value, or a phactory_blueprint
$associations array of phactory_associations

defineBlueprint() public méthode

* alias for define per @jblotus pull request eventually we should just rename the original function
public defineBlueprint ( $blueprint_name, $defaults, $associations = [] )

embedsMany() public méthode

* Create an embeds-many association object for use in define().
public embedsMany ( $collection_name )
$collection_name the singular name of the collection to associate with

embedsOne() public méthode

* Create an embeds-one association object for use in define().
public embedsOne ( $collection_name )
$collection_name the singular name of the collection to associate with

get() public méthode

* Get a document from the database as an array.
public get ( $collection_name, $query )
$collection_name name of the collection
$query a MongoDB query

getAll() public méthode

* Get results from the database as a cursor.
public getAll ( $collection_name, $query = [] )
$collection_name name of the collection
$query a MongoDB query

getDb() public méthode

* Get the Mongo database object.
public getDb ( )

recall() public méthode

* Delete created documents from the database.
public recall ( )

reset() public méthode

* Delete created objects from the database, clear defined blueprints, and clear stored inflection exceptions.
public reset ( )

setDb() public méthode

* Set the Mongo object to use for database connection.
public setDb ( MongoDB $db )
$db MongoDB Mongo object

setInflection() public méthode

For example, if your collection of fish is called 'fishes', call setInflection('fish', 'fishes')
public setInflection ( $singular, $plural )
$singular singular form of the word.
$plural plural form of the word.

Property Details

$_blueprints protected_oe property

* Array of collection name => Blueprint
protected $_blueprints

$_db protected_oe property

* Mongo database object
protected $_db