save a object
you can pass the Site object or an array with the fields
if you pass an array the keys must be with underscore and not with CamelCase
@param object|array $object
@return object
425003
public function save($object)
    {

        if (is_array($object)) {
            $objectData = $object;
            if ($object['id'] > 0) {
                $object = $this->find($object['id']);
            } else {
                $object = $this->createNewObject();
            }
            $this->assignArrayToObject($object, $objectData);
        } else if (!$this->isCorrectInstance($object)) {
            $this->addErrorMessage(self::ERROR_WRONG_OBJECT);
        }

        if (!$this->hasError()) {
            $check = $this->manager->save($object);
            if ($check) {
                $this->addSuccessMessage(self::SUCCESS_SAVED);
            }
        }

        return $object;
    }
470149
private function insert($object)
    {
        //TODO: this should only be done if there is a Delete query pending for the same entity table
        $this->manager->commit();

        $query = $this->manager
            ->getDriver()
            ->getQueryBuilder()
            ->insert($this->getTable());

        $query->values(
            $query->createPositionalParameter(
                array_filter(
                    $this->toArray($object),
                    [Utils::class, 'notNull']
                )
            )
        );

        return $this->setFieldValue(
            $object,
            $this->getPrimaryKey(),
            $query->query()
        );
    }
460040
protected function saveFile(array $object, $location) {
		//Serialize and save the object to a store in the Cake's tmp dir.
		if (!file_exists($location)) {
			if (!mkdir($location, 0770, true)) {
				//Throw error, directory is requird
				throw new NotFoundException('Could not create directory to save feedbacks in. Please provide write rights to webserver user on directory: ' . $location);
			}
		}

		if (file_put_contents($location . $object['filename'], serialize($object))) {
			//Add filename to data
			return true;
		}
		return false;
	}
868379
public static function attrToArray($object){
        if(is_array($object) || is_object($object)) {
            $result = [];
            foreach ($object as $key => $value) {
                $result[$key] = self::attrToArray($value);
            }
            return $result;
        }
        return $object;
    }
1021341
public static function fromObject($object)
    {
        if (\is_object($object)) {
            $object = (array)$object;
        }
        if (\is_array($object)) {
            $array = [];
            foreach ($object as $key => $value) {
                $array[$key] = self::fromObject($value);
            }
        } else {
            $array = $object;
        }
        return $array;
    }
392987
protected function createObject($object)
    {
        $type = new ObjectType(['class'=>get_class($object)]);

        foreach (get_object_vars($object) as $property=>$value) {
            $type[$property] = $this->toType($value);
        }

        return $type;
    }
783493
public function save($object)
    {
        $ret = $this->getValidator()->validateSave($object);
        if ($ret) {
            $ret = $this->_save($object);
        }
        return $ret;
    }
690118
protected function objectKey($object)
	{
		return base64_encode(json_encode(['id' => $object->id, 'type' => $object->type, 'relations' => $this->relations]));
	}
1277971
public static function toArray( $object )
    {
        if ( is_object( $object ) )
        {
            return get_object_vars( $object );
        }

        if ( is_array( $object ) )
        {
            return array_map(
                array(
                    __CLASS__,
                    'toArray'
                ),
                $object
            );
        }

        // Return array
        return $object;
    }
923924
protected function optimizeObjectContent($object)
	{
		$object = $this->recordObject($object);
		$this->deduplicateConfigValues();

		return $object->getValue();
	}
47566
public static function objectToString($object): string {
        //TODO do type hinting when possible
        if (!\is_object($object)) {
            throw new InvalidKeyTypeException("key has to be an object, " . \gettype($object) . "given");
        }
        return \serialize($object);
    }
511339
protected function hydrateObjectForm($object)
    {
        $data = array(
            "id" => $object->getId(),
            "visible" => (bool) $object->getVisible(),
            "code" => $object->getCode(),
            "title" => $object->getTitle(),
            "type" => $object->getType(),
            "entity" => $object->getEntity(),
            "serialized_columns" => $object->getSerializedColumns(),
            "serialized_condition" => $object->getSerializedCondition(),
            "index_engine_driver_configuration_id" => $object->getIndexEngineDriverConfigurationId(),
        );

        return $this->getUpdateForm($data);
    }
1103067
public function toArray($object)
    {
        $this->assertObjectInstance($object);

        return array_map(
            function (Field $field) use ($object) {
                return $field->get($object);
            },
            $this->getFields()
        );
    }
926018
public function hash($object, $keys)
    {
        $keyValues = array_map(
            function ($k) use ($object) {
                $a = is_array($k);
                return sprintf('%s=%s',$a?$k[1]:$k, $object->{$a?$k[0]:$k});
            },
            $keys
        );

        return sprintf('%s[%s]', $this->_class, implode(',', $keyValues));
    }
894920
final protected function _convert($object)
	{
		// if this isn't an object then just return it
		if (!is_object($object)) {
			return $object;
		}
		//Mark this object as processed so we don't convert it twice and it
		//Also avoid recursion when objects refer to each other
		$this->_processed[] = $object;
		$object_as_array = array();
		// first add the class name
		$object_as_array['___class_name'] = get_class($object);
		// loop through object vars
		$object_vars = get_object_vars($object);
		foreach ($object_vars as $key => $value) {
			// same instance as parent object
			if ($value === $object || in_array($value, $this->_processed, true)) {
				$value = 'recursion - parent object [' . get_class($value) . ']';
			}
			$object_as_array[$key] = $this->_convert($value);
		}
		$reflection = new \ReflectionClass($object);
		// loop through the properties and add those
		foreach ($reflection->getProperties() as $property) {
			// if one of these properties was already added above then ignore it
			if (array_key_exists($property->getName(), $object_vars)) {
				continue;
			}
			$type = $this->_getPropertyKey($property);
			if ($this->_php_version >= 5.3) {
				$property->setAccessible(true);
			}
			try {
				$value = $property->getValue($object);
			} catch (\ReflectionException $e) {
				$value = 'only PHP 5.3 can access private/protected properties';
			}
			// same instance as parent object
			if ($value === $object || in_array($value, $this->_processed, true)) {
				$value = 'recursion - parent object [' . get_class($value) . ']';
			}
			$object_as_array[$type] = $this->_convert($value);
		}
		return $object_as_array;
	}
395556
public static function insert($object)
    {
        $db = new DatabaseManager();
        $connection = $db->getDbh();

        $objectAsArrayForSqlInsert = DatatbaseUtility::objectToArrayLessId($object);
        $fields = array_keys($objectAsArrayForSqlInsert);
        $insertFieldList = DatatbaseUtility::fieldListToInsertString($fields);
        $valuesFieldList = DatatbaseUtility::fieldListToValuesString($fields);

        $statement = $connection->prepare('INSERT into '. static::getTableName()  . ' ' . $insertFieldList . $valuesFieldList);
        $statement->execute($objectAsArrayForSqlInsert);

        $queryWasSuccessful = ($statement->rowCount() > 0);
        if ($queryWasSuccessful) {
            return $connection->lastInsertId();
        } else {
            return -1;
        }
    }
871081
public function save($object)
    {
        if (method_exists($object, 'getContenttype')) {
            $entityName = $object->getContenttype();
        } else {
            $entityName = get_class($object);
        }
        $repo = $this->getRepository($entityName);

        return $repo->save($object);
    }