Back to HttpFactory class

Method getHttp

public static \Joomla\CMS\Http\Http
getHttp
(mixed $options = [], mixed $adapters = null)
Method to create a JHttp instance.
Parameters
  • array|\ArrayAccess $options Client options array.
  • array|string $adapters Adapter (string) or queue of adapters (array) to use for communication.
Returns
  • \Joomla\CMS\Http\Http
Since
  • 3.0.0
-
  • \RuntimeException
Class: HttpFactory
Project: Joomla

Method getHttp - Source code

/**
 * Method to create a JHttp instance.
 *
 * @param   array|\ArrayAccess  $options   Client options array.
 * @param   array|string        $adapters  Adapter (string) or queue of adapters (array) to use for communication.
 *
 * @return  Http
 *
 * @since   3.0.0
 * @throws  \RuntimeException
 */
public static function getHttp($options = [], $adapters = null)
{
    if (!\is_array($options) && !$options instanceof \ArrayAccess) {
        throw new \InvalidArgumentException('The options param must be an array or implement the ArrayAccess interface.');
    }
    // Set default userAgent if nothing else is set
    if (!isset($options['userAgent'])) {
        $version = new Version();
        $options['userAgent'] = $version->getUserAgent('Joomla', true, false);
    }
    if (!($driver = static::getAvailableDriver($options, $adapters))) {
        throw new \RuntimeException('No transport driver available.');
    }
    return new Http($options, $driver);
}