CloudFrontManager::setCloudFrontClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Meema\CloudFront;
4
5
use Aws\CloudFront\CloudFrontClient;
6
use Aws\Credentials\Credentials;
7
use Exception;
8
use Illuminate\Support\Manager;
9
10
class CloudFrontManager extends Manager
11
{
12
    /**
13
     * Get a driver instance.
14
     *
15
     * @param string|null $name
16
     * @return mixed
17
     */
18
    public function engine($name = null)
19
    {
20
        return $this->driver($name);
21
    }
22
23
    /**
24
     * Create an Amazon CloudFront Converter instance.
25
     *
26
     * @return \Meema\CloudFront\CloudFront
27
     * @throws \Exception
28
     */
29
    public function createCloudFrontDriver(): CloudFront
30
    {
31
        $this->ensureAwsSdkIsInstalled();
32
33
        $config = $this->config['media-convert'];
34
35
        $credentials = $this->getCredentials($config['credentials']);
36
37
        $client = $this->setCloudFrontClient($config, $credentials);
38
39
        return new CloudFront($client);
40
    }
41
42
    /**
43
     * Sets the polly client.
44
     *
45
     * @param array $config
46
     * @param Credentials $credentials
47
     * @return \Aws\CloudFront\CloudFrontClient
48
     */
49
    protected function setCloudFrontClient(array $config, Credentials $credentials): CloudFrontClient
50
    {
51
        return new CloudFrontClient([
52
            'version' => $config['version'],
53
            'region' => $config['region'],
54
            'credentials' => $credentials,
55
        ]);
56
    }
57
58
    /**
59
     * Get credentials of AWS.
60
     *
61
     * @param array $credentials
62
     * @return \Aws\Credentials\Credentials
63
     */
64
    protected function getCredentials(array $credentials): Credentials
65
    {
66
        return new Credentials($credentials['key'], $credentials['secret']);
67
    }
68
69
    /**
70
     * Ensure the AWS SDK is installed.
71
     *
72
     * @return void
73
     *
74
     * @throws \Exception
75
     */
76
    protected function ensureAwsSdkIsInstalled()
77
    {
78
        if (! class_exists(CloudFrontClient::class)) {
79
            throw new Exception('Please install the AWS SDK PHP using `composer require aws/aws-sdk-php`.');
80
        }
81
    }
82
83
    /**
84
     * Get the default Text to Speech driver name.
85
     *
86
     * @return string
87
     */
88
    public function getDefaultDriver(): string
89
    {
90
        return 'cloudfront';
91
    }
92
}
93