1 | <?php |
||
56 | class IsCompatibleWith |
||
57 | { |
||
58 | use LookupMethodByType; |
||
59 | |||
60 | /** |
||
61 | * is $data compatible with $constraint? |
||
62 | * |
||
63 | * @param mixed $data |
||
64 | * the object to check |
||
65 | * @param string|object $constraint |
||
66 | * @return boolean |
||
67 | * TRUE if $data is compatible |
||
68 | * FALSE otherwise |
||
69 | */ |
||
70 | public function __invoke($data, $constraint) |
||
74 | |||
75 | /** |
||
76 | * is $data compatible with $constraint? |
||
77 | * |
||
78 | * @param mixed $data |
||
79 | * the object to check |
||
80 | * @param string|object $constraint |
||
81 | * @return boolean |
||
82 | * TRUE if $data is compatible |
||
83 | * FALSE otherwise |
||
84 | */ |
||
85 | public static function check($data, $constraint) |
||
90 | |||
91 | /** |
||
92 | * is $data compatible with $constraint? |
||
93 | * |
||
94 | * @param object $data |
||
95 | * the object to check |
||
96 | * @param string|object $constraint |
||
97 | * the class or object that $data must be compatible with |
||
98 | * @return boolean |
||
99 | * TRUE if $data is compatible |
||
100 | * FALSE otherwise |
||
101 | */ |
||
102 | public static function checkObject($data, $constraint) |
||
111 | |||
112 | /** |
||
113 | * is $data compatible with $constraint? |
||
114 | * |
||
115 | * @param string $data |
||
116 | * the class name to check |
||
117 | * @param string|object $constraint |
||
118 | * the class or object that $data must be compatible with |
||
119 | * @return boolean |
||
120 | * TRUE if $data is compatible |
||
121 | * FALSE otherwise |
||
122 | */ |
||
123 | public static function checkString($data, $constraint) |
||
142 | |||
143 | /** |
||
144 | * called when $data is a data type that we do not support |
||
145 | * |
||
146 | * @param mixed $data |
||
147 | * @return void |
||
148 | */ |
||
149 | public static function nothingMatchesTheInputType($data) |
||
153 | |||
154 | /** |
||
155 | * our lookup table of which method to call for which supported data type |
||
156 | * @var array |
||
157 | */ |
||
158 | private static $dispatchTable = [ |
||
159 | 'Object' => 'checkObject', |
||
160 | 'String' => 'checkString', |
||
161 | ]; |
||
162 | } |
||
163 |