Commit 9e46cada authored by Taylor Otwell's avatar Taylor Otwell

Minor refactoring of the Validator. Mainly code formatting and naming changes.

parent ed092bf6
...@@ -38,7 +38,7 @@ class Validator { ...@@ -38,7 +38,7 @@ class Validator {
* *
* @var Database\Connection * @var Database\Connection
*/ */
protected $connection; protected $db;
/** /**
* The language that should be used when retrieving error messages. * The language that should be used when retrieving error messages.
...@@ -160,9 +160,9 @@ class Validator { ...@@ -160,9 +160,9 @@ class Validator {
$value = Arr::get($this->attributes, $attribute); $value = Arr::get($this->attributes, $attribute);
if ( ! $this->validatable($rule, $attribute, $value)) return; $validatable = $this->validatable($rule, $attribute, $value);
if ( ! $this->{'validate_'.$rule}($attribute, $value, $parameters, $this)) if ($validatable and ! $this->{'validate_'.$rule}($attribute, $value, $parameters, $this))
{ {
$this->error($attribute, $rule, $parameters); $this->error($attribute, $rule, $parameters);
} }
...@@ -182,7 +182,18 @@ class Validator { ...@@ -182,7 +182,18 @@ class Validator {
*/ */
protected function validatable($rule, $attribute, $value) protected function validatable($rule, $attribute, $value)
{ {
return ($this->validate_required($attribute, $value) or in_array($rule, array('required', 'accepted'))); return $this->validate_required($attribute, $value) or $this->implicit($rule);
}
/**
* Determine if a given rule implies that the attribute is required.
*
* @param string $rule
* @return bool
*/
protected function implicit($rule)
{
return $rule == 'required' or $rule == 'accepted';
} }
/** /**
...@@ -401,9 +412,9 @@ class Validator { ...@@ -401,9 +412,9 @@ class Validator {
{ {
if ( ! isset($parameters[1])) $parameters[1] = $attribute; if ( ! isset($parameters[1])) $parameters[1] = $attribute;
if (is_null($this->connection)) $this->connection = DB::connection(); if (is_null($this->db)) $this->db = DB::connection();
return $this->connection->table($parameters[0])->where($parameters[1], '=', $value)->count() == 0; return $this->db->table($parameters[0])->where($parameters[1], '=', $value)->count() == 0;
} }
/** /**
...@@ -678,7 +689,7 @@ class Validator { ...@@ -678,7 +689,7 @@ class Validator {
*/ */
public function connection(\Laravel\Database\Connection $connection) public function connection(\Laravel\Database\Connection $connection)
{ {
$this->connection = $connection; $this->db = $connection;
return $this; return $this;
} }
...@@ -697,4 +708,4 @@ class Validator { ...@@ -697,4 +708,4 @@ class Validator {
throw new \BadMethodCallException("Call to undefined method [$method] on Validator instance."); throw new \BadMethodCallException("Call to undefined method [$method] on Validator instance.");
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment