function __construct($baseUrl, Http\RequestMethod $method) { $this->method = $method; $this->baseUrl = $baseUrl; $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); switch ($method) { case Http\RequestMethod::Post(): curl_setopt($this->ch, CURLOPT_POST, true); curl_setopt($this->ch, CURLOPT_HEADER, false); break; case Http\RequestMethod::Get(): curl_setopt($this->ch, CURLOPT_POST, false); curl_setopt($this->ch, CURLOPT_HEADER, false); break; case Http\RequestMethod::Head(): curl_setopt($this->ch, CURLOPT_HEADER, true); curl_setopt($this->ch, CURLOPT_NOBODY, true); break; } }
/** * Returns GET or POST data array * @param RequestMethod $method The request method * @param string $name Optional parameter name * @return array Returns either the full request array or an array filtered by name * @throws \InvalidArgumentException Raises an error if method is neither post nor get */ static function MethodArray(RequestMethod $method, $name = '') { switch ($method) { case RequestMethod::Get(): return self::GetArray($name); case RequestMethod::Post(): return self::PostArray($name); default: throw new \InvalidArgumentException('Request::MethodArray is available for request methods POST and GET, only'); } }