diff --git a/composer.json b/composer.json index 781a9c7a..688488f1 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,8 @@ "psr-0": { "Guzzle\\Tests": "tests/", "Guzzle": "src/" - } + }, + "files": ["src/Guzzle/Guzzle.php"] }, "require-dev": { diff --git a/src/Guzzle/Guzzle.php b/src/Guzzle/Guzzle.php new file mode 100644 index 00000000..2a9a3662 --- /dev/null +++ b/src/Guzzle/Guzzle.php @@ -0,0 +1,185 @@ +createRequest($method, $url, $headers, $body); + + if ($allow_redirects === false) { + $request->getParams()->set(RedirectPlugin::DISABLE, true); + } + + if (is_array($cookies)) { + foreach ($cookies as $name => $value) { + $request->addCookie($name, $value); + } + } + + if (is_array($query)) { + $request->getQuery()->overwriteWith($query); + } + + if (is_array($curl)) { + $request->getCurlOptions()->overwriteWith($curl); + } + + if (is_array($auth)) { + if (!isset($auth[1])) { + throw new InvalidArgumentException('"auth" requires an array containing a username and password'); + } + $request->setAuth($auth[0], $auth[1]); + } + + if (is_array($events)) { + foreach ($events as $name => $method) { + $request->getEventDispatcher()->addListener($name, $method); + } + } + + if (is_array($plugins)) { + foreach ($plugins as $plugin) { + $request->addSubscriber($plugin); + } + } + + return $request->send(); + } + + /** + * Send a GET request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function get($url, $options = array()) + { + return self::request('GET', $url, $options); + } + + /** + * Send a HEAD request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function head($url, $options = array()) + { + return self::request('HEAD', $url, $options); + } + + /** + * Send a DELETE request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function delete($url, $options = array()) + { + return self::request('DELETE', $url, $options); + } + + /** + * Send a POST request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function post($url, $options = array()) + { + return self::request('POST', $url, $options); + } + + /** + * Send a PUT request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function put($url, $options = array()) + { + return self::request('PUT', $url, $options); + } + + /** + * Send a PATCH request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function patch($url, $options = array()) + { + return self::request('PATCH', $url, $options); + } + + /** + * Send an OPTIONS request + * + * @param string $url URL of the request + * @param array $options Array of request options + * + * @return \Guzzle\Http\Message\Response + * @see Guzzle::request for a list of available options + */ + public static function options($url, $options = array()) + { + return self::request('OPTIONS', $url, $options); + } +}