Completed
Pull Request — master (#177)
by Mikołaj
38:01
created

GenericProvider::upload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\MediaProvider;
14
15
use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
16
use BitBag\SyliusCmsPlugin\Uploader\MediaUploaderInterface;
17
use Symfony\Component\Templating\EngineInterface;
18
19
final class GenericProvider implements ProviderInterface
20
{
21
    /** @var MediaUploaderInterface */
22
    private $uploader;
23
24
    /** @var EngineInterface */
25
    private $twigEngine;
26
27
    /** @var string */
28
    private $template;
29
30
    /** @var string */
31
    private $pathPrefix;
32
33
    public function __construct(
34
        MediaUploaderInterface $uploader,
35
        EngineInterface $twigEngine,
36
        string $template,
37
        string $pathPrefix
38
    ) {
39
        $this->uploader = $uploader;
40
        $this->twigEngine = $twigEngine;
41
        $this->template = $template;
42
        $this->pathPrefix = $pathPrefix;
43
    }
44
45
    public function render(MediaInterface $media, array $options = []): string
46
    {
47
        return $this->twigEngine->render($this->template, array_merge(['media' => $media], $options));
48
    }
49
50
    public function upload(MediaInterface $media): void
51
    {
52
        $this->uploader->upload($media,  $this->pathPrefix);
53
    }
54
}
55