From eb4896b905a309ba7d495de3a1f82d48100796a3 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sun, 27 Sep 2009 12:24:20 -0400 Subject: [PATCH] Move automatic request object generation to a factory method --- framework/Http/lib/Horde/Http/Client.php | 21 ++----------- framework/Http/lib/Horde/Http/Request/Factory.php | 36 +++++++++++++++++++++++ framework/Http/package.xml | 2 ++ 3 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 framework/Http/lib/Horde/Http/Request/Factory.php diff --git a/framework/Http/lib/Horde/Http/Client.php b/framework/Http/lib/Horde/Http/Client.php index 097170b72..e27533d64 100644 --- a/framework/Http/lib/Horde/Http/Client.php +++ b/framework/Http/lib/Horde/Http/Client.php @@ -56,7 +56,8 @@ class Horde_Http_Client $this->_request = $args['request']; unset($args['request']); } else { - $this->_request = $this->_createBestAvailableRequest(); + $requestFactory = new Horde_Http_Request_Factory(); + $this->_request = $requestFactory->create(); } foreach ($args as $key => $val) { @@ -172,22 +173,4 @@ class Horde_Http_Client { $this->{'_' . $name} = $value; } - - /** - * Find the best available request backend - * - * @return Horde_Http_Request_Base - */ - public function _createBestAvailableRequest() - { - if (class_exists('HttpRequest', false)) { - return new Horde_Http_Request_Peclhttp(); - } elseif (extension_loaded('curl')) { - return new Horde_Http_Request_Curl(); - } elseif (ini_get('allow_url_fopen')) { - return new Horde_Http_Request_Fopen(); - } else { - throw new Horde_Http_Exception('No HTTP request backends are available. You must install pecl_http, curl, or enable allow_url_fopen.'); - } - } } diff --git a/framework/Http/lib/Horde/Http/Request/Factory.php b/framework/Http/lib/Horde/Http/Request/Factory.php new file mode 100644 index 000000000..75614e0b5 --- /dev/null +++ b/framework/Http/lib/Horde/Http/Request/Factory.php @@ -0,0 +1,36 @@ + + * @license http://opensource.org/licenses/bsd-license.php BSD + * @category Horde + * @package Horde_Http + */ + +/** + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD + * @category Horde + * @package Horde_Http + */ +class Horde_Http_Request_Factory +{ + /** + * Find the best available request backend + * + * @return Horde_Http_Request_Base + */ + public function create() + { + if (class_exists('HttpRequest', false)) { + return new Horde_Http_Request_Peclhttp(); + } elseif (extension_loaded('curl')) { + return new Horde_Http_Request_Curl(); + } elseif (ini_get('allow_url_fopen')) { + return new Horde_Http_Request_Fopen(); + } else { + throw new Horde_Http_Exception('No HTTP request backends are available. You must install pecl_http, curl, or enable allow_url_fopen.'); + } + } +} diff --git a/framework/Http/package.xml b/framework/Http/package.xml index 2d9a647b6..89d9d69ce 100644 --- a/framework/Http/package.xml +++ b/framework/Http/package.xml @@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -73,6 +74,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + -- 2.11.0