Validates and saves record to disk.
@param array $data
184351
public function save(array $data)
    {
        if (!$this->getModel()->isSingle()) {
            $id = $data['id'] ?? $this->id;
            $this->id = $id;
        }

        $columns = $this->data;
        foreach ($columns as $key => $column) {
            if (array_key_exists($key, $data)) {
                $column->setValue($data[$key]);
            } else {
                $column->setValue(null);
            }
        }

        $yaml = Yaml::dump($this->getData(), 5, 4, YAML::DUMP_MULTI_LINE_LITERAL_BLOCK | YAML::DUMP_OBJECT_AS_MAP);

        $fs = new Filesystem();
        $fs->dumpFile($this->getContentFilePath(), $yaml);
    }
1152954
public function is_valid(array $data) {

		$this->data = $this->apply_filters($data);

		$this->errors = $this->test_rules();

		return empty($this->errors);

	}
1233131
public function save(array $data)
    {
        $project_id = empty($data['project_id']) ? 0: (int) $data['project_id'];
        if ($project_id <= 0) {
            throw new Exception('Required field project_id');
        }
        if (empty($data['pending_file_ref']) && empty($data['filename'])) {
            throw new Exception('Required field pending_file_ref or filename');
        }
        if (empty($data['pending_file_ref'])) {
            $data['pending_file_ref'] = $this->upload($data['filename']);
        }
        unset($data['filename']);
        return $this->rest->post("projects/$project_id/files", $data);
    }
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"));
    }
317373
public function save($id, array $data)
    {
        if(!empty($id) && (is_string($id) || is_numeric($id))) {
            $this->setFile($id);
            if ($this->file) {
                if (file_exists($this->file)) {
                    $this->update($id, $data);
                } else {
                    $this->add($id, $data);
                }
            }
        }
    }
708332
public function validate(array $data)
    {
        $rules = $this->getRules();
        foreach ($rules as $field => $rule) {
            if ((isset($rule['required']) && $rule['required'] === true && isset($data[$field]))
                || ((!isset($rule['required']) || !$rule['required'])) && isset($data[$field])) {
                foreach ($rule as $key => $value) {
                    if ($key !== 'required') {
                        foreach ($value as $validator) {
                            if (!is_array($validator)) {
                                $validator = [$validator];
                            }
                            if (!Validator::validate($validator[0], $field,
                                    $data, $validator)) {
                                $this->addError($field,
                                    isset($rule['errorMessage']) ? $rule['errorMessage']
                                            : false);
                            }
                        }
                    }
                }
            } elseif (isset($rule['required']) && $rule['required'] === true) {
                $this->addError($field,
                    isset($rule['errorMessage']) ? $rule['errorMessage'] : false);
            }
        }
        return !$this->hasErrors();
    }
822933
private function setData($data) {
        $this->indcheck = $data[0];
        $this->data = $data[1];
        $this->calculateChecksum();
    }
934210
public function validate( $data, array $rules = [] )
	{
		$this->normalizeData( $data );
		$this->setRules( $rules );

		foreach( $this->rules as $attribute => $rules ) {
			foreach( $rules as $rule ) {
				$this->validateAttribute( $rule, $attribute );

				if( $this->shouldStopValidating( $attribute ))break;
			}
		}

		return $this->errors;
	}
210716
public function updateData(array $data) {
        foreach($data as $name => $value) {
            $this->data[$name] = $value;
        }
    }
773905
public static function store($data)
    {
        // return errors if there are any
        $errorMessages = self::validateStore($data);
        if(count($errorMessages)) {
            return array('error' => true, 'data' => [], 'errorMessages' => $errorMessages, 'noty' => []);
        }

        // Set posts table
        $postObj = new Post();
        $postObj->setTable($data['postType']);
        $postType = PostType::findBySlug($data['postType']);

        // on create
        if(!isset($data['postID'])) {
            $populatedFields = self::populateStoreColumns($postObj, $data);
            $populatedFields['post']->createdByUserID = (!User::isAdmin() || !isset($data['createdByUserID'])) ? Auth::user()->userID : $data['createdByUserID'];
            $postObj = $populatedFields['post'];

            if(!$postObj->save()) {
                throw new \Exception("Post could not be saved");
            }

            $postID = $postObj->postID;
        }else{ // on update
            $postObj = $postObj->where('postID', $data['postID'])->first();

            if($postObj) {
                $populatedFields = self::populateStoreColumns($postObj, $data);
                $populatedFields['post']->createdByUserID = (!User::isAdmin() || !isset($data['createdByUserID'])) ? Auth::user()->userID : $data['createdByUserID'];
                $postObj = $populatedFields['post'];

                if($postObj->save()) {
                    // Delete existing relations, to ensure accuracy
                    if($postType->hasCategories) {
                        DB::table($data['postType'].'_categories')->where("postID", $data['postID'])->delete();
                    }

                    if($postType->hasTags) {
                        DB::table($data['postType'].'_tags')->where("postID", $data['postID'])->delete();
                    }
                    DB::table($data['postType'].'_media')->where("postID", $data['postID'])->delete();
                }

                $postID = $postObj->postID;
            }else{
                throw new \Exception("Trying to edit a post that doesn't exist!");
            }
        }

        if($postID) {
            if($postType->hasCategories) {
                // Insert categories
                self::insertCategories($data['selectedCategories'], $postObj->postID, $data['postType']);
            }

            if($postType->hasTags) {
                // Insert tags
                self::insertTags($data['selectedTags'], $postObj->postID, $postType);
            }

            // Insert media
            self::insertMedia($data['files'], $postObj->postID, $data['postType'], $data['languages'], $populatedFields['files'], $data['filesToBeIgnored']);

            // Event fired after post is stored
            Event::fire('post:stored', [$data, $postObj]);

            return [
              'error' => false,
              'postID' => $postID,
              'postType' => $data['postType'],
              'noty' => $postObj->getNotyMessages()
            ];
        }else{
            return [
              'error' => true,
              'errorMessages' => $errorMessages,
              'noty' => $postObj->getNotyMessages()
            ];
        }
    }
1060058
public function upload(array $data)
    {
        $content = $this->readCSV($data);
        if ($content === false) {
            return false;
        }

        $return = $this->writeFile($data['locale'], $content, 'csv');
        if ($return === false) {
            return false;
        }

        return $this->activeTranslate($data['locale']);

    }
1043030
public function php($data)
    {
        foreach ($this->fieldNames as $fieldName) {
            if (empty($data[$fieldName])) {
                return;
            }

            $this->validateField($fieldName, $data[$fieldName]);
        }
    }
700700
public function validateResponseData($data)
    {
        if (!isset($data->status)) {
            throw EventValidationResponseCorruptDataException::eventApiResponseCorrupt($data);
        } elseif (isset($data->errors)) {
            throw EventValidationResponseErrorException::eventApiResponseError($data->errors[0]);
        }
    }
205743
public function validate( array $data ) {
		// Validate use Validator.
		try {
			$this->validate_use_validator( $data, $this->get_validate_rules() );
		} catch ( \Exception $e ) {
			trigger_error( $e->getMessage(), E_USER_WARNING ); // @WPCS: XSS OK.
		}

		// Validate use custom callback.
		$callbacks = $this->fields->pluck( 'validate_cb', 'id' )->filter( 'is_callable' );

		if ( $callbacks->isNotEmpty() ) {
			$this->validate_by_callbacks( $data, $callbacks->all() );
		}
	}
1208989
private function validate($data)
    {
        // null or zero-length values cannot be assigned references
        if (is_null($data) || (is_string($data) && !strlen($data))) {
            return false;
        }

        return true;
    }
1202133
private function setData(array $data)
    {
        $this->data = (array) $data;

        // remove reserved stuff
        if (isset($this->data[self::VAR_CONTROLLER])) {
            unset($this->data[self::VAR_CONTROLLER]);
        }

        return !empty($this->data);
    }
484130
public function resetData(array $data)
    {
        $this->data = $data;
        if ($this->existsKey('uid')) {
            if (!$this->hasUid()) {
                $this->setUid((int)$this->data['uid']);
            }
            unset($this->data['uid']);
        }

        $this->markAsLoaded();
        if ($this->hasUid()) {
            $this->markAsClean();
        } else {
            $this->markAsDirty();
        }
    }