Completed
Push — develop ( 59bb22...d5718e )
by Fabian
01:40
created

Sdk::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cakasim\Payone\Sdk;
6
7
use Cakasim\Payone\Sdk\Api\Service as ApiService;
8
use Cakasim\Payone\Sdk\Config\ConfigInterface;
9
use Cakasim\Payone\Sdk\Container\ContainerException;
10
use Cakasim\Payone\Sdk\Http\Service as HttpService;
11
use Cakasim\Payone\Sdk\Notification\Service as NotificationService;
12
use Cakasim\Payone\Sdk\Redirect\Service as RedirectService;
13
use Psr\Container\ContainerExceptionInterface;
14
use Psr\Container\ContainerInterface;
15
16
/**
17
 * The SDK main class.
18
 *
19
 * @author Fabian Böttcher <[email protected]>
20
 * @since 0.1.0
21
 */
22
class Sdk
23
{
24
    public const API_SOLUTION_NAME = 'Cakasim/PAYONE-PHP-SDK';
25
    public const API_SOLUTION_VERSION = '0.1.0';
26
27
    /**
28
     * @var ContainerInterface The SDK service container.
29
     */
30
    protected $container;
31
32
    /**
33
     * Constructs the SDK with the provided service container.
34
     *
35
     * @param ContainerInterface|null $container The service container or null to use the default container.
36
     * @throws ContainerException If building the default container fails.
37
     */
38
    public function __construct(ContainerInterface $container = null)
39
    {
40
        $this->container = $container ?: ContainerBuilder::buildDefaultContainer();
41
    }
42
43
    /**
44
     * Returns the SDK service container.
45
     *
46
     * @return ContainerInterface The SDK service container.
47
     */
48
    public function getContainer(): ContainerInterface
49
    {
50
        return $this->container;
51
    }
52
53
    /**
54
     * Returns the SDK config.
55
     *
56
     * @return ConfigInterface The SDK config.
57
     * @throws ContainerException If the SDK config cannot be resolved.
58
     */
59
    public function getConfig(): ConfigInterface
60
    {
61
        return $this->container->get(ConfigInterface::class);
62
    }
63
64
    /**
65
     * Returns the HTTP service.
66
     *
67
     * @return HttpService The HTTP service.
68
     * @throws ContainerExceptionInterface If the HTTP service cannot be resolved.
69
     */
70
    public function getHttpService(): HttpService
71
    {
72
        return $this->container->get(HttpService::class);
73
    }
74
75
    /**
76
     * Returns the API service.
77
     *
78
     * @return ApiService The API service.
79
     * @throws ContainerExceptionInterface If the API service cannot be resolved.
80
     */
81
    public function getApiService(): ApiService
82
    {
83
        return $this->container->get(ApiService::class);
84
    }
85
86
    /**
87
     * Returns the notification service.
88
     *
89
     * @return NotificationService The notification service.
90
     * @throws ContainerExceptionInterface If the notification service cannot be resolved.
91
     */
92
    public function getNotificationService(): NotificationService
93
    {
94
        return $this->container->get(NotificationService::class);
95
    }
96
97
    /**
98
     * Returns the redirect service.
99
     *
100
     * @return RedirectService The redirect service.
101
     * @throws ContainerExceptionInterface If the redirect service cannot be resolved.
102
     */
103
    public function getRedirectService(): RedirectService
104
    {
105
        return $this->container->get(RedirectService::class);
106
    }
107
}
108