Final Class Yiisoft\Validator\Rule\Image\Image
Defines validation options to check that a value is an image and optionally check its dimensions.
Public Methods
Method Details
| public mixed __construct ( integer|null $width = null, integer|null $height = null, integer|null $minWidth = null, integer|null $minHeight = null, integer|null $maxWidth = null, integer|null $maxHeight = null, Yiisoft\Validator\Rule\Image\ImageAspectRatio|null $aspectRatio = null, string $notImageMessage = '{Property} must be an image.', string $notExactWidthMessage = 'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.', string $notExactHeightMessage = 'The height of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.', string $tooSmallWidthMessage = 'The width of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.', string $tooSmallHeightMessage = 'The height of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.', string $tooLargeWidthMessage = 'The width of {property} cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.', string $tooLargeHeightMessage = 'The height of {property} cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.', string $invalidAspectRatioMessage = 'The aspect ratio of {property} must be {aspectRatioWidth, number}:{aspectRatioHeight, number} with margin {aspectRatioMargin, number}%.', boolean|callable|null $skipOnEmpty = null, boolean $skipOnError = false, Closure|null $when = null ) | ||
| $width | integer|null |
Expected exact width of validated image file. |
| $height | integer|null |
Expected exact height of validated image file. |
| $minWidth | integer|null |
Expected minimum width of validated image file. |
| $minHeight | integer|null |
Expected minimum height of validated image file. |
| $maxWidth | integer|null |
Expected maximum width of validated image file. |
| $maxHeight | integer|null |
Expected maximum height of validated image file. |
| $aspectRatio | Yiisoft\Validator\Rule\Image\ImageAspectRatio|null |
Expected aspect ratio of validated image file. |
| $notImageMessage | string |
A message used when the validated value is not valid image file. You may use the following placeholders in the message:
|
| $notExactWidthMessage | string |
A message used when the width of validated image file doesn't exactly equal to {@see $width}. You may use the following placeholders in the message:
|
| $notExactHeightMessage | string |
A message used when the height of validated image file doesn't exactly equal to {@see $height}. You may use the following placeholders in the message:
|
| $tooSmallWidthMessage | string |
A message used when the width of validated image file is less than {@see $minWidth}. You may use the following placeholders in the message:
|
| $tooSmallHeightMessage | string |
A message used when the height of validated image file is less than {@see $minHeight}. You may use the following placeholders in the message:
|
| $tooLargeWidthMessage | string |
A message used when the width of validated image file is more than {@see $maxWidth}. You may use the following placeholders in the message:
|
| $tooLargeHeightMessage | string |
A message used when the height of validated image file is more than {@see $maxHeight}. You may use the following placeholders in the message:
|
| $invalidAspectRatioMessage | string |
A message used when aspect ratio of validated image file is different than {@see \Yiisoft\Validator\Rule\Image\ImageAspectRatio::$width}:{@see \Yiisoft\Validator\Rule\Image\ImageAspectRatio::$height} with correction based on {@see \Yiisoft\Validator\Rule\Image\ImageAspectRatio::$margin}. You may use the following placeholders in the message:
|
| $skipOnEmpty | boolean|callable|null |
Whether to skip this rule if the value validated is empty. See {@see \Yiisoft\Validator\SkipOnEmptyInterface}. |
| $skipOnError | boolean |
Whether to skip this rule if any of the previous rules gave an error. See {@see \Yiisoft\Validator\SkipOnErrorInterface}. |
| $when | Closure|null |
A callable to define a condition for applying the rule. See {@see \Yiisoft\Validator\WhenInterface}. |
public function __construct(
private ?int $width = null,
private ?int $height = null,
private ?int $minWidth = null,
private ?int $minHeight = null,
private ?int $maxWidth = null,
private ?int $maxHeight = null,
private ?ImageAspectRatio $aspectRatio = null,
private string $notImageMessage = '{Property} must be an image.',
private string $notExactWidthMessage = 'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
private string $notExactHeightMessage = 'The height of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
private string $tooSmallWidthMessage = 'The width of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
private string $tooSmallHeightMessage = 'The height of {property} cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
private string $tooLargeWidthMessage = 'The width of {property} cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
private string $tooLargeHeightMessage = 'The height of {property} cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
private string $invalidAspectRatioMessage = 'The aspect ratio of {property} must be {aspectRatioWidth, number}:{aspectRatioHeight, number} with margin {aspectRatioMargin, number}%.',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
private ?Closure $when = null,
) {
if ($this->width !== null && ($this->minWidth !== null || $this->maxWidth !== null)) {
throw new InvalidArgumentException('Exact width and min / max width can\'t be specified together.');
}
if ($this->height !== null && ($this->minHeight !== null || $this->maxHeight !== null)) {
throw new InvalidArgumentException('Exact width and min / max height can\'t be specified together.');
}
$this->skipOnEmpty = $skipOnEmpty;
}
| public Yiisoft\Validator\Rule\Image\ImageAspectRatio|null getAspectRatio ( ) |
public function getAspectRatio(): ?ImageAspectRatio
{
return $this->aspectRatio;
}
| public string getInvalidAspectRatioMessage ( ) |
public function getInvalidAspectRatioMessage(): string
{
return $this->invalidAspectRatioMessage;
}
| public integer|null getMaxHeight ( ) |
public function getMaxHeight(): ?int
{
return $this->maxHeight;
}
| public integer|null getMinHeight ( ) |
public function getMinHeight(): ?int
{
return $this->minHeight;
}
| public string getNotExactHeightMessage ( ) |
public function getNotExactHeightMessage(): string
{
return $this->notExactHeightMessage;
}
| public string getNotExactWidthMessage ( ) |
public function getNotExactWidthMessage(): string
{
return $this->notExactWidthMessage;
}
| public string getNotImageMessage ( ) |
public function getNotImageMessage(): string
{
return $this->notImageMessage;
}
| public array getOptions ( ) |
public function getOptions(): array
{
return [
'width' => $this->width,
'height' => $this->height,
'minWidth' => $this->minWidth,
'minHeight' => $this->minHeight,
'maxWidth' => $this->maxWidth,
'maxHeight' => $this->maxHeight,
'aspectRatioWidth' => $this->getAspectRatio()?->getWidth(),
'aspectRatioHeight' => $this->getAspectRatio()?->getHeight(),
'aspectRatioMargin' => $this->getAspectRatio()?->getMargin(),
'notExactWidthMessage' => [
'template' => $this->notExactWidthMessage,
'parameters' => [
'exactly' => $this->width,
],
],
'notExactHeightMessage' => [
'template' => $this->notExactHeightMessage,
'parameters' => [
'exactly' => $this->height,
],
],
'tooSmallWidthMessage' => [
'template' => $this->tooSmallWidthMessage,
'parameters' => [
'limit' => $this->minWidth,
],
],
'tooSmallHeightMessage' => [
'template' => $this->tooSmallHeightMessage,
'parameters' => [
'limit' => $this->minHeight,
],
],
'tooLargeWidthMessage' => [
'template' => $this->tooLargeWidthMessage,
'parameters' => [
'limit' => $this->maxWidth,
],
],
'tooLargeHeightMessage' => [
'template' => $this->tooLargeHeightMessage,
'parameters' => [
'limit' => $this->maxHeight,
],
],
'notImageMessage' => [
'template' => $this->notImageMessage,
'parameters' => [],
],
'invalidAspectRatioMessage' => [
'template' => $this->invalidAspectRatioMessage,
'parameters' => [
'aspectRatioWidth' => $this->getAspectRatio()?->getWidth(),
'aspectRatioHeight' => $this->getAspectRatio()?->getHeight(),
'aspectRatioMargin' => $this->getAspectRatio()?->getMargin(),
],
],
'skipOnEmpty' => $this->getSkipOnEmptyOption(),
'skipOnError' => $this->skipOnError,
];
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::getSkipOnEmpty()
A getter for $skipOnEmpty property.
| public boolean|callable|null getSkipOnEmpty ( ) | ||
| return | boolean|callable|null |
A current raw (non-normalized) value. |
|---|---|---|
public function getSkipOnEmpty(): bool|callable|null
{
return $this->skipOnEmpty;
}
| public string getTooLargeHeightMessage ( ) |
public function getTooLargeHeightMessage(): string
{
return $this->tooLargeHeightMessage;
}
| public string getTooLargeWidthMessage ( ) |
public function getTooLargeWidthMessage(): string
{
return $this->tooLargeWidthMessage;
}
| public string getTooSmallHeightMessage ( ) |
public function getTooSmallHeightMessage(): string
{
return $this->tooSmallHeightMessage;
}
| public string getTooSmallWidthMessage ( ) |
public function getTooSmallWidthMessage(): string
{
return $this->tooSmallWidthMessage;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::getWhen()
A getter for $when property.
| public Closure|null getWhen ( ) | ||
| return | Closure|null |
Current value:
|
|---|---|---|
public function getWhen(): ?Closure
{
return $this->when;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::shouldSkipOnError()
A getter for $skipOnError property.
| public boolean shouldSkipOnError ( ) | ||
| return | boolean |
Current value. |
|---|---|---|
public function shouldSkipOnError(): bool
{
return $this->skipOnError;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::skipOnEmpty()
An immutable setter to change $skipOnEmpty property.
| public $this skipOnEmpty ( boolean|callable|null $value ) | ||
| $value | boolean|callable|null |
A new value. |
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function skipOnEmpty(bool|callable|null $value): static
{
$new = clone $this;
$new->skipOnEmpty = $value;
return $new;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::skipOnError()
An immutable setter to change $skipOnError property.
| public $this skipOnError ( boolean $value ) | ||
| $value | boolean |
A new value. |
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function skipOnError(bool $value): static
{
$new = clone $this;
$new->skipOnError = $value;
return $new;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::when()
An immutable setter to change $when property.
| public $this when ( Closure|null $value ) | ||
| $value | Closure|null |
A new value:
|
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function when(?Closure $value): static
{
$new = clone $this;
$new->when = $value;
return $new;
}
Signup or Login in order to comment.