Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add support for granular messages on Dimensions rule #52707

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a8f35f
fix(dimensions): add properties to hold constraint values
CamKem Sep 6, 2024
c39a038
fix(dimensions): update constructor to call methods
CamKem Sep 6, 2024
cb46dd6
fix(dimensions): add new constraint methods & update existing to use …
CamKem Sep 6, 2024
04aaa29
fix(dimensions): build the validation rules and methods for data & va…
CamKem Sep 6, 2024
67b8991
fix(dimensions): add granular validation message translation strings
CamKem Sep 6, 2024
fcfd82b
fix(dimensions): add replace methods for granular rules
CamKem Sep 6, 2024
18b5652
fix(dimensions): cleanup additional methods on dimensions
CamKem Sep 6, 2024
1308f47
fix(dimensions): add methods for to ValidatesAttributes for validatin…
CamKem Sep 6, 2024
3948899
test: added one for each of the methods on the dimensions rule
CamKem Sep 6, 2024
c1ea328
test: add method for string format of the rule
CamKem Sep 6, 2024
8bee70f
test: added one for macroable trait
CamKem Sep 6, 2024
7ea1e5c
test: update expected validation messages for granularity on image fi…
CamKem Sep 6, 2024
6128096
chore: cleanup obsolete constructor
CamKem Sep 7, 2024
a2d280f
fix: add properties for the between rules & building rules
CamKem Sep 7, 2024
3b719bc
fix: add default callback & custom rule merges
CamKem Sep 9, 2024
8ddc78a
fix: use existing min, max & between replacement methods
CamKem Sep 9, 2024
868bac0
fix: styleci
CamKem Sep 9, 2024
5812d03
fix: styleci
CamKem Sep 9, 2024
3809876
Merge branch 'refs/heads/11.x' into feat/granular-dimension-messages
CamKem Sep 9, 2024
320f24c
stylci
CamKem Sep 11, 2024
7d47d87
fix: merge regression
CamKem Sep 17, 2024
054b1dd
test: coverage for constraints passed into the constructor via Rule c…
CamKem Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Illuminate/Translation/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
'numeric' => 'The :attribute field must be greater than or equal to :value.',
'string' => 'The :attribute field must be greater than or equal to :value characters.',
],
'height' => 'The :attribute field must have a height of :value pixels',
'height_between' => 'The :attribute field must have a height between :min and :max pixels.',
'hex_color' => 'The :attribute field must be a valid hexadecimal color.',
'image' => 'The :attribute field must be an image.',
'in' => 'The selected :attribute is invalid.',
Expand Down Expand Up @@ -99,6 +101,9 @@
'string' => 'The :attribute field must not be greater than :max characters.',
],
'max_digits' => 'The :attribute field must not have more than :max digits.',
'max_height' => 'The :attribute field must have a maximum height of :max pixels.',
'max_ratio' => 'The :attribute field must have an aspect ratio less than :max.',
'max_width' => 'The :attribute field must have a maximum width of :max pixels.',
'mimes' => 'The :attribute field must be a file of type: :values.',
'mimetypes' => 'The :attribute field must be a file of type: :values.',
'min' => [
Expand All @@ -108,6 +113,9 @@
'string' => 'The :attribute field must be at least :min characters.',
],
'min_digits' => 'The :attribute field must have at least :min digits.',
'min_height' => 'The :attribute field must have a minimum height of :min pixels.',
'min_ratio' => 'The :attribute field must have an aspect ratio greater than :min.',
'min_width' => 'The :attribute field must have a minimum width of :min pixels.',
'missing' => 'The :attribute field must be missing.',
'missing_if' => 'The :attribute field must be missing when :other is :value.',
'missing_unless' => 'The :attribute field must be missing unless :other is :value.',
Expand All @@ -133,6 +141,8 @@
'prohibited_if' => 'The :attribute field is prohibited when :other is :value.',
'prohibited_unless' => 'The :attribute field is prohibited unless :other is in :values.',
'prohibits' => 'The :attribute field prohibits :other from being present.',
'ratio' => 'The :attribute field must have an aspect ratio of :value',
'ratio_between' => 'The :attribute field must have an aspect ratio between :min and :max.',
'regex' => 'The :attribute field format is invalid.',
'required' => 'The :attribute field is required.',
'required_array_keys' => 'The :attribute field must contain entries for: :values.',
Expand Down Expand Up @@ -160,7 +170,8 @@
'url' => 'The :attribute field must be a valid URL.',
'ulid' => 'The :attribute field must be a valid ULID.',
'uuid' => 'The :attribute field must be a valid UUID.',

'width' => 'The :attribute field must have a width of :value pixels',
'width_between' => 'The :attribute field must have width between :min and :max pixels.',
/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
Expand Down
168 changes: 168 additions & 0 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,174 @@ protected function replaceDimensions($message, $attribute, $rule, $parameters)
return $message;
}

/**
* Replace placeholder for the width constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceWidth($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $parameters[0], $message);
}

/**
* Replace placeholder for the width constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMinWidth($message, $attribute, $rule, $parameters)
{
return $this->replaceMin($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholder for the maximum width constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMaxWidth($message, $attribute, $rule, $parameters)
{
return $this->replaceMax($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholders for the width between constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceWidthBetween($message, $attribute, $rule, $parameters)
{
return $this->replaceBetween($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholder for the height constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceHeight($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $parameters[0], $message);
}

/**
* Replace placeholder for the min height constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMinHeight($message, $attribute, $rule, $parameters)
{
return $this->replaceMin($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholder for the maximum height constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMaxHeight($message, $attribute, $rule, $parameters)
{
return $this->replaceMax($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholders for the height between constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceHeightBetween($message, $attribute, $rule, $parameters)
{
return $this->replaceBetween($message, $attribute, $rule, $parameters);
}

/**
* Replace placeholder for the ratio constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceRatio($message, $attribute, $rule, $parameters)
{
return str_replace(':value', round($parameters[0], 3), $message);
}

/**
* Replace placeholder for the minimum ratio constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMinRatio($message, $attribute, $rule, $parameters)
{
return $this->replaceMin($message, $attribute, $rule, [round($parameters[0], 3)]);
}

/**
* Replace placeholder for the maximum ratio constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceMaxRatio($message, $attribute, $rule, $parameters)
{
return $this->replaceMax($message, $attribute, $rule, [round($parameters[0], 3)]);
}

/**
* Replace placeholders for the ratio between constraint on the dimensions rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array<int, string> $parameters
* @return string
*/
protected function replaceRatioBetween($message, $attribute, $rule, $parameters)
{
return $this->replaceBetween($message, $attribute, $rule, [round($parameters[0], 3), round($parameters[1], 3)]);
}

/**
* Replace all place-holders for the ends_with rule.
*
Expand Down
Loading