2019-06-10 16:24:22 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 7.0
|
|
|
|
*
|
|
|
|
* Url handler
|
|
|
|
*
|
|
|
|
* @package RetailCrm\Common
|
|
|
|
* @author retailCRM <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
|
|
* @link http://help.retailcrm.pro/docs/Developers
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RetailCrm\Common;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 7.0
|
|
|
|
*
|
|
|
|
* Url class
|
|
|
|
*
|
|
|
|
* @package RetailCrm\Common
|
|
|
|
* @author retailCRM <integration@retailcrm.ru>
|
|
|
|
* @license https://opensource.org/licenses/MIT MIT License
|
|
|
|
* @link http://help.retailcrm.pro/docs/Developers
|
|
|
|
*/
|
|
|
|
class Url
|
|
|
|
{
|
2019-06-17 12:43:54 +03:00
|
|
|
/**
|
|
|
|
* This class is used to store normalizeUrl method
|
|
|
|
* which is used in Client and HttpClient to check
|
|
|
|
* trailing slash.
|
|
|
|
*/
|
|
|
|
private function __construct() {}
|
2019-06-10 16:24:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check trailing slash into url
|
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function normalizeUrl($url)
|
|
|
|
{
|
|
|
|
if ('/' !== $url[strlen($url) - 1]) {
|
|
|
|
$url .= '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
2019-06-17 13:59:14 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert request data to GET parameters
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function buildGetParameters(array $params)
|
|
|
|
{
|
|
|
|
$result = '';
|
|
|
|
|
|
|
|
foreach ($params as $param => $value) {
|
|
|
|
if (!is_array($value)) {
|
|
|
|
$result .= '&' . $param . '=' . $value;
|
|
|
|
} else {
|
|
|
|
foreach ($value as $subvalue) {
|
|
|
|
$result .= '&' . $param . '=' . $subvalue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count($result) > 0 ? '?' . substr($result, 1) : '';
|
|
|
|
}
|
2019-06-10 16:24:22 +03:00
|
|
|
}
|