Passed
Push — master ( 7df3a2...c2418e )
by Maximo
02:43
created

FileSystemProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 21
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 2
1
<?php
2
3
namespace Gewaer\Providers;
4
5
use Phalcon\Di\ServiceProviderInterface;
6
use Phalcon\DiInterface;
7
use League\Flysystem\Adapter\Local;
8
use League\Flysystem\AwsS3v3\AwsS3Adapter;
9
use League\Flysystem\Filesystem;
10
use Aws\S3\S3Client;
11
12
class FileSystemProvider implements ServiceProviderInterface
13
{
14
    /**
15
     * @param DiInterface $container
16
     */
17 54
    public function register(DiInterface $container)
18
    {
19 54
        $config = $container->getShared('config');
20
21 54
        $container->setShared(
22 54
            'filesystem',
23
            function ($filesystem = 'local') use ($config) {
24 1
                if ($filesystem === 'local') {
25
                    //create directory
26 1
                    $adapter = new Local($config->filesystem->local->path);
27
                } else {
28
                    //s3
29
                    $client = new S3Client($config->filesystem->s3->info->toArray());
30
                    $adapter = new AwsS3Adapter($client, $config->filesystem->s3->bucket, null, ['ACL' => 'public-read']);
31
                }
32 1
                return new Filesystem($adapter);
33 54
            }
34
        );
35 54
    }
36
}
37