This calls __set for each property of the model object created
above in the setResults call. See CEFData.php for what happens next.

@param $entity
@param $model

@return mixed
180855
private function populate($entity, $model)
    {
        if ($entity && (is_array($entity) || is_object($entity))) {
            foreach ($entity as $name => $value) {
                $model->$name = $value;
            }
        }

        return $model;
    }
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;
    }
479209
public function persist(Entity $entity)
    {
        $this->checkEntityType($entity);

        $this->events->invokeCallbacks(Events::EVENT_BEFORE_PERSIST, $entity);
        if ($entity->isDetached()) {
            $entity->makeAlive($this->entityFactory, $this->connection, $this->mapper);
            $this->events->invokeCallbacks(Events::EVENT_BEFORE_CREATE, $entity);
            $result = $id = $this->insertIntoDatabase($entity);
            $entity->attach($id);
            $this->events->invokeCallbacks(Events::EVENT_AFTER_CREATE, $entity);
        } else {
            if ($entity->isModified()) {
                $this->events->invokeCallbacks(Events::EVENT_BEFORE_UPDATE, $entity);
                $result = $this->updateInDatabase($entity);
                $this->events->invokeCallbacks(Events::EVENT_AFTER_UPDATE, $entity);
            }
            $this->persistHasManyChanges($entity);
            $entity->markAsUpdated();
        }
        $this->events->invokeCallbacks(Events::EVENT_AFTER_PERSIST, $entity);

        return isset($result) ? $result : null;
    }
39840
public function setEntity($entity)
    {
        $this->debugLog(sprintf('ENTITY: %s', $entity));

        $expectedEntity = $this->makeSQLSafe($this->getParams()['DBPREFIX'] . $entity);

        $this->debugLog(sprintf('SET ENTITY: %s', $expectedEntity));

        // Concatinate the entity with the sqldbprefix value only if not already done.
        if ($expectedEntity !== $this->entity) {
            $this->entity = $expectedEntity;
        }

        return $this;
    }
1319267
public function setPropertyValue(&$entity, $field, $value)
    {
        $this->assertEntity($entity);

        if (is_array($entity) || $entity instanceof \ArrayAccess) {
            $entity[$field] = $value;

            return;
        }

        $ref = $this->getReflection($entity);
        if (!$ref->hasProperty($field)) {
            $entity->{$field} = $value;

            return;
        }

        $this->getProperty($ref, $field)->setValue($entity, $value);
    }
1340425
public static function setValueInEntity($entity, $property, $value)
    {
        $setter = self::createSetter($entity, $property);
        $entity->$setter($value);
    }
1192496
protected function setEntityData($entity, $property)
    {
        if (is_array($entity) && count($entity) == 2) {
            TypeChecker::isString($entity[0]);
            TypeChecker::isNumeric($entity[1]);

            $type = $entity[0];
            $id = $entity[1];
        } elseif ($entity[0] instanceof Model) {
            $type = $entity[0]->getMorphClass();
            $id = $entity[0]->getKey();
        } else {
            TypeChecker::isNumeric($entity[0]);

            $type = notifynder_config()->getNotifiedModel();
            $id = $entity[0];
        }

        $this->setNotificationData("{$property}_type", $type);
        $this->setNotificationData("{$property}_id", $id);
    }
152433
public function getData($entity = array())
    {
        if ($this->accessor == null) {
            $this->accessor = new PropertyAccessor;
        }

        foreach ($this->getFields() as $name => $field) {
            if ($mapping = $field->getMappingName()) {
                if (is_array($entity)) {
                    $entity[$mapping] = $field->getMappingValue();
                } else {
                    $this->accessor->setValue($entity, $mapping, $field->getMappingValue());
                }
            }
        }

        return $entity;
    }
1046831
public function createFromEntity ($entity)
    {
        // Persist it
        $this->em->persist($entity);
        $this->em->flush();

        // Convert it to model and cache it
        $Model                  = $this->_convertEntityToModel($entity);
        $this->cache[$entity->getId()] = $Model;

        return $Model;
    }
1117043
public function validateEntity($entity)
    {
        $description = $entity->getEntityDescription();

        //if entity is persisted only look at the modified
        //properties
        if ($entity->isModified()) {
            $properties = array_intersect_key($description->getProperty(), AnConfig::unbox($entity->getModifiedData()));
        } else {
            $properties = $description->getProperty();
        }

        foreach ($properties as $property) {
            $value = $entity->get($property->getName());
            $entity->getValidator()->validateData($entity, $property, $value);
        }

        return $entity->getErrors()->count() === 0;
    }
940398
public static function update($entity): ResultInterface
    {
        $className = \get_class($entity);
        list($table, $idColumn, $idValue, $fields) = self::getFields($entity, 2);

        if (empty($fields)) {
            return new DbDataResult(0);
        }
        // 构建update查询器
        $instance = self::getInstance($className);
        $fields   = $fields ?? [];
        $query    = Query::table($table)->className($className)->where($idColumn, $idValue)->selectInstance($instance);

        return $query->update($fields);
    }
1286047
public function refresh($entity)
    {
        $fields = $this->getFields();

        foreach ($fields as $key => $mapping) {
            $fieldType = $this->fieldManager->get($mapping['fieldtype'], $mapping);
            $getter = 'get' . ucfirst($key);
            $value = $entity->$getter();
            if ($value) {
                $fieldType->set($entity, $value);
            }
        }
    }
266500
public function delete($entity) {
		if (is_null($entity))
			return;
		
		//connect to database
		$this->mapper->connect();
		
		//begin transaction
		$this->mapper->beginTransaction();
		
		//get primary key
		$pk = $this->getPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey());

		foreach ($this->entityProfile->getReferences() as $assoc)
			$this->entityProfile->getAssociation($assoc)->delete($this->mapper, $pk);
		
		//build fluent query
		$query = $this->mapper->newQuery()
		->deleteFrom($this->entityProfile->getEntityTable())
		->where(Column::__callstatic($this->entityProfile->getPrimaryKey(true))->eq($pk));
		
		//run query
		$result = $query->exec();
		
		//commit
		$this->mapper->commit();
		return $result;
	}
553559
public function set($entity, $val)
    {
        if ($val === null) {
            $val = new RepeatingFieldCollection($this->em, $this->mapping);
        }

        return parent::set($entity, $val);
    }
121828
private function createSetter(Entity $entity, $property, $annotation)
    {
        if ($annotation->setter === null) {
            $setter = new PropertySetter($entity, $property);
        } else {
            if ($annotation->setter === true) {
                $methodName = 'set' . ucfirst($property);
            } else {
                $methodName = $annotation->setter;
            }
            $setter = new MethodSetter($entity, $methodName);
        }

        return $setter;
    }
248453
public function setEntity(Entity $entity)
    {
        $this->each(
            function(Record $record) use ($entity) {
                $record->setEntity($entity);
                $record->setEntityClass(get_class($entity));
            }
        );

        return $this;
    }
1023312
public static function updateEntityFromArray($entity, array $data)
    {
        foreach ($data as $field => $value) {
            $method = 'set' . self::formatStringToMethodName($field);
            if (method_exists($entity, $method)) {
                $entity->$method($value);
            }
        }

        return $entity;
    }