PHP Class League\FactoryMuffin\FactoryMuffin

Author: Graham Campbell ([email protected])
Author: Scott Robertson ([email protected])
Author: Patrick McCarren ([email protected])
Author: Zizaco ([email protected])
显示文件 Open project: zizaco/factory-muff Class Usage Examples

Protected Properties

Property Type Description
$factory League\FactoryMuffin\Generators\GeneratorFactory The generator factory instance.
$store League\FactoryMuffin\Stores\StoreInterface The store instance.

Public Methods

Method Description
__construct ( League\FactoryMuffin\Stores\StoreInterface $store = null, GeneratorFactory $factory = null ) : void Create a new factory muffin instance.
camelize ( string $str ) : string Camelize string.
create ( string $name, array $attr = [] ) : object Creates and saves a model.
define ( string $name ) : League\FactoryMuffin\Definition Define a new model definition.
deleteSaved ( ) : FactoryMuffin Delete all the saved models.
getDefinition ( string $name ) : League\FactoryMuffin\Definition Get a model definition.
getDefinitions ( ) : League\FactoryMuffin\Definition[] Get all defined model definitions.
instance ( string $name, array $attr = [] ) : object Return an instance of the model.
isPendingOrSaved ( object $model ) : boolean Is the object saved or will be saved?
loadFactories ( string | string[] $paths ) : FactoryMuffin Load the specified factories.
seed ( integer $times, string $name, array $attr = [] ) : object[] Creates and saves multiple versions of a model.

Protected Methods

Method Description
generate ( object $model, array $attr = [] ) : void Generate and set the model attributes.
make ( string $name, array $attr, boolean $save ) : object Make an instance of a model.
makeClass ( string $class, callable $maker = null ) : object Make an instance of a class.
triggerCallback ( object $model, string $name ) : boolean Trigger the callback if we have one.

Private Methods

Method Description
loadDirectory ( string $path ) : void Load all the files in a directory.

Method Details

__construct() public method

Create a new factory muffin instance.
public __construct ( League\FactoryMuffin\Stores\StoreInterface $store = null, GeneratorFactory $factory = null ) : void
$store League\FactoryMuffin\Stores\StoreInterface The store instance.
$factory League\FactoryMuffin\Generators\GeneratorFactory The generator factory instance.
return void

camelize() public static method

Transforms a string to camel case (e.g. first_name -> firstName).
public static camelize ( string $str ) : string
$str string String in underscore format.
return string

create() public method

Creates and saves a model.
public create ( string $name, array $attr = [] ) : object
$name string The model definition name.
$attr array The model attributes.
return object

define() public method

Note that this method cannot be used to modify existing definitions. Please use the getDefinition method for that.
public define ( string $name ) : League\FactoryMuffin\Definition
$name string The model definition name.
return League\FactoryMuffin\Definition

deleteSaved() public method

Delete all the saved models.
public deleteSaved ( ) : FactoryMuffin
return FactoryMuffin

generate() protected method

Generate and set the model attributes.
protected generate ( object $model, array $attr = [] ) : void
$model object The model instance.
$attr array The model attributes.
return void

getDefinition() public method

Get a model definition.
public getDefinition ( string $name ) : League\FactoryMuffin\Definition
$name string The model definition name.
return League\FactoryMuffin\Definition

getDefinitions() public method

Get all defined model definitions.
public getDefinitions ( ) : League\FactoryMuffin\Definition[]
return League\FactoryMuffin\Definition[]

instance() public method

This does not save it in the database. Use create for that.
public instance ( string $name, array $attr = [] ) : object
$name string The model definition name.
$attr array The model attributes.
return object

isPendingOrSaved() public method

Is the object saved or will be saved?
public isPendingOrSaved ( object $model ) : boolean
$model object The model instance.
return boolean

loadFactories() public method

This method expects either a single path to a directory containing php files, or an array of directory paths, and will "require" each file. These files should be where you define your model definitions.
public loadFactories ( string | string[] $paths ) : FactoryMuffin
$paths string | string[] The directory path(s) to load.
return FactoryMuffin

make() protected method

Make an instance of a model.
protected make ( string $name, array $attr, boolean $save ) : object
$name string The model definition name.
$attr array The model attributes.
$save boolean Are we saving, or just creating an instance?
return object

makeClass() protected method

Make an instance of a class.
protected makeClass ( string $class, callable $maker = null ) : object
$class string The model class name.
$maker callable The maker callable.
return object

seed() public method

Under the hood, we're calling the create method over and over.
public seed ( integer $times, string $name, array $attr = [] ) : object[]
$times integer The number of models to create.
$name string The model definition name.
$attr array The model attributes.
return object[]

triggerCallback() protected method

Trigger the callback if we have one.
protected triggerCallback ( object $model, string $name ) : boolean
$model object The model instance.
$name string The model definition name.
return boolean

Property Details

$factory protected_oe property

The generator factory instance.
protected GeneratorFactory,League\FactoryMuffin\Generators $factory
return League\FactoryMuffin\Generators\GeneratorFactory

$store protected_oe property

The store instance.
protected StoreInterface,League\FactoryMuffin\Stores $store
return League\FactoryMuffin\Stores\StoreInterface