1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2018 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2018 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\ContentBundle\Factory\ORM; |
18
|
|
|
|
19
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleMediaInterface; |
20
|
|
|
use SWP\Bundle\ContentBundle\Model\ImageInterface; |
21
|
|
|
use SWP\Bundle\ContentBundle\Model\ImageRenditionInterface; |
22
|
|
|
use SWP\Component\Bridge\Model\RenditionInterface; |
23
|
|
|
use SWP\Component\Storage\Factory\FactoryInterface; |
24
|
|
|
|
25
|
|
|
final class ImageRenditionFactory implements ImageRenditionFactoryInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var FactoryInterface |
29
|
|
|
*/ |
30
|
|
|
private $decoratedFactory; |
31
|
|
|
|
32
|
|
|
public function __construct(FactoryInterface $decoratedFactory) |
33
|
|
|
{ |
34
|
|
|
$this->decoratedFactory = $decoratedFactory; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function createWith(ArticleMediaInterface $articleMedia, ImageInterface $image, RenditionInterface $rendition): ImageRenditionInterface |
38
|
|
|
{ |
39
|
|
|
$imageRendition = $this->create(); |
40
|
|
|
$imageRendition->setImage($image); |
41
|
|
|
$imageRendition->setMedia($articleMedia); |
42
|
|
|
$imageRendition->setHeight($rendition->getHeight()); |
43
|
|
|
$imageRendition->setWidth($rendition->getWidth()); |
44
|
|
|
$imageRendition->setName($rendition->getName()); |
45
|
|
|
$imageRendition->setPreviewUrl($rendition->getHref()); |
46
|
|
|
|
47
|
|
|
return $imageRendition; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function create(): ImageRenditionInterface |
51
|
|
|
{ |
52
|
|
|
return $this->decoratedFactory->create(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|