Create a new EntityBody based on the input type
resource|string|EntityBody $resource Entity body data:
int $size Size of the data contained in the resource:
InvalidArgumentException if the $resource arg is not a resource or string
public static function factory($resource = '', $size = null) {
if ($resource instanceof EntityBodyInterface) {
return $resource;
}
switch (gettype($resource)) {
case 'string':
return self::fromString($resource);
case 'resource':
return new static($resource, $size);
case 'object':
if (method_exists($resource, '__toString')) {
return self::fromString((string) $resource);
}
break;
case 'array':
return self::fromString(http_build_query($resource));
}
throw new InvalidArgumentException('Invalid resource type');
}