Exemplo n.º 1
0
/**
 * Extracts values having specific keys from the given array/object.
 *
 * @param array|object|null $target
 * @param array             $keys A list of keys to be extracted.
 * @return array A map of keys to extracted values or an empty array if $target is null.
 * @throws InvalidArgumentException If the target is not an array, object or null.
 */
function fields($target, array $keys)
{
    if (is_array($target)) {
        return array_only($target, $keys);
    }
    if (is_object($target)) {
        return object_only($target, $keys);
    }
    if (is_null($target)) {
        return [];
    }
    throw new InvalidArgumentException("Not an object or array");
}
 function __debugInfo()
 {
     // Exclude inherited properties.
     $baseProps = map((new ReflectionClass(CompositeComponent::class))->getProperties(ReflectionProperty::IS_PUBLIC), function (ReflectionProperty $p) {
         return $p->getName();
     });
     $allProps = map((new ReflectionClass($this))->getProperties(ReflectionProperty::IS_PUBLIC), function (ReflectionProperty $p) {
         return $p->getName();
     });
     $ownProps = array_diff($allProps, $baseProps);
     return object_only($this, $ownProps);
 }