| @@ 178-194 (lines=17) @@ | ||
| 175 | * @param string $accessor |
|
| 176 | * @return mixed |
|
| 177 | */ |
|
| 178 | protected function extractWithAccessor($subject, $propertyName, $accessor) |
|
| 179 | { |
|
| 180 | if ($accessor === self::ACCESSOR_ARRAY && is_array($subject) && array_key_exists($propertyName, $subject) |
|
| 181 | || $subject instanceof \ArrayAccess && $subject->offsetExists($propertyName) |
|
| 182 | ) { |
|
| 183 | return $subject[$propertyName]; |
|
| 184 | } elseif (is_object($subject)) { |
|
| 185 | if ($accessor === self::ACCESSOR_GETTER) { |
|
| 186 | return call_user_func_array([$subject, 'get' . ucfirst($propertyName)], []); |
|
| 187 | } elseif ($accessor === self::ACCESSOR_ASSERTER) { |
|
| 188 | return $this->extractThroughAsserter($subject, $propertyName); |
|
| 189 | } elseif ($accessor === self::ACCESSOR_PUBLICPROPERTY && property_exists($subject, $propertyName)) { |
|
| 190 | return $subject->$propertyName; |
|
| 191 | } |
|
| 192 | } |
|
| 193 | return null; |
|
| 194 | } |
|
| 195 | ||
| 196 | /** |
|
| 197 | * Detect which type of accessor to use when extracting |
|
| @@ 377-393 (lines=17) @@ | ||
| 374 | * @param string $accessor |
|
| 375 | * @return mixed |
|
| 376 | */ |
|
| 377 | protected function extractWithAccessor(&$subject, $propertyName, $accessor) |
|
| 378 | { |
|
| 379 | if ($accessor === self::ACCESSOR_ARRAY && is_array($subject) && array_key_exists($propertyName, $subject) |
|
| 380 | || $subject instanceof \ArrayAccess && $subject->offsetExists($propertyName) |
|
| 381 | ) { |
|
| 382 | return $subject[$propertyName]; |
|
| 383 | } elseif (is_object($subject)) { |
|
| 384 | if ($accessor === self::ACCESSOR_GETTER) { |
|
| 385 | return call_user_func_array([$subject, 'get' . ucfirst($propertyName)], []); |
|
| 386 | } elseif ($accessor === self::ACCESSOR_ASSERTER) { |
|
| 387 | return $this->extractThroughAsserter($subject, $propertyName); |
|
| 388 | } elseif ($accessor === self::ACCESSOR_PUBLICPROPERTY && property_exists($subject, $propertyName)) { |
|
| 389 | return $subject->$propertyName; |
|
| 390 | } |
|
| 391 | } |
|
| 392 | return null; |
|
| 393 | } |
|
| 394 | ||
| 395 | /** |
|
| 396 | * Detect which type of accessor to use when extracting |
|