mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
67 lines
1.4 KiB
PHP
67 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.1
|
|
*
|
|
* @package Framework
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://website.orange-management.de
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace phpOMS\Message\Http;
|
|
|
|
/**
|
|
* Rest request class.
|
|
*
|
|
* @package Framework
|
|
* @license OMS License 1.0
|
|
* @link http://website.orange-management.de
|
|
* @since 1.0.0
|
|
*/
|
|
class Rest
|
|
{
|
|
|
|
/**
|
|
* Make request.
|
|
*
|
|
* @param Request $request Request
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public static function request(Request $request) : string
|
|
{
|
|
$curl = curl_init();
|
|
|
|
switch ($request->getMethod()) {
|
|
case RequestMethod::POST:
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
|
if ($request->getData() !== null) {
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData());
|
|
}
|
|
break;
|
|
case RequestMethod::PUT:
|
|
curl_setopt($curl, CURLOPT_PUT, 1);
|
|
break;
|
|
}
|
|
|
|
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
|
curl_setopt($curl, CURLOPT_USERPWD, "username:password");
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $request->getUri()->__toString());
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$result = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $result;
|
|
}
|
|
}
|