1 |
efrain |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
|
|
|
3 |
namespace EduSharingApiClient;
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* Class CurlHandler
|
|
|
7 |
*
|
|
|
8 |
* Class that describes the handling of curl requests
|
|
|
9 |
*
|
|
|
10 |
* @author Torsten Simon <simon@edu-sharing.net>
|
|
|
11 |
* @author Marian Ziegler <ziegler@edu-sharing.net>
|
|
|
12 |
*/
|
|
|
13 |
abstract class CurlHandler
|
|
|
14 |
{
|
|
|
15 |
public const METHOD_GET = 'get';
|
|
|
16 |
public const METHOD_POST = 'post';
|
|
|
17 |
public const METHOD_PUT = 'put';
|
|
|
18 |
public const METHOD_DELETE = 'delete';
|
|
|
19 |
protected const METHODS = [self::METHOD_GET, self::METHOD_POST, self::METHOD_PUT, self::METHOD_DELETE];
|
|
|
20 |
|
|
|
21 |
protected string $method = 'get';
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Function handleCurlRequest
|
|
|
25 |
*
|
|
|
26 |
* @param string $url the request url
|
|
|
27 |
* @param array $curlOptions the curl options, assoc array same as in the default php curl implementation
|
|
|
28 |
* @return CurlResult a result object containing the response content, error/status code and a curl info array
|
|
|
29 |
*/
|
|
|
30 |
public abstract function handleCurlRequest(string $url, array $curlOptions): CurlResult;
|
|
|
31 |
|
|
|
32 |
public function setMethod(string $method): void {
|
|
|
33 |
if (in_array($method, self::METHODS, true)) {
|
|
|
34 |
$this->method = $method;
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
}
|