@param DoplioDbTable $instance
@param array         $entityArray

@return DoplioDbTable
436850
protected function fillExistingInstanceFromEntityArray(DoplioDbTable $instance, array $entityArray)
    {
        $relations = $instance->getRelations();

        foreach ($entityArray as $offset => $value) {
            if (method_exists($instance, $offset)) {
                /** @var Relation $relationship */
                $relationship     = $instance->$offset();
                $subMapper        = new GenericDataMapper($this->resolver);
                $className        = get_class($relationship->getQuery()->getModel());
                $subMapper->table = new $className();

                if (!array_key_exists($offset, $relations)) {
                    $instance->setRelation($offset, $this->createInstanceFromEntityArray($value, $subMapper));
                } else {
                    if ($relations[$offset] instanceof Collection) {
                        $filled = $relations[$offset];
                        foreach ($relations[$offset] as $collectionOffset => $item) {
                            $this->fillExistingInstanceFromEntityArray($item, $value[$collectionOffset]);
                        }
                    } else {
                        $filled = $this->fillExistingInstanceFromEntityArray($relations[$offset], $value);
                    }
                    $instance->setRelation($offset, $filled);
                }

                unset($entityArray[$offset]);
            }
        }

        $instance->fill($entityArray);
        return $instance;
    }
795385
public function setInstance(\Illuminate\Database\Eloquent\Model $instance): ColumnInterface
    {
        $this->instance = $instance;

        return $this;
    }
1001002
protected static function applyProperties($entityInstance, $data)
    {
        foreach ($data as $property => $value) {
            $funcName = 'set'.ucfirst($property);
            if (method_exists($entityInstance, $funcName)) {
                $entityInstance->$funcName($value);
            }
        }

        return $entityInstance;
    }
1150434
private function findFieldInstances($entityType, $entityInfo)
    {
        $ret = [];

        // Add field properties, since Drupal does not differenciate entity
        // bundles using different class for different object, we are just
        // gonna give the whole field list
        foreach (field_info_instances($entityType) as $fields) {
            foreach ($fields as $name => $instance) {

                if (isset($ret[$name])) {
                    continue;
                }

                $ret[$name] = $instance;
            }
        }

        return $ret;
    }
864666
public function write($instance, $entity = null)
    {
        list($instance, $entity) = $this->reassignEntity($instance, $entity);

        return new WriteQuery(
            $this->connection,
            $instance,
            $this->models->get($entity),
            $this->factory,
            $this->accessor,
            $this->dispatcher
        );
    }
902794
public function getByEntity($entityClass, $id, $locale, $object = null)
    {
        $metadata = $this->structureMetadataFactory->getStructureMetadata('page', $object->getStructureType());

        return [
            '_controller' => $metadata->getController(),
            'view' => $metadata->getView(),
            'object' => $object,
            'structure' => $this->documentToStructure($object),
        ];
    }
469169
public function remove(AbstractEntity $instance)
    {
        $class = get_class($instance);
        $entityPool = $this->pool[$class] ?? [];
        $id = '' . $instance->id;
        if (isset($entityPool[$id])) {
            unset($entityPool[$id]);
            $this->pool[$class] = $entityPool;
        }
        unset($instance);

        return true;
    }
124676
public function getModelInstanceIfId($instance, $table)
    {
        if ($instance instanceof Model) {
            return $instance;
        }

        if ($instance instanceof Collection) {
            return $instance->current();
        }

        return $this->findModelInstanceByPk($table, $instance);
    }
450506
public function update($entityKey, $commandKey, $instanceId)
    {
        $list = $this->getListInstance($entityKey);
        $list->buildListConfig();

        $handler = $this->getCommandHandler($list, $commandKey, $instanceId);

        return $this->returnCommandResult(
            $list,
            $handler->execute(
                $instanceId,
                $handler->formatRequestData((array)request("data"), $instanceId)
            )
        );
    }
576400
protected function parseProperty(string $entity, $entityName, array $fields, Schema $schema, $instance)
    {
        $this->entity     = $entity;
        $this->entityName = $entityName;
        $this->entityDate = date('Y年m月d日');
        $this->fields     = $fields;
        $removeTablePrefix = $this->removeTablePrefix;

        $entityClass = $this->entity;
        if (!empty($removeTablePrefix)) {
            $entityClass = StringHelper::replaceFirst($removeTablePrefix, '', $this->entity);
        }
        $this->entityClass = StringHelper::camel($entityClass);
        $this->entityClass = ucfirst($this->entityClass);

        $param = [
            $schema,
            $this->uses,
            $this->extends,
            $this->entity,
            $this->entityName,
            $this->entityClass,
            $this->entityDate,
            $this->fields,
            $instance,
        ];

        $sgGenerator = new SetGetGenerator();
        $sgGenerator(...$param);
    }
74244
public function findRootParentRecursively(string $parentProperty, string $table, Model $instance, bool $returnInstanceIfNoParent = true)
    {
        if (!$instance || !$instance->{$parentProperty}
            || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $returnInstanceIfNoParent ? $instance : null;
        }

        return $this->findRootParentRecursively($parentProperty, $table, $parentInstance);
    }
962536
public function contextFactory(ContextFactory $instance = null, array $contexts = [])
    {
        if ($instance === null) {
            if ($this->_contextFactory === null) {
                $this->_contextFactory = ContextFactory::createWithDefaults($contexts);
            }

            return $this->_contextFactory;
        }
        $this->_contextFactory = $instance;

        return $this->_contextFactory;
    }
1263290
public function setInstance($instance)
    {
        $this->instance = $instance;
        $this->setClassName(get_class($this->instance));

        return $this;
    }
1047818
public static function prepareQuery(array &$options=array(), &$instance=null, $IDField=null) {
		self::prepareInstance($instance);
		self::$instances[$instance]->setIDField($IDField);
		if( !empty($options) && !empty($options['output']) && $options['output'] == SQLAdapter::ARR_FIRST ) {
			$options['number'] = 1;
		}
	}
538392
public function update_instance($instance, $data) {
        global $DB;
        $properties = array('status', 'name', 'password', 'customint1', 'customint2', 'customint3',
                            'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
                            'customchar1', 'customchar2', 'customchar3', 'customdec1', 'customdec2',
                            'customtext1', 'customtext2', 'customtext3', 'customtext4', 'roleid',
                            'enrolperiod', 'expirynotify', 'notifyall', 'expirythreshold',
                            'enrolstartdate', 'enrolenddate', 'cost', 'currency');

        foreach ($properties as $key) {
            if (isset($data->$key)) {
                $instance->$key = $data->$key;
            }
        }
        $instance->timemodified = time();

        $update = $DB->update_record('enrol', $instance);
        if ($update) {
            \core\event\enrol_instance_updated::create_from_record($instance)->trigger();
        }
        return $update;
    }
1212480
final public static function setInstance($instance)
    {
        if ($instance instanceof PDO) {
            $instance = $instance->getAttribute(PDO::ATTR_DRIVER_NAME);
        }
        if (is_string($instance)) {
            if (class_exists('SQL\Writer\\' . $instance)) {
                $class = 'SQL\Writer\\' . $instance ;
                $instance = new $class;
            } else {
                $instance = new self;
            }
        }

        if (!($instance instanceof self)) {
            throw new RuntimeException('$instance must an instanceof SQL\Writer');
        }

        self::$instance = $instance;
    }
200786
public static function setInstance($instance)
    {
        if ($instance instanceof self) {
            self::$instance = $instance;
        } elseif (is_array($instance)) {
            self::$instance = new self($instance);
        } else {
            $message = 'Argument 1 passed to Storage::setInstance must be '.
                'an instance of go\DB\DB or array, '.gettype($instance).' given';
            trigger_error($message, E_USER_ERROR);
        }
        return self::$instance;
    }