-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageStorage.php
More file actions
110 lines (91 loc) 路 4.03 KB
/
Copy pathImageStorage.php
File metadata and controls
110 lines (91 loc) 路 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace SixtyEightPublishers\ImageStorage;
use SixtyEightPublishers\FileStorage\Config\ConfigInterface;
use SixtyEightPublishers\FileStorage\FileStorage;
use SixtyEightPublishers\FileStorage\PathInfoInterface;
use SixtyEightPublishers\FileStorage\Resource\ResourceFactoryInterface;
use SixtyEightPublishers\ImageStorage\Config\NoImageConfigInterface;
use SixtyEightPublishers\ImageStorage\FileInfoInterface as ImageFileInfoInterface;
use SixtyEightPublishers\ImageStorage\ImageServer\ImageServerFactoryInterface;
use SixtyEightPublishers\ImageStorage\ImageServer\ImageServerInterface;
use SixtyEightPublishers\ImageStorage\ImageServer\RequestInterface;
use SixtyEightPublishers\ImageStorage\Info\InfoFactoryInterface;
use SixtyEightPublishers\ImageStorage\LinkGenerator\LinkGeneratorInterface as ImageLinkGeneratorInterface;
use SixtyEightPublishers\ImageStorage\NoImage\NoImageResolverInterface;
use SixtyEightPublishers\ImageStorage\PathInfoInterface as ImagePathInfoInterface;
use SixtyEightPublishers\ImageStorage\Persistence\ImagePersisterInterface;
use SixtyEightPublishers\ImageStorage\Responsive\Descriptor\DescriptorInterface;
use SixtyEightPublishers\ImageStorage\Responsive\SrcSet;
use SixtyEightPublishers\ImageStorage\Security\SignatureStrategyInterface;
use function assert;
final class ImageStorage extends FileStorage implements ImageStorageInterface
{
private ?ImageServerInterface $imageServer = null;
public function __construct(
string $name,
ConfigInterface $config,
ResourceFactoryInterface $resourceFactory,
ImageLinkGeneratorInterface $linkGenerator,
ImagePersisterInterface $imagePersister,
private readonly NoImageResolverInterface $noImageResolver,
private readonly InfoFactoryInterface $infoFactory,
private readonly ImageServerFactoryInterface $imageServerFactory,
) {
parent::__construct($name, $config, $resourceFactory, $linkGenerator, $imagePersister);
}
/**
* @param string|array<string, string|numeric|bool>|null $modifier
*/
public function createPathInfo(string $path, string|array|null $modifier = null): ImagePathInfoInterface
{
if (empty($path)) {
return $this->getNoImage()->withModifiers($modifier);
}
return $this->infoFactory->createPathInfo($path, $modifier);
}
public function createFileInfo(PathInfoInterface $pathInfo): ImageFileInfoInterface
{
if (!$pathInfo instanceof ImagePathInfoInterface) {
$pathInfo = $this->createPathInfo($pathInfo->getPath());
}
return $this->infoFactory->createFileInfo($pathInfo);
}
public function getImageResponse(RequestInterface $request): object
{
if (null === $this->imageServer) {
$this->imageServer = $this->imageServerFactory->create($this);
}
return $this->imageServer->getImageResponse($request);
}
public function getNoImageConfig(): NoImageConfigInterface
{
return $this->noImageResolver->getNoImageConfig();
}
public function getNoImage(?string $name = null): ImagePathInfoInterface
{
return $this->noImageResolver->getNoImage($name);
}
public function isNoImage(string $path): bool
{
return $this->noImageResolver->isNoImage($path);
}
public function resolveNoImage(string $path): ImagePathInfoInterface
{
return $this->noImageResolver->resolveNoImage($path);
}
public function srcSet(ImagePathInfoInterface $info, ?DescriptorInterface $descriptor = null, bool $absolute = true): SrcSet
{
assert($this->linkGenerator instanceof ImageLinkGeneratorInterface);
return $this->linkGenerator->srcSet(
info: $info,
descriptor: $descriptor,
absolute: $absolute,
);
}
public function getSignatureStrategy(): ?SignatureStrategyInterface
{
assert($this->linkGenerator instanceof ImageLinkGeneratorInterface);
return $this->linkGenerator->getSignatureStrategy();
}
}