Comments (10)
Maybe also pass the JsonApiRequestInterface $request to validateDomainObject. I don't have a case now where I would need the request, but if something is in the request, but it's not in the DomainObject... maybe I this is a step to far
Huh, although I think it's really a bit too much of overengineering, I'm ok to add it (e.g. CreateHydratorTrait::validateClientGeneratedId()
already does something similar). And I've just realized that the Exception Factory should be added as well. Unfortunately, I missed to add it to validateRequest()
(or maybe it has a reason I forgot). However, as I've already started to work on v5.0, I'm going to fix this inconsistency issue there.
To merge my requests (internal work projects) I would need this to be released to a stable version first... I guess it won't take long before it's tagged :)?
I have to wait a little bit for another feedback (#103), but I can release the next version soon if everything goes well.
from yin.
I've just release 4.3.0 including the validation of the domain object. :)
from yin.
So I made a fork and made the changes needed to solve my current issue: master...signet-connectivity:pass-object-to-validator
I guess its a backwards incompatible change. I could solve this without making these changes, but I would have to copy/paste some of the trait methods.
I think in the end that it's hard to extend/reuse AbstractHydrator
because of the traits here.
The traits are both an implementation and a contract. I think separating just that would make things easier to extend.
from yin.
Hi @Ilyes512
Sorry for not not replying so long. I'll carve out some free time for Yin this week so that I can look into the open tickets.
from yin.
No problem :) BTW, I am also no a 100% sure if this is the way to go.
from yin.
Can you please tell me why the $domainObject
is needed for validation? Does it have more information besides the data from the request?
Regarding the BC impact, I have a possible idea: we could add a new UpdateHydratorTrait::validateDomainObject()
method which would be called after request validation. I like this idea because request validation was separated from the object validation this way, but I'm curious if it would work for your use-case?
from yin.
Does it have more information besides the data from the request?
Yes. So what I have is an entity that has 2 attributes, limit
and maxLimit
. Users are able to adjust limit
between 0 and maxLimit
. Where maxLimit
is different for each entity (dynamic), but not configurable by the user (it is set and updated by another service).
Regarding your solution... I think that will work in my case. First check that the received limit
is an int and higher than 0. And after that, validate if it's lower than the maxLimit
.
The validateDomainObject
.... would it receive the object before or after being hydrated (after going through getAttributeHydrator
)?.
from yin.
Thanks for the quick answers!
The validateDomainObject.... would it receive the object before or after being hydrated (after going through getAttributeHydrator)?.
My idea is to run validateDomainObject()
after it has been hydrated
from yin.
I added e55ee84. Can you please test it?
from yin.
Yes! I tested this out on my actual problem... and it works for my case :).
Just one remark (cause now it wouldn't be backwards imcompatible). Maybe also pass the JsonApiRequestInterface $request
to validateDomainObject
. I don't have a case now where I would need the request, but if something is in the request, but it's not in the DomainObject... maybe I this is a step to far ¯_(ツ)_/¯
To merge my requests (internal work projects) I would need this to be released to a stable version first... I guess it won't take long before it's tagged :)?
from yin.
Related Issues (20)
- Error in createResourceIdInvalidException HOT 3
- Parsed body always contains an empty array when using Symfony requests HOT 4
- Missing data in response if using omitDataWhenNotIncluded HOT 7
- [PHP8] Method ReflectionParameter::getClass() is deprecated HOT 3
- Data Transformer array_merge problem HOT 2
- The package doesn't support psr/http-message v2 HOT 1
- Using same temp stream in multiple requests HOT 1
- Possible bug in OffsetBasedPagination HOT 6
- Exception code 0 HOT 2
- Hydrating same type (child, parent) related entity HOT 2
- Feature request: InfoDocument support HOT 1
- How to hydrate a POST request with multiple resources HOT 4
- Content-Type and Accept headers not really under domain validation HOT 7
- Using validateJsonBody() before getResource() makes request body empty HOT 3
- Problem with recursive relations HOT 1
- AbstractLinks::transform() generates invalid "prev" / "next" links HOT 3
- Incorrect encoding of (pagination) query parameters HOT 6
- Throw Exception if 'data' and 'errors' coexist in the request body HOT 3
- Add support for PSR-17 Http factory HOT 2
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 yin.