1 | <?php |
||
52 | class IsTraversable |
||
53 | { |
||
54 | // speed repeated things up |
||
55 | use StaticDataCache; |
||
56 | |||
57 | /** |
||
58 | * list of types that we consider to be traversable |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | private static $acceptableTypes = [ |
||
63 | 'Array' => true, |
||
64 | stdClass::class => true, |
||
65 | Traversable::class => true, |
||
66 | IteratorAggregate::class => true, |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * is $item something that can be used in a foreach() loop? |
||
71 | * |
||
72 | * @param mixed $item |
||
73 | * the item to examine |
||
74 | * @return boolean |
||
75 | * true if the item can be used in a foreach() loop |
||
76 | * false otherwise |
||
77 | */ |
||
78 | public static function check($item) |
||
89 | |||
90 | /** |
||
91 | * is $item something that can be used in a foreach() loop? |
||
92 | * |
||
93 | * @param mixed $item |
||
94 | * the item to examine |
||
95 | * @return boolean |
||
96 | * true if the item can be used in a foreach() loop |
||
97 | * false otherwise |
||
98 | */ |
||
99 | private static function calculateResult($item) |
||
110 | |||
111 | /** |
||
112 | * is $item something that can be used in a foreach() loop? |
||
113 | * |
||
114 | * @deprecated since 2.10.0 |
||
115 | * @codeCoverageIgnore |
||
116 | * @param mixed $item |
||
117 | * the item to examine |
||
118 | * @return boolean |
||
119 | * true if the item can be used in a foreach() loop |
||
120 | * false otherwise |
||
121 | */ |
||
122 | public static function checkMixed($item) |
||
126 | |||
127 | /** |
||
128 | * is $item something that can be used in a foreach() loop? |
||
129 | * |
||
130 | * @param mixed $item |
||
131 | * the item to examine |
||
132 | * @return boolean |
||
133 | * true if the item can be used in a foreach() loop |
||
134 | * false otherwise |
||
135 | */ |
||
136 | public function __invoke($item) |
||
140 | |||
141 | /** |
||
142 | * have we seen this kind of item before? |
||
143 | * |
||
144 | * @param mixed $item |
||
145 | * @return boolean|null |
||
146 | */ |
||
147 | private static function getCachedResult($item) |
||
152 | |||
153 | /** |
||
154 | * remember the result in case there is a next time |
||
155 | * |
||
156 | * @param mixed $item |
||
157 | * @param boolean $result |
||
158 | * @return void |
||
159 | */ |
||
160 | private static function setCachedResult($item, $result) |
||
165 | |||
166 | /** |
||
167 | * work out what lookup key to use for this item |
||
168 | * |
||
169 | * @param mixed $item |
||
170 | * @return string |
||
171 | */ |
||
172 | private static function getCacheKey($item) |
||
180 | } |