PHP Class League\FactoryMuffin\FactoryMuffin

Author: Graham Campbell ([email protected])
Author: Scott Robertson ([email protected])
Author: Patrick McCarren ([email protected])
Author: Zizaco ([email protected])
Afficher le fichier Open project: zizaco/factory-muff Class Usage Examples

Protected Properties

Свойство Type Description
$factory League\FactoryMuffin\Generators\GeneratorFactory The generator factory instance.
$store League\FactoryMuffin\Stores\StoreInterface The store instance.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

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

Method Details

__construct() public méthode

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.
Résultat void

camelize() public static méthode

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

create() public méthode

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

define() public méthode

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.
Résultat League\FactoryMuffin\Definition

deleteSaved() public méthode

Delete all the saved models.
public deleteSaved ( ) : FactoryMuffin
Résultat FactoryMuffin

generate() protected méthode

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

getDefinition() public méthode

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

getDefinitions() public méthode

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

instance() public méthode

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.
Résultat object

isPendingOrSaved() public méthode

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

loadFactories() public méthode

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.
Résultat FactoryMuffin

make() protected méthode

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?
Résultat object

makeClass() protected méthode

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.
Résultat object

seed() public méthode

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.
Résultat object[]

triggerCallback() protected méthode

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.
Résultat boolean

Property Details

$factory protected_oe property

The generator factory instance.
protected GeneratorFactory,League\FactoryMuffin\Generators $factory
Résultat League\FactoryMuffin\Generators\GeneratorFactory

$store protected_oe property

The store instance.
protected StoreInterface,League\FactoryMuffin\Stores $store
Résultat League\FactoryMuffin\Stores\StoreInterface