On Oct 11, 2014 6:14 PM, "Márk Sági-Kazár" <mark.sa...@gmail.com> wrote:
> I looked at the Psr MessageInterface and found that the handling of invalid data is a bit inconsistent (or there is no restriction).
>
> The setBody function takes a typehinted stream parameter and should throw an InvalidArgumentException in case of invalid body?
>
> What about the other functions?
>
> I mean: the interface describes very precisley that the header setters accept a value which is a string, array of strings or can be casted to string. What about invalid data? Should be checked and thrown an InvalidArgumentException as well or just cast everything (value or values in array) to string and let PHP fail with an error?
Typically, you will throw an exception in cases of invalid input. In writing/editing the interfaces, I did not explicitly indicate this for two reasons:
- once you start adding @throws annotations, somebody will come along and start disputing which exception type you've specified (because everybody has an opinion on these), and/or insist on adding exception interfaces to the proposal (which will cause others to start disputing naming and/or necessity of them).
- how errors are detected and handled is largely an implementation detail, and should be left to the libraries implementing the interfaces.
Regarding this last point, my assertion is that most implementations will follow the spec closely, and handle unexpected input with exceptions, and that there will be few enough differences that interop will not be hampered. What I've seen so far of the other proposals that provide interfaces also suggests that we'll typically see between 1 and 5 widely used implementations, and these will primarily differ only in terms of extensibility; basic functionality will be largely identical, particularly when it comes to the consumer API defined by the shared interfaces.
> I think Phil Sturgeon's DBAD logic can be interpreted here as well, so for me the second is acceptable, meaning it is the developers responsibility to provide valid data and any other cases is treated as an error.
Precisely - developers should provide input the interfaces would expect, and expect an error condition should they fail to do so.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/47db3135-9a13-40ed-95e5-01a85b172d87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.