League\FactoryMuffin\FactoryMuffin::define PHP Метод

define() публичный Метод

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.
Результат League\FactoryMuffin\Definition
    public function define($name)
    {
        if (isset($this->definitions[$name])) {
            throw new DefinitionAlreadyDefinedException($name);
        }
        if (strpos($name, ':') !== false) {
            $group = current(explode(':', $name));
            $class = str_replace($group . ':', '', $name);
            $this->definitions[$name] = clone $this->getDefinition($class);
            $this->definitions[$name]->setGroup($group);
        } else {
            $this->definitions[$name] = new Definition($name);
        }
        return $this->definitions[$name];
    }

Usage Example

Пример #1
0
 /**
  * Creates a model definition. This can be used from a helper:.
  *
  * ```php
  * $this->getModule('{{MODULE_NAME}}')->_define('User', [
  *     'name' => $faker->name,
  *     'email' => $faker->email
  * ]);
  *
  * ```
  *
  * @param $model
  * @param $fields
  *
  * @return \League\FactoryMuffin\Definition
  *
  * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException
  */
 public function _define($model, $fields)
 {
     return $this->factoryMuffin->define($model)->setDefinitions($fields);
 }