PHP Class Phactory\Sql\Phactory

Exibir arquivo Open project: chriskite/phactory Class Usage Examples

Protected Properties

Property Type Description
$_blueprints * Array of table name => Blueprint
$_pdo * PDO database connection

Public Methods

Method Description
__construct ( PDO $pdo ) Constructs a Phactory object for testing SQL databases
build ( $table, $overrides = [] ) * Build a Row object, optionally overriding some or all of the default values.
buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Build a Row object, optionally overriding some or all of the default values.
create ( $table, $overrides = [] ) * Instantiate a row in the specified table, optionally overriding some or all of the default values.
createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] ) * Instantiate a row in the specified table, optionally overriding some or all of the default values.
define ( $blueprint_name, $defaults = [], $associations = [] ) * Define the default values to use when constructing a row in the specified table.
defineBlueprint ( $blueprint_name, $defaults = [], $associations = [] ) * alias for define per @jblotus pull request eventually we should just rename the original function
get ( $table_name, $byColumns ) * Get a row from the database as a Row.
getAll ( $table_name, $byColumns )
getConnection ( ) * Get the PDO database connection object.
manyToMany ( $to_table, $join_table, $from_column = null, $from_join_column = null, $to_join_column = null, $to_column = null )
manyToOne ( $to_table, $from_column = null, $to_column = null ) * Create a many-to-one association object for use in define().
oneToOne ( $to_table, $from_column, $to_column = null ) * Create a one-to-one association object for use in define().
recall ( ) * Delete created Row objects from the database.
reset ( ) * Delete created objects from the database, clear defined blueprints, and clear stored inflection exceptions.
setConnection ( $pdo ) * Set the PDO object to use for database connection.
setInflection ( $singular, $plural ) * Specify an exception for table name inflection.

Method Details

__construct() public method

Constructs a Phactory object for testing SQL databases
public __construct ( PDO $pdo )
$pdo PDO A PDO database connection to test with

build() public method

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

buildWithAssociations() public method

The row is not saved to the database.
public buildWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [table name] => [Row]
$overrides key => value pairs of column => value

create() public method

The row is saved to the database, and returned as a Row.
public create ( $table, $overrides = [] )
$table name of the table
$overrides key => value pairs of column => value

createWithAssociations() public method

The row is saved to the database, and returned as a Row.
public createWithAssociations ( $blueprint_name, $associations = [], $overrides = [] )
$blueprint_name name of the blueprint to use
$associations [table name] => [Row]
$overrides key => value pairs of column => value

define() public method

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

defineBlueprint() public method

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

get() public method

$byColumn is like array('id' => 123).
public get ( $table_name, $byColumns )
$table_name name of the table

getAll() public method

public getAll ( $table_name, $byColumns )

getConnection() public method

* Get the PDO database connection object.
public getConnection ( )

manyToMany() public method

public manyToMany ( $to_table, $join_table, $from_column = null, $from_join_column = null, $to_join_column = null, $to_column = null )

manyToOne() public method

* Create a many-to-one association object for use in define().
public manyToOne ( $to_table, $from_column = null, $to_column = null )
$to_table the table to associate with
$from_column the fk column on the left table
$to_column the pk column of the right table, or null to autodetect

oneToOne() public method

* Create a one-to-one association object for use in define().
public oneToOne ( $to_table, $from_column, $to_column = null )
$to_table the table to associate with
$from_column the fk column on the left table
$to_column the pk column of the right table, or null to autodetect

recall() public method

* Delete created Row objects from the database.
public recall ( )

reset() public method

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

setConnection() public method

* Set the PDO object to use for database connection.
public setConnection ( $pdo )
$pdo PDO object

setInflection() public method

For example, if your table 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 table name => Blueprint
protected $_blueprints

$_pdo protected_oe property

* PDO database connection
protected $_pdo