Skip to content

Commit

Permalink
#13: Fixed validation for the item ID containing dot ('.')
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Sep 9, 2020
1 parent 90240a5 commit a8a1cfd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,13 @@
Laravel Persistent Configuration Repository
===========================================

1.3.0 Under Development
-----------------------

- Bug #13: Fixed validation for the item ID containing dot ('.') (klimov-paul)
- Enh: Added support for "illuminate/support" 8.0 (klimov-paul)


1.2.0, March 11, 2020
---------------------

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -496,8 +496,8 @@ $validatedData = $config->validate($request->all()); // throws \Illuminate\Valid
You can also use `\Illuminatech\Config\PersistentRepository::makeValidator()` method to create a validator instance for manual processing.

**Heads up!** Watch for usage dot symbols ('.') inside the input in case you do not use `\Illuminatech\Config\PersistentRepository::validate()` method.
By default Laravel considers dots in validation rules as array nested keys separator. You should either replace them
by '->' string or manually define `\Illuminatech\Config\Item::$id` in the way it does not contain a dot.
By default Laravel considers dots in validation rules as array nested keys separator. You should either prefix them
with backslash ('\') or manually define `\Illuminatech\Config\Item::$id` in the way it does not contain a dot.


### Creating configuration web interface <span id="creating-configuration-web-interface"></span>
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE.md
Expand Up @@ -8,6 +8,12 @@ if you want to upgrade from version A to version C and there is
version B between A and C, you need to following the instructions
for both A and B.

Upgrade from 1.2.0
------------------

* "illuminate/support" package requirements were raised to 7.26.0. Make sure to upgrade your code accordingly.


Upgrade from 1.1.1
------------------

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"illuminate/support": "^6.0 || ^7.0"
"illuminate/support": "^7.26.0 || ^8.0"
},
"require-dev": {
"illuminate/database": "*",
Expand All @@ -24,7 +24,7 @@
"illuminate/encryption": "*",
"illuminate/validation": "*",
"psr/log": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.0"
"phpunit/phpunit": "^8.0 || ^9.3"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 5 additions & 12 deletions src/PersistentRepository.php
Expand Up @@ -362,7 +362,7 @@ public function makeValidator(array $values): Validator
{
$rules = [];
foreach ($this->getItems() as $item) {
$inputName = str_replace('.', '->', $item->id);
$inputName = str_replace('.', '\.', $item->id);
$rules[$inputName] = $item->rules;
}

Expand All @@ -386,11 +386,10 @@ public function validate(array $values): array
if ($validator->fails()) {
$errors = [];
foreach ($validator->errors()->getMessages() as $key => $messages) {
$itemId = str_replace('->', '.', $key);
$errors[$itemId] = [];
$errors[$key] = [];
foreach ($messages as $message) {
$itemLabel = $items[$itemId]->label;
$errors[$itemId][] = str_replace(
$itemLabel = $items[$key]->label;
$errors[$key][] = str_replace(
[
$key,
Str::ucfirst($key),
Expand All @@ -409,13 +408,7 @@ public function validate(array $values): array
throw ValidationException::withMessages($errors);
}

$itemValues = [];
foreach ($validator->validated() as $key => $value) {
$itemId = str_replace('->', '.', $key);
$itemValues[$itemId] = $value;
}

return $itemValues;
return $validator->validated();
}

/**
Expand Down

0 comments on commit a8a1cfd

Please sign in to comment.