Skip to content

Commit

Permalink
Merge pull request #2268 from jim-parry/validation-session
Browse files Browse the repository at this point in the history
Validation session use only if exists
  • Loading branch information
MGatner authored Sep 26, 2019
2 parents 56717ad + defc573 commit 1fa1e10
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* CodeIgniter
*
Expand Down Expand Up @@ -100,6 +99,7 @@ class Validation implements ValidationInterface
* @var \Config\Validation
*/
protected $config;

/**
* The view renderer used to render validation messages.
*
Expand Down Expand Up @@ -275,8 +275,7 @@ protected function processRules(string $field, string $label = null, $value, $ru

$found = true;

$passed = $param === false ? $set->$rule($value, $error)
: $set->$rule($value, $param, $data, $error);
$passed = $param === false ? $set->$rule($value, $error) : $set->$rule($value, $param, $data, $error);
break;
}

Expand All @@ -291,8 +290,7 @@ protected function processRules(string $field, string $label = null, $value, $ru
// Set the error message if we didn't survive.
if ($passed === false)
{
$this->errors[$field] = is_null($error) ? $this->getErrorMessage($rule, $field, $label, $param)
: $error;
$this->errors[$field] = is_null($error) ? $this->getErrorMessage($rule, $field, $label, $param) : $error;

return false;
}
Expand Down Expand Up @@ -493,7 +491,7 @@ public function listErrors(string $template = 'list'): string
}

return $this->view->setVar('errors', $this->getErrors())
->render($this->config->templates[$template]);
->render($this->config->templates[$template]);
}

//--------------------------------------------------------------------
Expand All @@ -519,7 +517,7 @@ public function showError(string $field, string $template = 'single'): string
}

return $this->view->setVar('error', $this->getError($field))
->render($this->config->templates[$template]);
->render($this->config->templates[$template]);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -648,13 +646,7 @@ public function getErrors(): array
// passed along from a redirect_with_input request.
if (empty($this->errors) && ! is_cli())
{
// Start up the session if it's not already
if (! isset($_SESSION))
{
session();
}

if ($errors = session('_ci_validation_errors'))
if (isset($_SESSION) && session('_ci_validation_errors'))
{
$this->errors = unserialize($errors);
}
Expand Down Expand Up @@ -724,15 +716,15 @@ protected function splitRules(string $rules): array
{
$non_escape_bracket = '((?<!\\\\)(?:\\\\\\\\)*[\[\]])';
$pipe_not_in_bracket = sprintf(
'/\|(?=(?:[^\[\]]*%s[^\[\]]*%s)*(?![^\[\]]*%s))/',
$non_escape_bracket,
$non_escape_bracket,
$non_escape_bracket
'/\|(?=(?:[^\[\]]*%s[^\[\]]*%s)*(?![^\[\]]*%s))/',
$non_escape_bracket,
$non_escape_bracket,
$non_escape_bracket
);

$_rules = preg_split(
$pipe_not_in_bracket,
$rules
$pipe_not_in_bracket,
$rules
);

return array_unique($_rules);
Expand Down

0 comments on commit 1fa1e10

Please sign in to comment.