Skip to content

Commit

Permalink
Merge pull request #14 from Jaspaul/master
Browse files Browse the repository at this point in the history
Add Support For Laravel 5.0
  • Loading branch information
Chris Hayes committed Mar 1, 2015
2 parents 3a4100d + ed9d2d3 commit 3b53d0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "~4.1",
"illuminate/http": "~4.1",
"illuminate/validation": "~4.1"
"illuminate/support": "~5.0",
"illuminate/http": "~5.0",
"illuminate/validation": "~5.0",
"illuminate/contracts": "~5.0"
},
"require-dev": {
"mockery/mockery": "0.7.*"
Expand Down
48 changes: 24 additions & 24 deletions src/Crhayes/Validation/ContextualValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,61 @@

use Crhayes\Validation\Exceptions\ReplacementBindingException;
use Crhayes\Validation\Exceptions\ValidatorContextException;
use Illuminate\Support\Contracts\MessageProviderInterface;
use Illuminate\Contracts\Support\MessageProvider;
use Input;
use Validator;

abstract class ContextualValidator implements MessageProviderInterface
abstract class ContextualValidator implements MessageProvider
{
const DEFAULT_KEY = 'default';

/**
* Store the attributes we are validating.
*
*
* @var array
*/
protected $attributes = array();

/**
* Store the validation rules.
*
*
* @var array
*/
protected $rules = array();

/**
* Store any custom messages for validation rules.
*
*
* @var array
*/
protected $messages = array();

/**
* Store any contexts we are validating within.
*
*
* @var array
*/
protected $contexts = array();

/**
* Store replacement values for any bindings in our rules.
*
*
* @var array
*/
protected $replacements = array();

/**
* Store any validation messages generated.
*
*
* @var array
*/
protected $errors = array();

/**
* Our constructor will store the attributes we are validating, and
* may also take as a second parameter the contexts within which
* may also take as a second parameter the contexts within which
* we are validating.
*
*
* @param array $attributes
* @param mixed $context
*/
Expand All @@ -71,7 +71,7 @@ public function __construct($attributes = null, $context = null)

/**
* Static shorthand for creating a new validator.
*
*
* @param mixed $validator
* @return Crhayes\Validation\GroupedValidator
*/
Expand All @@ -83,7 +83,7 @@ public static function make($attributes = null, $context = null)
/**
* Stub method that can be extended by child classes.
* Passes a validator object and allows for adding complex conditional validations.
*
*
* @param \Illuminate\Validation\Validator $validator
*/
protected function addConditionalRules($validator) {}
Expand Down Expand Up @@ -113,13 +113,13 @@ public function getAttributes()

/**
* Add a validation context.
*
*
* @param array $context
*/
public function addContext($context)
{
$context = is_array($context) ? $context : array($context);

$this->contexts = array_merge($this->contexts, $context);

return $this;
Expand All @@ -140,7 +140,7 @@ public function setContext($context)

/**
* Retrieve the valiation context.
*
*
* @return array
*/
public function getContexts()
Expand All @@ -150,7 +150,7 @@ public function getContexts()

/**
* Bind a replacement value to a placeholder in a rule.
*
*
* @param string $field
* @param array $replacement
* @return Crhayes\Validation\ContextualValidator
Expand All @@ -164,7 +164,7 @@ public function bindReplacement($field, array $replacement)

/**
* Get a bound replacement by key.
*
*
* @param string $key
* @return array
*/
Expand All @@ -175,7 +175,7 @@ public function getReplacement($key)

/**
* Perform a validation check against our attributes.
*
*
* @return boolean
*/
public function passes()
Expand Down Expand Up @@ -215,7 +215,7 @@ public function getMessageBag()

/**
* Return any errors.
*
*
* @return Illuminate\Support\MessageBag
*/
public function errors()
Expand All @@ -227,7 +227,7 @@ public function errors()

/**
* Get the validaton rules within the context of the current validation.
*
*
* @return array
*/
protected function getRulesInContext()
Expand All @@ -242,8 +242,8 @@ protected function getRulesInContext()
{
throw new ValidatorContextException(
sprintf(
"'%s' does not contain the validation context '%s'",
get_called_class(),
"'%s' does not contain the validation context '%s'",
get_called_class(),
$context
)
);
Expand All @@ -258,7 +258,7 @@ protected function getRulesInContext()
/**
* Spin through our contextual rules array and bind any replacement
* values to placeholders within the rules.
*
*
* @param array $rules
* @return array
*/
Expand Down Expand Up @@ -296,7 +296,7 @@ protected function bindReplacements($rules)

/**
* Check if the current validation has a context.
*
*
* @return boolean
*/
protected function hasContext()
Expand Down
24 changes: 12 additions & 12 deletions src/Crhayes/Validation/GroupedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
namespace Crhayes\Validation;

use Crhayes\Validation\Exceptions\MissingValidatorException;
use Illuminate\Support\Contracts\MessageProviderInterface;
use Illuminate\Contracts\Support\MessageProvider;

class GroupedValidator
{
/**
* An array of Validator objects we will spin through
* when running our grouped validation.
*
*
* @var array
*/
protected $validators = array();

/**
* An array of errors returned from all of the validators.
*
*
* @var array
*/
protected $errors = array();

/**
* Create a new GroupedValidator, with the option of specifying
* either a single validator object or an array of validators.
*
*
* @param mixed $validator
*/
public function __construct($validator = array())
Expand All @@ -35,7 +35,7 @@ public function __construct($validator = array())

/**
* Static shorthand for creating a new grouped validator.
*
*
* @param mixed $validator
* @return Crhayes\Validation\GroupedValidator
*/
Expand All @@ -47,21 +47,21 @@ public static function make($validator = array())
/**
* Add a validator to spin through. Accepts either a single
* Validator object or an array of validators.
*
*
* @param mixed $validator
*/
public function addValidator(MessageProviderInterface $validator)
public function addValidator(MessageProvider $validator)
{
$validator = is_array($validator) ? $validator : array($validator);

$this->validators = array_merge($this->validators, $validator);

return $this;
}

/**
* Perform a check to see if all of the validators have passed.
*
*
* @return boolean
*/
public function passes()
Expand All @@ -78,10 +78,10 @@ public function passes()

return (count($this->errors)) ? false : true;
}

/**
* Perform a check to see if any of the validators have failed.
*
*
* @return boolean
*/
public function fails()
Expand All @@ -91,7 +91,7 @@ public function fails()

/**
* Return the combined errors from all validators.
*
*
* @return Illuminate\Support\MessageBag
*/
public function errors()
Expand Down

0 comments on commit 3b53d0d

Please sign in to comment.