Comments (5)
I prefer first way with additional parameter in Result::getAttributeErrorMessagesIndexedByPath()
and
Result::getErrorMessagesIndexedByPath()
and by default escape separator chars in value path elements. It's allow to consumers correctly parse result keys.
from validator.
What is your use case for this method?
from validator.
I have REST API. After validating the data with this method, I get all the errors given their path, since I'm using a Nested
validator. Then I generate an exception, where I put the received array of errors, encode it through json_encode
and give it to the client. And as planned, the key in this array can look like: "account.profile.name".
Also, "account.profile.name" is the key in the array of data that comes from the client to the server and it sends them for validation. Therefore, in order to avoid the behavior that Nested
validator has, when "sub-arrays" are formed from such keys, I follow the documentation and escape the dots. "account/.profile/.name".
If a key contains the separator (.), or Each shortcut (*), it must be escaped with backslash () in the rule config to work correctly. In the input data escaping is not needed.
If the "account.profile.name" attribute fails validation, then I would expect to see the following in the response from the getErrorMessagesIndexedByPath
: {"account.profile.name": "error text"}
,
but not {"account//.profile//.name": "error text"}
from validator.
I hope you got what I meant :)
from validator.
Makes sense. Thanks for suggestion, @bouledepate
from validator.
Related Issues (20)
- Remove or improve `RulesDumper` HOT 5
- Increase MSI to 100%
- Add support non-public properties for dot notation in `Nested` rule
- Add methods `getFirstErrorMessagesIndexedByAttribute()` and `getFirstErrorMessagesIndexedByPath()` to `Result` class HOT 2
- Way to add error with custom value path HOT 2
- Return error code for API application HOT 6
- Can rule Integer allow only 'int'? HOT 1
- Add method to merge several validation results to one HOT 3
- Replace `mixed $skipOnEmpty` in rules constructors to `bool|callable|null $skipOnEmpty` HOT 3
- update irc link
- update docs folder link
- Allow to validate aspect ratio in `Image` rule
- Replace type rule in `RuleHandlerInterface::validate()` from `object` to `RuleInterface`
- Extract rule name and options to separate collector HOT 4
- Extract rule name and options to separate collector HOT 1
- Add `Unique` rule for validating `iterable` HOT 1
- Add `Any` rule
- `AtLeast`, `OneOf` naming - not clear that they are applied to attributes, not other rules HOT 2
- `AnyRule` - make the error message more detailed HOT 1
- `UniqueIterable` rule - add non-strict mode to support values of different types HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validator.