|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
|
4
|
|
|
* Date: 9/16/14 |
|
5
|
|
|
* Time: 10:19 PM |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace NilPortugues\Validator\Validation\Object; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class ObjectValidation |
|
15
|
|
|
* @package NilPortugues\Validator\Validation\ObjectAttribute |
|
16
|
|
|
*/ |
|
17
|
|
|
class ObjectValidation |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param $value |
|
21
|
|
|
* |
|
22
|
|
|
* @return bool |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function isObject($value) |
|
25
|
|
|
{ |
|
26
|
|
|
return \is_object($value); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param mixed $value |
|
31
|
|
|
* @param string $instanceOf |
|
32
|
|
|
* |
|
33
|
|
|
* @return bool |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function isInstanceOf($value, $instanceOf) |
|
36
|
|
|
{ |
|
37
|
|
|
return $value instanceof $instanceOf; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param \Tests\NilPortugues\Validator\Resources\Dummy $value |
|
42
|
|
|
* @param string $property |
|
43
|
|
|
* |
|
44
|
|
|
* @return bool |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function hasProperty($value, $property) |
|
47
|
|
|
{ |
|
48
|
|
|
return \is_object($value) && \property_exists(\get_class($value), $property); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param \Tests\NilPortugues\Validator\Resources\Dummy $value |
|
53
|
|
|
* @param string $method |
|
54
|
|
|
* |
|
55
|
|
|
* @return bool |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function hasMethod($value, $method) |
|
58
|
|
|
{ |
|
59
|
|
|
return \is_object($value) && \method_exists(\get_class($value), $method); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param $value |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function hasParentClass($value) |
|
68
|
|
|
{ |
|
69
|
|
|
return \is_object($value) && \get_parent_class($value) !== false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param \Tests\NilPortugues\Validator\Resources\Dummy $value |
|
74
|
|
|
* @param string $parentClass |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function isChildOf($value, $parentClass) |
|
79
|
|
|
{ |
|
80
|
|
|
return \is_object($value) && \get_parent_class($value) === $parentClass; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param \Tests\NilPortugues\Validator\Resources\Dummy $value |
|
85
|
|
|
* @param string $inheritsClass |
|
86
|
|
|
* |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
|
|
public static function inheritsFrom($value, $inheritsClass) |
|
90
|
|
|
{ |
|
91
|
|
|
return \is_object($value) && \is_subclass_of($value, $inheritsClass); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param \Tests\NilPortugues\Validator\Resources\Dummy $value |
|
96
|
|
|
* @param string $interface |
|
97
|
|
|
* |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
public static function hasInterface($value, $interface) |
|
101
|
|
|
{ |
|
102
|
|
|
return \is_object($value) && \in_array($interface, \class_implements($value)); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|