1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2016-present Ganbaro Digital Ltd |
5
|
|
|
* All rights reserved. |
6
|
|
|
* |
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
8
|
|
|
* modification, are permitted provided that the following conditions |
9
|
|
|
* are met: |
10
|
|
|
* |
11
|
|
|
* * Redistributions of source code must retain the above copyright |
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
13
|
|
|
* |
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
16
|
|
|
* the documentation and/or other materials provided with the |
17
|
|
|
* distribution. |
18
|
|
|
* |
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
20
|
|
|
* contributors may be used to endorse or promote products derived |
21
|
|
|
* from this software without specific prior written permission. |
22
|
|
|
* |
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
* |
36
|
|
|
* @category Libraries |
37
|
|
|
* @package MissingBits/ClassesAndObjects |
38
|
|
|
* @author Stuart Herbert <[email protected]> |
39
|
|
|
* @copyright 2016-present Ganbaro Digital Ltd www.ganbarodigital.com |
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41
|
|
|
* @link http://ganbarodigital.github.io/php-the-missing-bits |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\FilterClassProperties; |
45
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\FilterObjectProperties; |
46
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\HasClassProperties; |
47
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\HasObjectProperties; |
48
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\IsClassProperty; |
49
|
|
|
use GanbaroDigital\MissingBits\ClassesAndObjects\IsObjectProperty; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* is this property a class property? |
53
|
|
|
* |
54
|
|
|
* @param ReflectionProperty $refProp |
55
|
|
|
* the property to inspect |
56
|
|
|
* @return bool |
57
|
|
|
* TRUE if $refProp is a class property |
58
|
|
|
* FALSE otherwise |
59
|
|
|
*/ |
60
|
|
|
function check_is_class_property(ReflectionProperty $refProp) |
61
|
|
|
{ |
62
|
|
|
return IsClassProperty::check($refProp); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* is this property a property on an object? |
67
|
|
|
* |
68
|
|
|
* @param ReflectionProperty $refProp |
69
|
|
|
* the property to inspect |
70
|
|
|
* @return bool |
71
|
|
|
* TRUE if $refProp is an object property |
72
|
|
|
* FALSE otherwise |
73
|
|
|
*/ |
74
|
|
|
function check_is_object_property(ReflectionProperty $refProp) |
75
|
|
|
{ |
76
|
|
|
return IsObjectProperty::check($refProp); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* get a class's static properties |
81
|
|
|
* |
82
|
|
|
* @param string $target |
83
|
|
|
* the class to examine |
84
|
|
|
* @param int $propTypes |
85
|
|
|
* the kind of properties to look for |
86
|
|
|
* default is to look for public properties only |
87
|
|
|
* @return array |
88
|
|
|
* a (possibly empty) read-only list of the class's static properties |
89
|
|
|
* @throws InvalidArgumentException |
90
|
|
|
* if $target is not a valid class name |
91
|
|
|
*/ |
92
|
|
|
function get_class_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC) |
93
|
|
|
{ |
94
|
|
|
// our helper class has all the answers |
95
|
|
|
return FilterClassProperties::from($target, $propTypes); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* does a class have static properties? |
100
|
|
|
* |
101
|
|
|
* @param string $target |
102
|
|
|
* the class to examine |
103
|
|
|
* @param int $propTypes |
104
|
|
|
* the kind of properties to look for |
105
|
|
|
* default is to look for public properties only |
106
|
|
|
* @return boolean |
107
|
|
|
* TRUE if $target is a class with static properties |
108
|
|
|
* FALSE otherwise |
109
|
|
|
*/ |
110
|
|
|
function has_class_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC) |
111
|
|
|
{ |
112
|
|
|
return HasClassProperties::check($target, $propTypes); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* get an object's properties |
117
|
|
|
* |
118
|
|
|
* @param object $target |
119
|
|
|
* the object to examine |
120
|
|
|
* @param int $propTypes |
121
|
|
|
* the kind of properties to look for |
122
|
|
|
* default is to look for public properties only |
123
|
|
|
* @return array |
124
|
|
|
* a (possibly empty) read-only list of the class's static properties |
125
|
|
|
* @throws InvalidArgumentException |
126
|
|
|
* if $target is not an object |
127
|
|
|
*/ |
128
|
|
|
function get_object_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC) |
129
|
|
|
{ |
130
|
|
|
// our helper class has all the answers |
131
|
|
|
return FilterObjectProperties::from($target, $propTypes); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* does an object have properties? |
136
|
|
|
* |
137
|
|
|
* @param object $target |
138
|
|
|
* the object to examine |
139
|
|
|
* @param int $propTypes |
140
|
|
|
* the kind of properties to look for |
141
|
|
|
* default is to look for public properties only |
142
|
|
|
* @return boolean |
143
|
|
|
* TRUE if $target is an object with properties |
144
|
|
|
* FALSE otherwise |
145
|
|
|
*/ |
146
|
|
|
function has_object_properties($target, $propTypes = ReflectionProperty::IS_PUBLIC) |
147
|
|
|
{ |
148
|
|
|
return HasObjectProperties::check($target, $propTypes); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|