Save the entity or throw an exception.
@param mixed[] $data
@param mixed[] $whiteList
@throws \Frogg\Exception\UnableToSaveRecord
19725
public function saveOrFail(?array $data = null, ?array $whiteList = null) : void
    {
        $return = parent::save($data, $whiteList);

        if ($return === false) {
            throw new UnableToSaveRecord('Unable to save entity. Details: ' . json_encode($this->getMessages()));
        }
    }
249313
public function handleSave(GridField $grid, DataObjectInterface $record)
    {
        if (!$this->immediateUpdate) {
            $value = $grid->Value();
            $sortedIDs = $this->getSortedIDs($value);
            if ($sortedIDs) {
                $this->executeReorder($grid, $sortedIDs);
            }
        }
    }
1010050
public function assign($data, $whiteList = null)
    {
        if ($whiteList === null) {
            $whiteList = $this->getSafeFields();
        }

        if ($whiteList === null) {
            throw new PreconditionException(['`:model` model do not define accessible fields.', 'model' => static::class]);
        }

        foreach ($whiteList ?: $this->getFields() as $field) {
            if (isset($data[$field])) {
                $value = $data[$field];
                $this->{$field} = is_string($value) ? trim($value) : $value;
            }
        }

        return $this;
    }
463585
public function save($data)
	{
		$dispatcher = JEventDispatcher::getInstance();
		$table      = $this->getTable();
		$input      = JFactory::getApplication()->input;
		$pk         = (!empty($data['id'])) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
		$isNew      = true;
		$context    = $this->option . '.' . $this->name;

		// Include the plugins for the save events.
		JPluginHelper::importPlugin($this->events_map['save']);

		// Load the row if saving an existing category.
		if ($pk > 0)
		{
			$table->load($pk);
			$isNew = false;
		}

		// Set the new parent id if parent id not matched OR while New/Save as Copy .
		if ($table->parent_id != $data['parent_id'] || $data['id'] == 0)
		{
			$table->setLocation($data['parent_id'], 'last-child');
		}

		// Alter the title for save as copy
		if ($input->get('task') == 'save2copy')
		{
			$origTable = clone $this->getTable();
			$origTable->load($input->getInt('id'));

			if ($data['title'] == $origTable->title)
			{
				list($title, $alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']);
				$data['title'] = $title;
				$data['alias'] = $alias;
			}
			else
			{
				if ($data['alias'] == $origTable->alias)
				{
					$data['alias'] = '';
				}
			}

			$data['published'] = 0;
		}

		// Bind the data.
		if (!$table->bind($data))
		{
			$this->setError($table->getError());

			return false;
		}

		// Bind the rules.
		if (isset($data['rules']))
		{
			$rules = new JAccessRules($data['rules']);
			$table->setRules($rules);
		}

		// Check the data.
		if (!$table->check())
		{
			$this->setError($table->getError());

			return false;
		}

		// Trigger the before save event.
		$result = $dispatcher->trigger($this->event_before_save, array($context, &$table, $isNew));

		if (in_array(false, $result, true))
		{
			$this->setError($table->getError());

			return false;
		}

		// Store the data.
		if (!$table->store())
		{
			$this->setError($table->getError());

			return false;
		}

		$assoc = $this->getAssoc();

		if ($assoc)
		{
			// Adding self to the association
			$associations = isset($data['associations']) ? $data['associations'] : array();

			// Unset any invalid associations
			$associations = Joomla\Utilities\ArrayHelper::toInteger($associations);

			foreach ($associations as $tag => $id)
			{
				if (!$id)
				{
					unset($associations[$tag]);
				}
			}

			// Detecting all item menus
			$all_language = $table->language == '*';

			if ($all_language && !empty($associations))
			{
				JError::raiseNotice(403, JText::_('COM_CATEGORIES_ERROR_ALL_LANGUAGE_ASSOCIATED'));
			}

			// Get associationskey for edited item
			$db    = $this->getDbo();
			$query = $db->getQuery(true)
				->select($db->quoteName('key'))
				->from($db->quoteName('#__languages_associations'))
				->where($db->quoteName('context') . ' = ' . $db->quote($this->associationsContext))
				->where($db->quoteName('id') . ' = ' . (int) $table->id);
			$db->setQuery($query);
			$old_key = $db->loadResult();

			// Deleting old associations for the associated items
			$query = $db->getQuery(true)
				->delete($db->quoteName('#__languages_associations'))
				->where($db->quoteName('context') . ' = ' . $db->quote($this->associationsContext));

			if ($associations)
			{
				$query->where('(' . $db->quoteName('id') . ' IN (' . implode(',', $associations) . ') OR '
					. $db->quoteName('key') . ' = ' . $db->quote($old_key) . ')');
			}
			else
			{
				$query->where($db->quoteName('key') . ' = ' . $db->quote($old_key));
			}

			$db->setQuery($query);

			try
			{
				$db->execute();
			}
			catch (RuntimeException $e)
			{
				$this->setError($e->getMessage());

				return false;
			}

			// Adding self to the association
			if (!$all_language)
			{
				$associations[$table->language] = (int) $table->id;
			}

			if (count($associations) > 1)
			{
				// Adding new association for these items
				$key = md5(json_encode($associations));
				$query->clear()
					->insert('#__languages_associations');

				foreach ($associations as $id)
				{
					$query->values(((int) $id) . ',' . $db->quote($this->associationsContext) . ',' . $db->quote($key));
				}

				$db->setQuery($query);

				try
				{
					$db->execute();
				}
				catch (RuntimeException $e)
				{
					$this->setError($e->getMessage());

					return false;
				}
			}
		}

		// Trigger the after save event.
		$dispatcher->trigger($this->event_after_save, array($context, &$table, $isNew));

		// Rebuild the path for the category:
		if (!$table->rebuildPath($table->id))
		{
			$this->setError($table->getError());

			return false;
		}

		// Rebuild the paths of the category's children:
		if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path))
		{
			$this->setError($table->getError());

			return false;
		}

		$this->setState($this->getName() . '.id', $table->id);

		// Clear the cache
		$this->cleanCache();

		return true;
	}
468428
protected function HLUpdate(array $data)
    {
        $return = [];
        if (empty($data['NAME'])) {
            throw new Exception('You must set NAME');
        }
        if ($id = $this->HLGetIdByCode($data['NAME'])) {
            $arLoad = $data;
            unset($arLoad['LANGS'], $arLoad['RIGHTS'], $arLoad['NAME']);
            if ($arLoad) {
                $result = HighloadBlockTable::update($id, $arLoad);
                if ($result->isSuccess()) {
                    if (!empty($data['LANGS'])) {
                        $this->HLSetLangs($id, $data['LANGS']);
                    }
                    if (!empty($data['RIGHTS'])) {
                        $this->HLSetRights($id, $data['RIGHTS']);
                    }
                    $return[] = "Update {$data['NAME']} ({$id}) highload block";
                } else {
                    throw new Exception("Can't update {$data['NAME']} ({$id}) highload block: " . implode(', ', $result->getErrorMessages()));
                }
            } elseif (!empty($data['RIGHTS'])) {
                $this->HLSetRights($id, $data['RIGHTS']);
            } elseif (!empty($data['LANGS'])) {
                $this->HLSetLangs($id, $data['LANGS']);
            }
        } else {
            throw new Exception("Hl entity with name {$data['NAME']} does not exist");
        }

        return $return;
    }
309236
public function createRole(array $data = [], $permissionIds = '')
    {
        $model = new Role($this->db);
        $model->data($data);
        try{
            $res = $model->saveRole($permissionIds);
            return $res;
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }

    }
314172
protected function saveEntity($data)
    {
        $entityManager = $this->getManagerForEntity($data);
        $entityManager->persist($data);
        $entityManager->flush();

        $action = $this->admin->getCurrentAction();
        $this->addFlash('success', $this->translate("admin.flash.{$action->getCode()}.success"));
    }
718417
public static function in($data, $whiteList)
    {
        if ($data) {
            if (is_object($data)) {
                $data = get_object_vars($data);
            }
            $whiteList = array_flip($whiteList);

            //Filter
            foreach ($data as $key => $value) {
                if (is_object($value)) {
                    $value = get_object_vars($value);
                }
                $data[$key] = array_intersect_key($value, $whiteList);
            }
        }
        return $data;
    }
932701
protected function guardAgainstNull(
        $data,
        $dataName = 'Argument',
        $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException'
    ) {
        if (null === $data) {
            $message = sprintf('%s cannot be null', $dataName);
            throw new $exceptionClass($message);
        }
    }
1233917
public function put($data)
	{
		if( ! $data instanceof DataTransferObject)
		{
			throw new Exception('You are trying to put invalid object to trunk.');
		}

		if( ! array_key_exists($data->getType(), $this->storage) )
		{
			$this->storage[$data->getType()] = [];
		}

		$storageKey = $this->storageKey($data->getParams());
		$this->storage[$data->getType()][$storageKey] = $data;
	}
950823
private function persistRecord(array $data, array $fillable = array(), $set)
    {
        if (!empty($fillable) && !ArrayUtils::keysExist($data, $fillable)) {
            throw new LogicException('Can not persist the entity due to fillable protection. Make sure all fillable keys exist in the entity');
        }

        $this->validateShortcutData();

        if (isset($data[$this->getPk()]) && $data[$this->getPk()]) {
            $result = $this->db->update(static::getTableName(), $data)
                               ->whereEquals($this->getPk(), $data[$this->getPk()])
                               ->execute();

            return $set === true ? $data : $result;

        } else {
            // Do not insert primary key if present
            if (array_key_exists($this->getPk(), $data)) {
                unset($data[$this->getPk()]);
            }

            // Insert a new row without PK
            $result = $this->db->insert(static::getTableName(), $data)
                               ->execute();

            if ($set === true) {
                // Append a PK in result-set now
                $data[$this->getPk()] = $this->getMaxId();
                return $data;
            } else {
                return $result;
            }
        }
    }
573437
public function save($eloquent, UpdateRequest $request)
    {
        $saver = app('scaffold.module')->saver();
        $saver = new $saver($eloquent, $request);

        if (!$saver instanceof Saver) {
            throw new Exception('Saver must implement '.Saver::class.' contract');
        }

        return $saver->sync();
    }
872294
function save($parent_id = 0, $requestedSaveId = null, $createDefinition = true)
    {
        if ('' == trim($this->getTitle())) {
            throw new Exception('Must have a non blank title to save ' . $this->getType());
        }
        $levelId = $this->findEntityIdByTitle();
        if ($levelId) {
            $this->id = $levelId;
            return $levelId;
        }
        if ($requestedSaveId && $this->requestedIdCorrespondsToExistingRecord($requestedSaveId)) {
            $this->id = $requestedSaveId;
        }
        if ($this->getId()) {
            $sql = sprintf(
                "UPDATE %s SET `title` = %s WHERE id = %d",
                $this->getReadAdapter()->quoteIdentifier($this->getTable()),
                $this->getReadAdapter()->quote($this->getTitle()),
                (int)$this->getId()
            );
            $this->query($sql);
            return $this->id;
        }
        $data = array('title' => $this->getTitle());
        if ($requestedSaveId) {
            $data['id'] = $requestedSaveId;
        }
        $this->getReadAdapter()->insert($this->getTable(), $data);
        $levelId = $this->getReadAdapter()->lastInsertId();
        $this->setId($levelId);
        return $levelId;
    }
660468
public static function isWhitelisted(Request $request, array $whiteList)
    {
        if (!\array_key_exists($request->getRequestMethod(), $whiteList)) {
            return false;
        }

        return \in_array($request->getPathInfo(), $whiteList[$request->getRequestMethod()], true);
    }
1225828
public static function allow(array $whitelist) : Validator\Any
    {
        return self::any()->should(
            function ($value) use ($whitelist) : bool {
                foreach ($whitelist as $candidate) {
                    if ($candidate === $value) {
                        return true;
                    }
                }

                return false;
            },
            'not in the whitelist'
        );
    }
329176
protected function save( $contents ) {
		if ( ! trim( $contents ) ) {
			throw new Exception( 'Cannot save the config file with empty contents.' );
		}

		if ( $contents === $this->wp_config_src ) {
			return false;
		}

		$result = file_put_contents( $this->wp_config_path, $contents, LOCK_EX );

		if ( false === $result ) {
			throw new Exception( 'Failed to update the config file.' );
		}

		return true;
	}
796243
public function save($data=null)
    {
        if ( is_null($data)) {
            throw new \Exception('There is no data to save.');
        }

        $filter = array();
        if (isset($data['id'])) {
            $filter['id'] = $data['id'];
        }

        try {

            // check if exists record
            $entity = $this->getEntity($filter);
            if (!empty($filter['id']) && empty($entity)) {
                throw new \Exception("Role not found.");
            }
            $entity->setActive($data['active']);
            $entity->setName($data['name']);

            $_id = $entity->getId();
            if (isset($_id) && ($_id > 0)) {
                $this->_em->merge($entity);
            } else {
                $this->_em->persist($entity);
            }
            $this->_em->flush();
            $_id = $entity->getId();
        } catch (\Exception $e){
            \error_log($e->getMessage());
            throw new \Exception($e->getMessage());
        }
        return $_id;
    }