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

Core/FieldType/Image/Value.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Image;
8
9 use eZ\Publish\Core\FieldType\Value as BaseValue;
10 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
11 use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException;
12
22 class Value extends BaseValue
23 {
31 public $id;
32
38 public $alternativeText;
39
47 public $fileName;
48
56 public $fileSize;
57
63 public $uri;
64
70 public $imageId;
71
77 public $inputUri;
78
84 public $width;
85
91 public $height;
92
98 public function __construct(array $imageData = [])
99 {
100 foreach ($imageData as $key => $value) {
101 try {
102 $this->$key = $value;
103 } catch (PropertyNotFoundException $e) {
104 throw new InvalidArgumentType(
105 sprintf('Image\Value::$%s', $key),
106 'Existing property',
107 $value
108 );
109 }
110 }
111 }
112
113 public function isAlternativeTextEmpty(): bool
114 {
115 return $this->alternativeText === null || trim($this->alternativeText) === '';
116 }
117
129 public static function fromString($path)
130 {
131 if (!file_exists($path)) {
132 throw new InvalidArgumentType(
133 '$path',
134 'existing file',
135 $path
136 );
137 }
138
139 return new static(
140 [
141 'inputUri' => $path,
142 'fileName' => basename($path),
143 'fileSize' => filesize($path),
144 ]
145 );
146 }
147
153 public function getFileSize()
154 {
155 return $this->fileSize;
156 }
157
161 public function __toString()
162 {
163 return (string)$this->fileName;
164 }
165
166 public function __get($propertyName)
167 {
168 if ($propertyName === 'path') {
169 return $this->inputUri ?: $this->id;
170 }
171
172 throw new PropertyNotFoundException($propertyName, get_class($this));
173 }
174
175 public function __set($propertyName, $propertyValue)
176 {
177 if ($propertyName === 'path') {
178 $this->inputUri = $propertyValue;
179
180 return;
181 }
182
183 throw new PropertyNotFoundException($propertyName, get_class($this));
184 }
185 }
eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
This Exception is thrown if an accessed property in a value object was not found.
Definition: PropertyNotFoundException.php:15
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value
Struct that stores extra value information for a Criterion object.
Definition: API/Repository/Values/Content/Query/Criterion/Value.php:13
eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
Invalid Argument Type Exception implementation.
Definition: InvalidArgumentType.php:17
eZ\Publish\Core\FieldType\Image\Value\$width
$width
Definition: Core/FieldType/Image/Value.php:84
eZ\Publish\Core\FieldType\Image\Value\__set
__set($propertyName, $propertyValue)
Magic set function handling writes to non public properties.
Definition: Core/FieldType/Image/Value.php:175
eZ\Publish\Core\FieldType\Image\Value\$alternativeText
$alternativeText
Definition: Core/FieldType/Image/Value.php:38
eZ\Publish\Core\FieldType\Image\Value\$fileSize
$fileSize
Definition: Core/FieldType/Image/Value.php:56
eZ\Publish\Core\FieldType\Image\Value\$id
$id
Definition: Core/FieldType/Image/Value.php:31
eZ\Publish\Core\FieldType\Image\Value\$fileName
$fileName
Definition: Core/FieldType/Image/Value.php:47
eZ\Publish\Core\FieldType\Image\Value\$uri
$uri
Definition: Core/FieldType/Image/Value.php:63
eZ\Publish\Core\FieldType\Image\Value\$imageId
$imageId
Definition: Core/FieldType/Image/Value.php:70
eZ\Publish\Core\FieldType\Image\Value\$inputUri
$inputUri
Definition: Core/FieldType/Image/Value.php:77
eZ\Publish\Core\FieldType\Image\Value\__construct
__construct(array $imageData=[])
Construct a new Value object.
Definition: Core/FieldType/Image/Value.php:98
eZ\Publish\Core\FieldType\Image\Value\isAlternativeTextEmpty
isAlternativeTextEmpty()
Definition: Core/FieldType/Image/Value.php:113
eZ\Publish\Core\FieldType\Image\Value\__get
__get($propertyName)
Magic get function handling read to non public properties.
Definition: Core/FieldType/Image/Value.php:166
eZ\Publish\Core\FieldType\Image\Value\fromString
static fromString($path)
Creates a value only from a file path.
Definition: Core/FieldType/Image/Value.php:129
eZ\Publish\Core\FieldType\Image\Value\$height
$height
Definition: Core/FieldType/Image/Value.php:91
eZ\Publish\Core\FieldType\Image\Value\getFileSize
getFileSize()
Returns the image file size in byte.
Definition: Core/FieldType/Image/Value.php:153
eZ\Publish\Core\FieldType\Image\Value\__toString
__toString()
Definition: Core/FieldType/Image/Value.php:161
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\Core\FieldType\Image
Definition: AliasCleanerInterface.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.