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 setTemplate(string $string): ProviderInterface |
46
|
|
|
{ |
47
|
|
|
$this->template = $string; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getTemplate(): string |
53
|
|
|
{ |
54
|
|
|
return $this->template; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function render(MediaInterface $media, array $options = []): string |
58
|
|
|
{ |
59
|
|
|
return $this->twigEngine->render($this->template, array_merge(['media' => $media], $options)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function upload(MediaInterface $media): void |
63
|
|
|
{ |
64
|
|
|
$this->uploader->upload($media, $this->pathPrefix); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|