Permalink
Browse files

Endpoint settings

  • Loading branch information...
zeleznypa committed Jul 11, 2013
1 parent 58b914c commit e09ea9c14743a11e56368db0a8dae7378d5aa066
Showing with 30 additions and 4 deletions.
  1. +30 −4 Zeleznypa/Curl/Curl.php
@@ -12,6 +12,9 @@ class Curl extends \Zeleznypa\Curl\SimpleCurl
/** @var array $arguments */
private $arguments = array();
/** @var string $endpoint */
private $endpoint;
/** @var string $url */
private $url;
@@ -87,6 +90,28 @@ public function setArguments(array $arguments, $overwrite = FALSE)
return $this;
}
/**
* Endpoint getter
* @author Pavel Železný <info@pavelzelezny.cz>
* @return string
*/
public function getEndpoint()
{
return $this->endpoint;
}
/**
* Endpoint setter
* @author Pavel Železný <info@pavelzelezny.cz>
* @param string $endpoint
* @return \Zeleznypa\Curl\Curl Provides fluent interface
*/
public function setEndpoint($endpoint)
{
$this->endpoint = '/' . ltrim($endpoint, '/');
return $this;
}
/**
* Get cURL destination address
* @author Pavel Železný <info@pavelzelezny.cz>
@@ -116,18 +141,19 @@ public function setUrl($url)
*/
public function getRequestUrl()
{
$url = ($this->getEndpoint() !== NULL) ? rtrim($this->getUrl(), '/') . $this->getEndpoint() : $this->getUrl();
$urlArguments = http_build_query($this->getArguments());
if ($urlArguments === '')
{
return $this->getUrl();
return $url;
}
elseif (strpos($this->getUrl(), '?') === FALSE)
elseif (strpos($url, '?') === FALSE)
{
return $this->getUrl() . '?' . $urlArguments;
return $url . '?' . $urlArguments;
}
else
{
return $this->getUrl() . '&' . $urlArguments;
return $url . '&' . $urlArguments;
}
}

0 comments on commit e09ea9c

Please sign in to comment.