refactoring and adding more dependency injection through ioc container.

This commit is contained in:
Taylor Otwell
2011-08-24 22:51:32 -05:00
parent 99adf09ac7
commit 6a8aafc259
46 changed files with 1039 additions and 1276 deletions

View File

@@ -37,6 +37,13 @@ class Validator {
*/
public $language;
/**
* The database connection that should be used by the validator.
*
* @var DB\Connection
*/
public $connection;
/**
* The size related validation rules.
*
@@ -302,7 +309,9 @@ class Validator {
{
if ( ! isset($parameters[1])) $parameters[1] = $attribute;
return DB::connection()->table($parameters[0])->where($parameters[1], '=', $this->attributes[$attribute])->count() == 0;
if (is_null($this->connection)) $this->connection = DB::connection();
return $this->connection->table($parameters[0])->where($parameters[1], '=', $this->attributes[$attribute])->count() == 0;
}
/**
@@ -514,4 +523,16 @@ class Validator {
return $this;
}
/**
* Set the database connection that should be used by the validator.
*
* @param DB\Connection $connection
* @return Validator
*/
public function connection(DB\Connection $connection)
{
$this->connection = $connection;
return $this;
}
}