inclusion_of.php 779 Bytes
Newer Older
1 2
<?php namespace System\Validation\Rules;

3
use System\Validation\Nullable_Rule;
4

5
class Inclusion_Of extends Nullable_Rule {
6 7 8 9 10 11 12 13 14 15 16 17 18

	/**
	 * The accepted values for the attribute.
	 *
	 * @var string
	 */
	public $accepted;

	/**
	 * Evaluate the validity of an attribute.
	 *
	 * @param  string  $attribute
	 * @param  array   $attributes
19
	 * @return bool
20 21 22
	 */
	public function check($attribute, $attributes)
	{
23
		if ( ! is_null($nullable = parent::check($attribute, $attributes)))
24
		{
25
			return $nullable;
26 27 28 29 30 31 32 33
		}

		return in_array($attributes[$attribute], $this->accepted);
	}	

	/**
	 * Set the accepted values for the attribute.
	 *
34
	 * @param  array         $accepted
35 36 37 38 39 40 41 42 43
	 * @return Inclusion_Of
	 */
	public function in($accepted)
	{
		$this->accepted = $accepted;
		return $this;
	}

}