DoesntContain.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Illuminate\Validation\Rules;
  3. use Illuminate\Contracts\Support\Arrayable;
  4. use Stringable;
  5. use function Illuminate\Support\enum_value;
  6. class DoesntContain implements Stringable
  7. {
  8. /**
  9. * The values that should be contained in the attribute.
  10. *
  11. * @var array
  12. */
  13. protected $values;
  14. /**
  15. * Create a new doesntContain rule instance.
  16. *
  17. * @param \Illuminate\Contracts\Support\Arrayable|\UnitEnum|array|string $values
  18. */
  19. public function __construct($values)
  20. {
  21. if ($values instanceof Arrayable) {
  22. $values = $values->toArray();
  23. }
  24. $this->values = is_array($values) ? $values : func_get_args();
  25. }
  26. /**
  27. * Convert the rule to a validation string.
  28. *
  29. * @return string
  30. */
  31. public function __toString()
  32. {
  33. $values = array_map(function ($value) {
  34. $value = enum_value($value);
  35. return '"'.str_replace('"', '""', $value).'"';
  36. }, $this->values);
  37. return 'doesnt_contain:'.implode(',', $values);
  38. }
  39. }