Assert\Assertion::choice PHP Method

choice() public static method

Assert that value is in array of choices.
public static choice ( mixed $value, array $choices, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$choices array
$message string | null
$propertyPath string | null
return boolean
    public static function choice($value, array $choices, $message = null, $propertyPath = null)
    {
        if (!in_array($value, $choices, true)) {
            $message = sprintf($message ?: 'Value "%s" is not an element of the valid values: %s', static::stringify($value), implode(", ", array_map('Assert\\Assertion::stringify', $choices)));
            throw static::createException($value, $message, static::INVALID_CHOICE, $propertyPath, array('choices' => $choices));
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param string $direction
  * @param int $days
  */
 public function __construct($direction, $days)
 {
     Assertion::integerish($days);
     Assertion::choice($direction, [self::DIRECTION_PAST, self::DIRECTION_FUTURE]);
     $this->direction = $direction;
     $this->days = (int) $days;
 }
All Usage Examples Of Assert\Assertion::choice