Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

ImageProcessor.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Common\FieldTypeProcessor;
8
9 use Symfony\Component\Routing\RouterInterface;
10
11 class ImageProcessor extends BinaryInputProcessor
12 {
18 protected $urlTemplate;
19
29 protected $variations;
30
32 protected $router;
33
39 public function __construct($temporaryDirectory, RouterInterface $router, array $variations)
40 {
41 parent::__construct($temporaryDirectory);
42 $this->router = $router;
43 $this->variations = $variations;
44 }
45
46 public function preProcessValueHash($incomingValueHash)
47 {
48 if (is_array($incomingValueHash) && array_key_exists('variations', $incomingValueHash)) {
49 unset($incomingValueHash['variations']);
50 }
51
52 return parent::preProcessValueHash($incomingValueHash);
53 }
54
58 public function postProcessValueHash($outgoingValueHash)
59 {
60 if (!is_array($outgoingValueHash)) {
61 return $outgoingValueHash;
62 }
63
64 $outgoingValueHash['path'] = '/' . $outgoingValueHash['path'];
65 foreach ($this->variations as $variationIdentifier) {
66 $outgoingValueHash['variations'][$variationIdentifier] = [
67 'href' => $this->router->generate(
68 'ezpublish_rest_binaryContent_getImageVariation',
69 [
70 'imageId' => $outgoingValueHash['imageId'],
71 'variationIdentifier' => $variationIdentifier,
72 ]
73 ),
74 ];
75 }
76
77 return $outgoingValueHash;
78 }
79
88 protected function generateUrl($path, $variation)
89 {
90 $fieldId = '';
91 $versionNo = '';
92
93 // 223-1-eng-US/Cool-File.jpg
94 if (preg_match('((?<id>[0-9]+)-(?<version>[0-9]+)-[^/]+/[^/]+$)', $path, $matches)) {
95 $fieldId = $matches['id'];
96 $versionNo = $matches['version'];
97 }
98
99 return str_replace(
100 [
101 '{variation}',
102 '{fieldId}',
103 '{versionNo}',
104 ],
105 [
106 $variation,
107 $fieldId,
108 $versionNo,
109 ],
110 $this->urlTemplate
111 );
112 }
113 }
eZ\Publish\Core\REST\Common\FieldTypeProcessor\BinaryInputProcessor
Definition: BinaryInputProcessor.php:12
eZ\Publish\Core\REST\Common\FieldTypeProcessor\BinaryInputProcessor\$temporaryDirectory
$temporaryDirectory
Definition: BinaryInputProcessor.php:14
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor
Definition: ImageProcessor.php:12
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\$variations
$variations
Definition: ImageProcessor.php:29
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\$urlTemplate
$urlTemplate
Definition: ImageProcessor.php:18
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\generateUrl
generateUrl($path, $variation)
Generates a URL for $path in $variation.
Definition: ImageProcessor.php:88
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\__construct
__construct($temporaryDirectory, RouterInterface $router, array $variations)
Definition: ImageProcessor.php:39
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\postProcessValueHash
postProcessValueHash($outgoingValueHash)
{Perform manipulations on an a generated $outgoingValueHash.This method is called by the REST output ...
Definition: ImageProcessor.php:58
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\preProcessValueHash
preProcessValueHash($incomingValueHash)
{{Perform manipulations on a received $incomingValueHash.This method is called by the REST input pars...
Definition: ImageProcessor.php:46
eZ\Publish\Core\REST\Common\FieldTypeProcessor\ImageProcessor\$router
$router
Definition: ImageProcessor.php:32
eZ\Publish\Core\REST\Common\FieldTypeProcessor
Definition: AuthorProcessor.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.