save a Site
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 GroupInterface|array $object
@return GroupInterface
168130
public function save($object)
    {

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

        if (!$this->hasError()) {
            $check = $this->groupManager->update($object);
            if ($check === true) {
                $this->addSuccessMessage(self::SUCCESS_SAVED);
            }
        }

        return $object;
    }
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;
	}
806358
private function savePropertiesDirectly(Remote\Model $object)
    {
        foreach ($object::getProperties() as $property_name => $meta) {
            if ($meta[Remote\Model::KEY_SAVE_DIRECTLY] && $object->isDirty($property_name)) {
                //Then actually save
                $property_objects = $object->$property_name;
                /** @var Remote\Model $property_type */
                $property_type = get_class(current($property_objects));

                $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI()));
                $request = new Request($this, $url, Request::METHOD_PUT);

                $property_array = [];
                /** @var Remote\Model[] $property_objects */
                foreach ($property_objects as $property_object) {
                    $property_array[] = $property_object->toStringArray(false);
                }

                $root_node_name = Helpers::pluralize($property_type::getRootNodeName());
                $request->setBody(Helpers::arrayToXML([$root_node_name => $property_array]));

                $request->send();

                $response = $request->getResponse();
                foreach ($response->getElements() as $element_index => $element) {
                    if ($response->getErrorsForElement($element_index) === null) {
                        $property_objects[$element_index]->fromStringArray($element);
                        $property_objects[$element_index]->setClean();
                    }
                }

                //Set it clean so the following save might have nothing to do.
                $object->setClean($property_name);
            }
        }
    }
1037621
public static function keys($object)
    {
        if ($object instanceof \stdClass)
            $object = (array)$object;

        if (is_array($object))
            return array_keys($object);

        $result = [];
        static::each($object, function ($item, $key) use (& $result) {
            $result[] = $key;
        });

        return $result;
    }
800690
public static function createAdapterObject($object)
    {
        $wrapperObject = self::create($object, null, function ($method, $arguments, $result) {
            $data['method']    = $method;
            $data['arguments'] = $arguments;

            $appType = php_sapi_name();
            if ($appType == 'cli') {
                $processName = @cli_get_process_title();
                if (strpos($processName, 'msf') !== false) {
                    $appType = 'msf';
                }
            } else {
                $appType = 'web';
            }

            if ($appType != 'msf' && $result instanceof \Generator) {
                $data['result'] = $result->getReturn();
                return $data;
            }

            $data['result'] = $result;
            return $data;
        });

        return $wrapperObject;
    }
1177519
public function persist($object, $collection = null)
    {
        $repository = $this->getRepository(get_class($object), $collection);
        $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_PRE_PERSIST, $object);
        $this->addObject($object, ObjectManager::OBJ_NEW, $repository);
        $repository->getClassMetadata()->getEventManager()->execute(EventManager::EVENT_POST_PERSIST, $object);

        return $this;
    }
158051
public function hydrate( array $data, $object )
    {
        if ( $object instanceof MapperAwareInterface )
        {
            $object->setMapper( $this );
        }

        if ( $object instanceof Structure )
        {
            if ( ! empty( $data['cssFile'] ) && is_file( $data['cssFile'] ) )
            {
                $object->parseFile( $data['cssFile'] );
            }
            else if ( ! empty( $data['css'] ) )
            {
                $object->parseString( $data['css'] );
            }
        }
        else
        {
            if ( ! empty( $data['cssFile'] ) && is_file( $data['cssFile'] ) )
            {
                $object->css = file_get_contents( $data['cssFile'] );
            }
            else if ( ! empty( $data['css'] ) )
            {
                $object->css = (string) $data['css'];
            }
        }

        if ( array_key_exists( 'rootId', $data ) )
        {
            $object->rootId = $data['rootId'];
        }

        return $object;
    }
731061
public static function create($object)
    {
        if ($object instanceof JobDetail) {
            $message = sprintf(
                'Unable to store Job : "%s", because one already exists with this identification.', $object->getKey()
            );
        } elseif ($object instanceof Trigger) {
            $message = sprintf(
                'Unable to store Trigger with name: "%s" and group: "%s", because one already exists with this identification.'
                , $object->getKey()->getName(), $object->getKey()->getGroup()
            );
        } else {
            $message = (string) $object;
        }

        return new static($message);
    }
821948
protected function processInternal($object) {
		if (is_scalar($object)) {
			return $object;
		} elseif (is_array($object)) {
			return $this->processCollectionType($object, array_keys($object));
		} elseif ($object instanceof \DateTime) {
			return $object->format(DateTimeConverter::DEFAULT_DATE_FORMAT);
		} elseif (is_object($object) && ($object instanceof ArrayCollection)) {
			$arrayRepresentation = $object->toArray();
			return $this->processCollectionType($arrayRepresentation, array_keys($arrayRepresentation));
		} elseif ($object instanceof DataTransferInterface) {
			if (!$this->cacheTagService) {
				$content = $this->processCollectionType($object, $object->getPropertyNamesToBeApiExposed());
			} else {
				$this->cacheTagService->openEnvironment();
				$this->cacheTagService->addEnvironmentCacheTag($object);
				$identifier = md5($this->cacheTagService->createCacheIdentifier([$this->metaDataProcessorGroup, $object]));

				if (!$this->cache->has($identifier)) {
					$content = $this->processCollectionType($object, $object->getPropertyNamesToBeApiExposed());
					$this->cache->set($identifier, $content, $this->cacheTagService->getEnvironmentTags());
				} else {
					$content = $this->cache->get($identifier);
				}
				$this->cacheTagService->closeEnvironment();
			}
			return $content;
		} elseif ($object instanceof UriPointer) {
			return $this->processUriPointer($object);
		} elseif ($object instanceof Resource) {
			return $this->resourceManager->getPublicPersistentResourceUri($object);
		}
	}
895996
private static function toArrayRecursive($object)
    {
        $output = get_object_vars($object);

        foreach ($output as $key => $value) {
            if ($value instanceof \DateTime) {
                $output[$key] = $value->format('c');
            } elseif (is_object($value)) {
                $output[$key] = static::toArrayRecursive($value);
            }
        }

        return $output;
    }
167234
public function create($object)
    {
        $db = new DatabaseManager();
        $connection = $db->getDbh();

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

        $sql = 'INSERT into :table :insertFieldList :valuesFieldList';
        $sql = str_replace(':table', $this->tableName, $sql);
        $sql = str_replace(':insertFieldList', $insertFieldList, $sql);
        $sql = str_replace(':valuesFieldList', $valuesFieldList, $sql);

        $statement = $connection->prepare($sql);
        $statement->execute($objectAsArrayForSqlInsert);

        $queryWasSuccessful = ($statement->rowCount() > 0);
        if($queryWasSuccessful) {
            return $connection->lastInsertId();
        } else {
            return -1;
        }
    }
1194712
protected function createObject(ArraySerializable $object): ArraySerializable
    {
        return $this->sendRequestForEntity(
            $this->createRequest(self::POST, $this->urlRender->prepareCreateUrl($object->toArray()), [], $object->toArray())
        );
    }
218242
public function fromArray(array $object = array())
    {
        if (count($object) > 0) {
            $reflector = new \ReflectionClass($this);
            $properties = InjectorHelper::extractProperties($reflector, \ReflectionProperty::IS_PUBLIC, InjectorHelper::VAR_PATTERN);
            unset($reflector);
            foreach ($object as $key => $value) {
                if (property_exists($this, $key) && null !== $value) {
                    $this->parseDtoField($properties, $key, $value);
                }
            }
        }
    }
568704
public function hydrate(array $data, $object)
    {
        if (isset($data['forge-name'])) {
            $object->setName($data['forge-name']);
        } elseif (isset($data['name'])) {
            $object->setName($data['name']);
        }
        if (isset($data['inherited'])) {
            $object->setInherited($data['inherited']);
        }
        if (isset($data['version'])) {
            $object->setVersion($data['version']);
        }
        if (isset($data['source'])) {
            $object->setSource($data['source']);
        }
        if (isset($data['project_page'])) {
            $object->setProjectPage($data['project_page']);
        }
        if (isset($data['issues_url'])) {
            $object->setIssuesUrl($data['issues_url']);
        }
        if (isset($data['author'])) {
            $object->setAuthor($data['author']);
        }
        if (isset($data['summary'])) {
            $object->setSummary($data['summary']);
        }
        if (isset($data['license'])) {
            $object->setLicense($data['license']);
        }
        return $object;
    }
240722
public function add(GroupObject $object) : Group
    {
        if (count($this->objects) < 2)
        {
            $this->objects[] = $object;
        }
        else
        {
            throw new Exception(
                "An XORGroup may not contain more than two objects."
            );
        }

        return $this;
    }
695157
public function persistNewObject(IObject $object)
    {
        if (!$this->contains($object)) {
            throw new NotAllowedOperationException($this->translate(
                'Cannot persist new object. Object from another collection given.'
            ));
        }

        $dataSource = $this->getMetadata()
            ->getCollectionDataSource();
        $identifyColumnName = $this->getIdentifyField()
            ->getColumnName();

        $insertBuilder = $dataSource->insert();

        // set object id
        if ($object->getId()) {
            $insertBuilder
                ->set($identifyColumnName)
                ->bindValue(
                    ':' . $identifyColumnName,
                    $object->getId(),
                    $this
                        ->getIdentifyField()
                        ->getDataType()
                );
        }

        // set type
        $typeName = $object->getTypePath();
        $objectTypeField = $this->getObjectTypeField();
        $columnName = $objectTypeField->getColumnName();
        $insertBuilder->set($columnName);
        $insertBuilder->bindValue(':' . $columnName, $typeName, $objectTypeField->getDataType());

        foreach ($object->getModifiedProperties() as $property) {
            if ($this->getMetadata()
                ->getFieldExists($property->getName())
            ) {
                $field = $this->getMetadata()
                    ->getField($property->getName());
                $field->persistProperty($object, $property, $insertBuilder);
            }
        }

        $insertBuilder->execute();
        
        if (!$object->getId()) {
            $objectId = $insertBuilder->getConnection()->lastInsertId();
            if (!$objectId) {
                throw new RuntimeException($this->translate(
                    'Cannot persist object. Cannot get last inserted id for object.'
                ));
            }
            $object->getProperty(IObject::FIELD_IDENTIFY)
                ->setInitialValue($objectId);
        }

    }
978364
protected function recordObjectContent($object)
	{
		foreach ($object as $k => $v)
		{
			if ($this->canDeduplicate($v) && !$this->shouldPreserve($v))
			{
				$object[$k] = $this->recordObject($v);
			}
		}

		return $object;
	}