Completed
Push — master ( 50b9db...4de1a8 )
by WEBEWEB
03:01
created

CURLFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the curl-library package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\CURL\Factory;
13
14
use WBW\Library\Core\Exception\IO\InvalidHTTPMethodException;
15
use WBW\Library\Core\IO\HTTPInterface;
16
use WBW\Library\CURL\Configuration\CURLConfiguration;
17
use WBW\Library\CURL\Request\CURLDeleteRequest;
18
use WBW\Library\CURL\Request\CURLGetRequest;
19
use WBW\Library\CURL\Request\CURLHeadRequest;
20
use WBW\Library\CURL\Request\CURLOptionsRequest;
21
use WBW\Library\CURL\Request\CURLPatchRequest;
22
use WBW\Library\CURL\Request\CURLPostRequest;
23
use WBW\Library\CURL\Request\CURLPutRequest;
24
use WBW\Library\CURL\Request\CURLRequestInterface;
25
26
/**
27
 * cURL factory.
28
 *
29
 * @author webeweb <https://github.com/webeweb/>
30
 * @package WBW\Library\CURL\Factory
31
 */
32
class CURLFactory implements HTTPInterface {
33
34
    /**
35
     * Constructor.
36
     */
37
    private function __construct() {
38
        // NOTHING TO DO.
39
    }
40
41
    /**
42
     * Get an instance.
43
     *
44
     * @param string $method The method.
45
     * @param CURLConfiguration $configuration The configuration.
46
     * @return CURLRequestInterface Returns this cURL request.
47
     * @throws InvalidHTTPMethodException Throws an invalid HTTP method exception if the method is not implemented.
48
     */
49
    public static function getInstance($method, CURLConfiguration $configuration = null, $resourcePath = null) {
50
51
        // Check the configuration.
52
        if (null === $configuration) {
53
            $configuration = new CURLConfiguration();
54
        }
55
56
        // Switch into $method.
57
        switch ($method) {
58
59
            case self::HTTP_METHOD_DELETE:
60
                return new CURLDeleteRequest($configuration, $resourcePath);
61
62
            case self::HTTP_METHOD_GET:
63
                return new CURLGetRequest($configuration, $resourcePath);
64
65
            case self::HTTP_METHOD_HEAD:
66
                return new CURLHeadRequest($configuration, $resourcePath);
67
68
            case self::HTTP_METHOD_OPTIONS:
69
                return new CURLOptionsRequest($configuration, $resourcePath);
70
71
            case self::HTTP_METHOD_PATCH:
72
                return new CURLPatchRequest($configuration, $resourcePath);
73
74
            case self::HTTP_METHOD_POST:
75
                return new CURLPostRequest($configuration, $resourcePath);
76
77
            case self::HTTP_METHOD_PUT:
78
                return new CURLPutRequest($configuration, $resourcePath);
79
80
            default:
81
                throw new InvalidHTTPMethodException($method);
82
        }
83
    }
84
85
}
86