public function fake(EntityInterface $entity, array $options = array())
    {
        if (!empty($options[self::OPTION_LOCALE])) {
            $loc = $options[self::OPTION_LOCALE];
            if (!is_string($loc) || !preg_match('#[a-z]{2,6}_[A-Z]{2,6}#', $loc)) {
                throw new BadValueException(
                    'Given option "' . self::OPTION_LOCALE
                    . '" is not a valid string. Use "languageCode_countryCode", e.g. "de_DE" or "en_UK".'
                );
            }
            $this->locale = $loc;
            $this->faker = Factory::create($this->locale);
        }

        $attributes_to_exclude = array();
        if (!empty($options[self::OPTION_EXCLUDED_FIELDS])) {
            $excluded = $options[self::OPTION_EXCLUDED_FIELDS];
            if (!is_array($excluded)) {
                throw new BadValueException(
                    'Given option "' . self::OPTION_EXCLUDED_FIELDS
                    . '" is not an array. It should be an array of attribute_names.'
                );
            }
            $attributes_to_exclude = $excluded;
        }

        $type = $entity->getType();
        foreach ($type->getAttributes() as $attribute_name => $attribute) {
            if (in_array($attribute_name, $attributes_to_exclude, true)) {
                continue;
            }

            $name = $this->getMethodNameFor($attribute);
            if (null !== $name) {
                $this->$name($entity, $attribute, $options);
            } else {
                $this->setValue($entity, $attribute, $attribute->getDefaultValue(), $options);
            }
        }

        if (array_key_exists(self::OPTION_MARK_CLEAN, $options)
            && true === $options[self::OPTION_MARK_CLEAN]
        ) {
            $entity->markClean();
        }
    }
public function fake(EntityInterface $entity, array $options = array())
    {
        if (!empty($options[self::OPTION_LOCALE])) {
            $loc = $options[self::OPTION_LOCALE];
            if (!is_string($loc) || !preg_match('#[a-z]{2,6}_[A-Z]{2,6}#', $loc)) {
                throw new BadValueException(
                    'Given option "' . self::OPTION_LOCALE
                    . '" is not a valid string. Use "languageCode_countryCode", e.g. "de_DE" or "en_UK".'
                );
            }
            $this->locale = $loc;
            $this->faker = Factory::create($this->locale);
        }

        $attributes_to_exclude = array();
        if (!empty($options[self::OPTION_EXCLUDED_FIELDS])) {
            $excluded = $options[self::OPTION_EXCLUDED_FIELDS];
            if (!is_array($excluded)) {
                throw new BadValueException(
                    'Given option "' . self::OPTION_EXCLUDED_FIELDS
                    . '" is not an array. It should be an array of attribute_names.'
                );
            }
            $attributes_to_exclude = $excluded;
        }

        $type = $entity->getType();
        foreach ($type->getAttributes() as $attribute_name => $attribute) {
            if (in_array($attribute_name, $attributes_to_exclude, true)) {
                continue;
            }

            $name = $this->getMethodNameFor($attribute);
            if (null !== $name) {
                $this->$name($entity, $attribute, $options);
            } else {
                $this->setValue($entity, $attribute, $attribute->getDefaultValue(), $options);
            }
        }

        if (array_key_exists(self::OPTION_MARK_CLEAN, $options)
            && true === $options[self::OPTION_MARK_CLEAN]
        ) {
            $entity->markClean();
        }
    }
public function fake ( EntityInterface $ entity , array $ options = array ( ) ) { if ( ! empty ( $ options [ self :: OPTION_LOCALE ] ) ) { $ loc = $ options [ self :: OPTION_LOCALE ] ; if ( ! is_string ( $ loc ) || ! preg_match ( '#[a-z]{2,6}_[A-Z]{2,6}#' , $ loc ) ) { throw new BadValueException ( 'Given option "' . self :: OPTION_LOCALE . '" is not a valid string. Use "languageCode_countryCode", e.g. "de_DE" or "en_UK".' ) ; } $ this -> locale = $ loc ; $ this -> faker = Factory :: create ( $ this -> locale ) ; } $ attributes_to_exclude = array ( ) ; if ( ! empty ( $ options [ self :: OPTION_EXCLUDED_FIELDS ] ) ) { $ excluded = $ options [ self :: OPTION_EXCLUDED_FIELDS ] ; if ( ! is_array ( $ excluded ) ) { throw new BadValueException ( 'Given option "' . self :: OPTION_EXCLUDED_FIELDS . '" is not an array. It should be an array of attribute_names.' ) ; } $ attributes_to_exclude = $ excluded ; } $ type = $ entity -> getType ( ) ; foreach ( $ type -> getAttributes ( ) as $ attribute_name => $ attribute ) { if ( in_array ( $ attribute_name , $ attributes_to_exclude , true ) ) { continue ; } $ name = $ this -> getMethodNameFor ( $ attribute ) ; if ( null !== $ name ) { $ this -> $ name ( $ entity , $ attribute , $ options ) ; } else { $ this -> setValue ( $ entity , $ attribute , $ attribute -> getDefaultValue ( ) , $ options ) ; } } if ( array_key_exists ( self :: OPTION_MARK_CLEAN , $ options ) && true === $ options [ self :: OPTION_MARK_CLEAN ] ) { $ entity -> markClean ( ) ; } }
This method fills the given entity with fake data. You may customize
the fake data generation used for each attribute by using the options array.

Supported options:
- OPTION_LOCALE: Locale for fake data (e.g. 'en_UK', defaults to 'de_DE').
- OPTION_MARK_CLEAN: Calls `$entity->markClean()` at the end to prevent
change events to occur after faking data. Default is false.
- OPTION_FIELD_VALUES: array of `attribute_name` => `value` pairs to customize
fake values per attribute of the given entity. You can
either specify a direct value or provide a closure. The
closure must return the value you want to set on that attribute.
- OPTION_EXCLUDED_FIELDS: Array of attribute_names to excluded from filling
with fake data.
- OPTION_GUESS_PROVIDER_BY_NAME: Boolean true by default. Certain attribute_names
trigger different providers (e.g. firstname or email).

@param EntityInterface $entity an instance of the entity to fill with fake data.
@param array $options array of options to customize fake data creation.

@return void

@throws \Trellis\Runtime\Entity\InvalidValueException in case of fake data being invalid for the given attribute
@throws \Trellis\Runtime\Entity\BadValueException in case of invalid locale option string
@throws \Trellis\Common\Error\RuntimeException on EmbeddedEntityListAttribute misconfiguration
This method fills the given entity with fake data . You may customize the fake data generation used for each attribute by using the options array .