transform sql data in Entity
@access public
@param $data   array
@param $entity string
@return array
@since  2.4
498102
final public function ormToEntity($data = [], $entity = '') {
        $entities = [];

        foreach ($data as $value) {
            if ($entity != '') {
                $entityName = '\entity\\' . $entity;
                $entityObject = new $entityName(Database::instance()->db());

                foreach ($value as $key => $value2) {
                    $entityObject->$key = $value2;
                }
            }
            else {
                $entityObject = new Multiple($data);
            }

            array_push($entities, $entityObject);
        }

        return $entities;
    }
70266
public function toSerializableArray($entity)
    {
        $data = array_intersect_key($entity->getData(), $entity->getEntityDescription()->getAttributes());

        return $data;
    }
95197
protected function transform($data)
    {
        if (!$data instanceof GetSchema\Schema) {
            throw new Exception('Schema instance missing.');
        }

        $returnData = [];

        foreach ($data->getTableDefinitions() as $definition) {
            $tmp = self::$tplData;
            $tmp['Name'] = $tmp[0] = $definition->getName();
            $returnData[] = $tmp;
        }

        if ($this->likeExpr !== '') {
            $returnData = $this->filterData($returnData);
        }

        return array_values($returnData);
    }
871107
public function transform($entity)
    {
        $data = [];

        if (null === $entity) {
            return $data;
        }

        $accessor = PropertyAccess::createPropertyAccessor();
        $text = is_null($this->textProperty)
            ? (string)$entity
            : $accessor->getValue($entity, $this->textProperty);

        $attr = [];
        foreach ( $this->data as $d ) {
            $value = $accessor->getValue($entity, $d);
            if ( $value instanceof PersistentCollection || $value instanceof ArrayCollection ) {
                $value = $value->first();
            }

            $attr[$d] = $value;
        }

        $data[$accessor->getValue($entity, $this->primaryKey)] = [
            'text' => $text,
            'attr' => $attr
        ];
        return $data;
    }
280923
protected function prepareQueueableEntities($data)
	{
		if ($data instanceof QueueableEntity)
		{
			return $this->prepareQueueableEntity($data);
		}

		if (is_array($data))
		{
			array_walk($data, function(&$d) { $d = $this->prepareQueueableEntity($d); });
		}

		return $data;
	}
1140665
protected function buildTable(Entity $entity)
    {
        // Prepare pivot tables and one-to-* columns
        $attributes = $this->prepareRelationships($entity) + $entity->getAttributeConfig();

        // Allow other services to append schema
        foreach(event(new SchemaPrepare($entity)) as $attrs){

            foreach((array)$attrs as $key => $value){

                $attributes[$key] = $this->applyAttributeDefaults($value);

            }

        }

        // Append attribute columns
        return $this->addAttributes($entity->getTable(), $attributes);
    }
763407
public function duplicate(Entity $entity = null)
    {
        $entity = $this->getEntityIfEmpty($entity);

        $data = $this->toArray();
        if (isset($data['id'])) {
            unset($data['id']);
        }

        foreach ($data as $key => &$val) {
            if ($key && array_key_exists($key . '_x', $data) && array_key_exists($key . '_y', $data)) {
                $val = [
                    $data[$key . '_x'],
                    $data[$key . '_y'],
                ];
            }
        }

        $record = new static($data);
        $record->save($entity);

        return $record;
    }
729481
public function transform($data)
    {
        if ($data instanceof FormBuilder) {
            $response = $data->getRawResponse();

            foreach ($response['fieldsets'] as $fieldset) {
                $this->transformFieldset($fieldset);
            }

            return [
                'form' => [
                    'name'      => array_get($response, 'name'),
                    'rules'     => array_get($response, 'rules', []),
                    'fieldsets' => $this->fieldsets,
                ],
            ];
        }

        return parent::transform($data);
    }
1148948
protected static function buildEntity($data)
    {
        $entities = static::getDefinedEntitiesArray();

        if (isset($data['entity']))
        {
            if (in_array($data['entity'], $entities))
            {
                $class = static::getEntityClass($data['entity']);
                $entity = new $class;
            }
            else
            {
                $entity = new static;
            }
        }
        else
        {
            $entity = new static;
        }

        $entity->fill($data);

        return $entity;
    }
31066
public function toArray($entity)
    {
        $firstTime = !$this->entitiesGraph ? true : false;

        if (!in_array(get_class($this), $this->entitiesGraph)) {
            $this->entitiesGraph[] = get_class($this);
        }

        $toArray  = [];
        $newArray = [];

        $refl = new \ReflectionClass($entity);
        foreach ($refl->getProperties() as $property) {
            $property->setAccessible(true);

            $value = $property->getValue($entity);

            if (array_key_exists($property->getName(), $this->propertiesToArrayCallbacks)) {
                $value = call_user_func_array($this->propertiesToArrayCallbacks[$property->getName()], [$value]);
            }

            if (!is_null($value)) {
                $toArray[$property->getName()] = $value;
            }
        }

        foreach ($toArray as $propertyName => $propertyValue) {

            // Simple mappings
            if (
                in_array($propertyName, $this->columnsToProperties) &&
                !array_key_exists($propertyName, $this->propertiesToMappers)
            ) {
                $columnName = array_search($propertyName, $this->columnsToProperties);

                $result = $this->createArrayFromColumnName($columnName, $propertyValue);
                $newArray = array_merge_recursive($newArray, $result);
                continue;
            }

            // Via Classes
            if (array_key_exists($propertyName, $this->propertiesToClasses) && is_object($propertyValue)) {
                $subMapper = $this->propertiesToClasses[$propertyName];
                $subMapper->setEntitiesGraph($this->entitiesGraph);
                $value    = $subMapper->toArray($propertyValue);
                $newArray = array_merge_recursive($newArray, $value);
                continue;
            }

            // via Mappers
            if (array_key_exists($propertyName, $this->propertiesToMappers)) {
                $className = $this->propertiesToMappers[$propertyName];

                if (in_array($className, $this->entitiesGraph)) {
                    continue;
                }

                /** @var DoplioDataMapper $subMapper */
                $subMapper = $this->resolver->resolve($className);
                $subMapper->setEntitiesGraph($this->entitiesGraph);

                if ($subMapper->toArrayResultCallback) {
                    $method        = $subMapper->toArrayResultCallback;
                    $propertyValue = $method($propertyValue);

                    foreach ($propertyValue as $offset => $item) {
                        $value = $subMapper->toArray(
                            $item
                        );
                        $newArray[array_search($propertyName, $this->columnsToProperties)][$offset] = $value;
                    }
                } else {
                    $value = $subMapper->toArray(
                        $propertyValue
                    );
                    $newArray[array_search($propertyName, $this->columnsToProperties)] = $value;
                }

                $this->entitiesGraph = array_merge($this->entitiesGraph, $subMapper->entitiesGraph);
            }
        }

        if ($this->fromClassname) {
            $method = $this->fromClassname;
            $data = $method(get_class($entity));
            $newArray = array_merge_recursive($newArray, $data);
        }


        if ($firstTime) {
            $this->entitiesGraph = [];
        }
        return $newArray;
    }
716270
protected function prepareQueueableEntities( $data )
	{
		if ( $data instanceof QueueableEntity )
		{
			return $this->prepareQueueableEntity( $data );
		}

		if ( is_array( $data ) )
		{
			$data = array_map( function ( $d )
			{
				if ( is_array( $d ) )
				{
					return $this->prepareQueueableEntities( $d );
				}

				return $this->prepareQueueableEntity( $d );
			}, $data );
		}

		return $data;
	}
1030045
protected function transform($data)
    {

        $items = [
            'name'       => $data[ 'name' ],
            'static'     => $this->boolValue($data[ '@attributes.static' ]),
            'line'       => (int)$data[ '@attributes.line' ],
            'visibility' => $data[ '@attributes.visibility' ],
            'namespace'  => $data[ '@attributes.namespace' ],
            'package'    => $data[ '@attributes.package' ],

            'description'      => $this->createDescription($data[ 'docblock.description' ]),
            'long-description' => $this->createDescription($data[ 'docblock.long-description' ]),
        ];

        $items[ 'full_name' ]  = $data->get('full_name', $this->belongsTo[ 'full_name' ] . '::' . Str::removeLeft($data[ 'name' ], '$'));
        $items[ 'class_name' ] = head(explode('::', $items[ 'full_name' ]));
        $items[ 'inherited' ]  = $this->belongsTo[ 'full_name' ] !== $items[ 'class_name' ];
        $items[ 'tags' ]       = $this->structures('docblock.tag', Tag::class, $data);

        $types = $data->get('docblock.tag.type', 'mixed');
        if ( !is_array($types) ) {
            $types = [ $types ];
        }
        $items[ 'types' ] = $types;

        return $items;
    }
299840
protected function _fillFromArray($entity, $data)
    { 
      
      if ($data) {
        
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $className = 'MercadoPago\\' . $this->_camelize($key);
                if (class_exists($className, true)) {
                    $entity->_setValue($key, new $className, false);
                    $entity->_fillFromArray($this->{$key}, $value);
                } else {
                    $entity->_setValue($key, json_decode(json_encode($value)), false);
                }
                continue;
            }
            $entity->_setValue($key, $value, false);
        }
      }
    }
862456
public function transform($entity)
    {
        $data = array();
        if (empty($entity)) {
            return $data;
        }

        $text = is_null($this->textProperty)
            ? (string) $entity
            : $this->accessor->getValue($entity, $this->textProperty);

        if ($this->em->contains($entity)) {
            $value = (string) $this->accessor->getValue($entity, $this->primaryKey);
        } else {
            $value = $this->newTagPrefix . $text;
            $text = $text.$this->newTagText;
        }

        $data[$value] = $text;

        return $data;
    }
355055
public function query ($query, $data = array(), $entity = null)
		{
			if ($this->cache->isCached($query)) {
				return $this->cache->getCachedResult($query);
			} else {
				try {
					$statement = $this->database->prepare((string) $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
					$result = $statement->execute($data);
					$this->lastQuery = $statement->queryString;
					$this->lastStatement = $statement;

					if (! $result) {
						throw new DatabaseException(implode(': ', $statement->errorInfo()) . PHP_EOL . PHP_EOL . $query);
					}

				} catch (PDOException $e) {
					throw new DatabaseException($e->getMessage() . PHP_EOL . PHP_EOL . $query);
				}

				$databaseResult = $this->createResult($statement, $entity);

				if ($query instanceof DatabaseQuery && $databaseResult instanceof DatabaseResult) {
					$this->cache->cacheQuery($query, $databaseResult);
				}

				if ($query instanceof DatabaseQuery) {
					$this->cache->refreshCache($query);
				}

				if ($databaseResult instanceof DatabaseResult) {
					return $databaseResult;

				} else if ($query instanceof DatabaseQuery && $query->getType() == DatabaseQuery::QUERY_TYPE_INSERT) {
					return $this->insertId($query->getTable());

				} else {
					return $databaseResult;
				}
			}
		}
286179
public function create($data, $entity = null)
    {
        $entity = $this->getEntity($entity);
        $fields = $this->getFields();

        // set fields
        foreach ($fields as $key => $mapping) {
            $fieldType = $this->fieldManager->get($mapping['fieldtype'], $mapping);

            // If we have a transformer setup then this takes precedence
            $mappedType = $mapping['fieldtype'];
            $handler = isset($this->transformers[$mappedType]) ? $this->transformers[$mappedType] : null;

            if ($handler) {
                $handler($entity, $data[$key]);
            } else {
                $val = isset($data[$key]) ? $data[$key] : null;
                if ($fieldType instanceof FieldTypeInterface) {
                    $fieldType->set($entity, $val);
                }
            }
        }

        return $entity;
    }
971737
public static function create($data = [], Entity $entity = null)
    {
        $record = new static($data, $entity);

        $record->save();

        return $record;
    }