1<?php
2/**
3 * Copyright 2007-2016 Horde LLC (http://www.horde.org/)
4 *
5 * @author   Chuck Hagenbuch <chuck@horde.org>
6 * @license  http://www.horde.org/licenses/bsd BSD
7 * @category Horde
8 * @package  Http
9 */
10
11/**
12 * @author   Chuck Hagenbuch <chuck@horde.org>
13 * @license  http://www.horde.org/licenses/bsd BSD
14 * @category Horde
15 * @package  Http
16 */
17class Horde_Http_Request_Factory
18{
19    /**
20     * Find the best available request backend
21     *
22     * @return Horde_Http_Request_Base
23     */
24    public function create()
25    {
26        if (class_exists('HttpRequest', false)) {
27            return new Horde_Http_Request_Peclhttp();
28        } elseif (class_exists('\http\Client', false)) {
29            return new Horde_Http_Request_Peclhttp2();
30        } elseif (extension_loaded('curl')) {
31            return new Horde_Http_Request_Curl();
32        } elseif (ini_get('allow_url_fopen')) {
33            return new Horde_Http_Request_Fopen();
34        } else {
35            throw new Horde_Http_Exception('No HTTP request backends are available. You must install pecl_http, curl, or enable allow_url_fopen.');
36        }
37    }
38}
39