mirror of
https://github.com/ambieco/scribe.git
synced 2026-04-26 03:34:57 +08:00
Merge pull request #299 from t1sh0o/feature/add-nested-array-validations
Display the validation rules for array properties
This commit is contained in:
@@ -4,5 +4,3 @@ enabled:
|
||||
- phpdoc_order
|
||||
- phpdoc_separation
|
||||
- unalign_double_arrow
|
||||
|
||||
linting: true
|
||||
|
||||
@@ -79,8 +79,9 @@ abstract class AbstractGenerator
|
||||
*/
|
||||
protected function getParameters($routeData, $routeAction, $bindings)
|
||||
{
|
||||
$validator = Validator::make([], $this->getRouteRules($routeAction['uses'], $bindings));
|
||||
foreach ($validator->getRules() as $attribute => $rules) {
|
||||
$rules = $this->simplifyRules($this->getRouteRules($routeAction['uses'], $bindings));
|
||||
|
||||
foreach ($rules as $attribute => $rules) {
|
||||
$attributeData = [
|
||||
'required' => false,
|
||||
'type' => null,
|
||||
@@ -88,6 +89,7 @@ abstract class AbstractGenerator
|
||||
'value' => '',
|
||||
'description' => [],
|
||||
];
|
||||
|
||||
foreach ($rules as $ruleName => $rule) {
|
||||
$this->parseRule($rule, $attribute, $attributeData, $routeData['id']);
|
||||
}
|
||||
@@ -97,6 +99,31 @@ abstract class AbstractGenerator
|
||||
return $routeData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the validation rules as plain array.
|
||||
*
|
||||
* @param array $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function simplifyRules($rules)
|
||||
{
|
||||
$simplifiedRules = Validator::make([], $rules)->getRules();
|
||||
|
||||
if (count($simplifiedRules) === 0) {
|
||||
return $simplifiedRules;
|
||||
}
|
||||
|
||||
$values = collect($simplifiedRules)
|
||||
->filter(function ($values) {
|
||||
return in_array('array', $values);
|
||||
})->map(function ($val, $key) {
|
||||
return [''];
|
||||
})->all();
|
||||
|
||||
return Validator::make($values, $rules)->getRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
* @param $bindings
|
||||
|
||||
Reference in New Issue
Block a user