Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(Validator): Add autoload from requests function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 7, 2019
1 parent 4442bb7 commit 16825fc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions framework/Validators/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Validator extends BaseObject
/** @var boolean */
protected $_success;

protected $_autoload_data = false;
protected $_autoload_data_from = [];

public function onConstruct()
{
$this->_validator = new \Sirius\Validation\Validator;
Expand Down Expand Up @@ -139,8 +142,18 @@ final protected function releaseDataToProperties()
$this->buildDefaultPropAfterValid();
}

private function autoloadDataFromRequests()
{
if ($this->_autoload_data) {
if (in_array('get', $this->_autoload_data_from)) $this->setData(app()->request->get());
if (in_array('post', $this->_autoload_data_from)) $this->setData(app()->request->post());
if (in_array('files', $this->_autoload_data_from)) $this->setFileData(app()->request->files());
}
}

public function validate()
{
$this->autoloadDataFromRequests();
$this->buildDefaultDataForValid();

// validate rules in static::inputRules()
Expand Down Expand Up @@ -182,4 +195,6 @@ public function flush()
{
throw new \RuntimeException('No flush function exist');
}


}

0 comments on commit 16825fc

Please sign in to comment.