mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Orange Management
|
|
*
|
|
* PHP Version 7.0
|
|
*
|
|
* @category TBD
|
|
* @package TBD
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @copyright 2013 Dennis Eichhorn
|
|
* @license OMS License 1.0
|
|
* @version 1.0.0
|
|
* @link http://orange-management.com
|
|
*/
|
|
namespace phpOMS\Message\Http;
|
|
|
|
/**
|
|
* Rest request class.
|
|
*
|
|
* @category Framework
|
|
* @package phpOMS\Request
|
|
* @author OMS Development Team <dev@oms.com>
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
* @license OMS License 1.0
|
|
* @link http://orange-management.com
|
|
* @since 1.0.0
|
|
*/
|
|
class Rest
|
|
{
|
|
/**
|
|
* Url.
|
|
*
|
|
* @var Request
|
|
* @since 1.0.0
|
|
*/
|
|
private $request = '';
|
|
|
|
/**
|
|
* Set url.
|
|
*
|
|
* @param Request $request Request
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn
|
|
*/
|
|
public function setRequest(Request $request)
|
|
{
|
|
$this->request = $request;
|
|
}
|
|
|
|
/**
|
|
* Make request.
|
|
*
|
|
* @param mixed $data Data to pass
|
|
*
|
|
* @return string
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn
|
|
*/
|
|
public function callApi($data = false) : string
|
|
{
|
|
$curl = curl_init();
|
|
|
|
switch ($this->request->getMethod()) {
|
|
case RequestMethod::POST:
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
|
if ($data) {
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
}
|
|
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, $this->request->getUri()->__toString());
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$result = curl_exec($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
return $result;
|
|
}
|
|
}
|