Helper/EntityHelper.php
public function createEntity($className, array $fields = [])
    {
        $metadata = $this->getEntityMetadata($className);

        if (is_null($metadata)) {
            return null;
        }

        $reflection = $metadata->getReflectionClass();

        try {
            $entity = $reflection->newInstance();
        } catch (\Exception $e) {
            $entity = $reflection->newInstanceWithoutConstructor();
        }

        foreach ($fields as $fieldName => $fieldValue) {
            if (self::IDENTITY === $fieldName) {
                $property = $reflection->getProperty($this->getEntityIdName($className));
            } else {
                $property = $reflection->getProperty($fieldName);
            }

            try {
                $property->setValue($entity, $fieldValue);
            } catch (\Exception $e) {
                $property->setAccessible(true);
                $property->setValue($entity, $fieldValue);
                $property->setAccessible(false);
            }
        }

        return $entity;
    }
public function createEntity($className, array $fields = [])
    {
        $metadata = $this->getEntityMetadata($className);

        if (is_null($metadata)) {
            return null;
        }

        $reflection = $metadata->getReflectionClass();

        try {
            $entity = $reflection->newInstance();
        } catch (\Exception $e) {
            $entity = $reflection->newInstanceWithoutConstructor();
        }

        foreach ($fields as $fieldName => $fieldValue) {
            if (self::IDENTITY === $fieldName) {
                $property = $reflection->getProperty($this->getEntityIdName($className));
            } else {
                $property = $reflection->getProperty($fieldName);
            }

            try {
                $property->setValue($entity, $fieldValue);
            } catch (\Exception $e) {
                $property->setAccessible(true);
                $property->setValue($entity, $fieldValue);
                $property->setAccessible(false);
            }
        }

        return $entity;
    }
public function createEntity ( $ className , array $ fields = [ ] ) { $ metadata = $ this -> getEntityMetadata ( $ className ) ; if ( is_null ( $ metadata ) ) { return null ; } $ reflection = $ metadata -> getReflectionClass ( ) ; try { $ entity = $ reflection -> newInstance ( ) ; } catch ( \ Exception $ e ) { $ entity = $ reflection -> newInstanceWithoutConstructor ( ) ; } foreach ( $ fields as $ fieldName => $ fieldValue ) { if ( self :: IDENTITY === $ fieldName ) { $ property = $ reflection -> getProperty ( $ this -> getEntityIdName ( $ className ) ) ; } else { $ property = $ reflection -> getProperty ( $ fieldName ) ; } try { $ property -> setValue ( $ entity , $ fieldValue ) ; } catch ( \ Exception $ e ) { $ property -> setAccessible ( true ) ; $ property -> setValue ( $ entity , $ fieldValue ) ; $ property -> setAccessible ( false ) ; } } return $ entity ; }
Create instance of the class, which managed by Doctrine, by received class name

@param string $className
@param array  $fields

@return object|null
Create instance of the class which managed by Doctrine by received class name