1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.9.8 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Validation\Traits; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Trait Lists |
19
|
|
|
* @package Quantum\Libraries\Validation\Rules |
20
|
|
|
*/ |
21
|
|
|
trait Lists |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Validates that the field value is contained within a given string. |
26
|
|
|
* @param string $field |
27
|
|
|
* @param string $value |
28
|
|
|
* @param string $haystack |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
protected function contains(string $field, string $value, string $haystack): bool |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$value = trim(strtolower($value)); |
34
|
|
|
$haystack = trim(strtolower($haystack)); |
35
|
|
|
|
36
|
|
|
return strpos($haystack, $value) !== false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Verifies that a value is contained within the pre-defined value set. |
41
|
|
|
* @param string $field |
42
|
|
|
* @param string $value |
43
|
|
|
* @param string ...$list |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
protected function containsList(string $field, string $value, string ...$list): bool |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$value = trim(strtolower($value)); |
49
|
|
|
|
50
|
|
|
$list = array_map(function ($item) { |
51
|
|
|
return trim(strtolower($item)); |
52
|
|
|
}, $list); |
53
|
|
|
|
54
|
|
|
return in_array($value, $list); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Verifies that a value is not contained within the pre-defined value set. |
59
|
|
|
* @param string $field |
60
|
|
|
* @param string $value |
61
|
|
|
* @param string ...$list |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
protected function doesntContainsList(string $field, string $value, string ...$list): bool |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$value = trim(strtolower($value)); |
67
|
|
|
|
68
|
|
|
$list = array_map(function ($item) { |
69
|
|
|
return trim(strtolower($item)); |
70
|
|
|
}, $list); |
71
|
|
|
|
72
|
|
|
return !in_array($value, $list); |
73
|
|
|
} |
74
|
|
|
} |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.