Adding custom validators restricted by the new `ValidatorInterface`
BC Break Report
| Q | A |
|---|---|
| Version | 3.x |
Summary
Following the change to the ValidatorInterface , adding custom validators implementing it is restricted by the existing properties of the new Environment class.
Being final, the Environment can't be extended, so any user that would require using any other value from the $_SERVER will not be able to access it from the class, even if the custom validator will be required to pass the two instances of it.
@gsteel What do you think we should do here ?
We can remove the final from the Environment class and allow user to extend it.
The 'Evironment' value object should encapsulate any environmental information that you might want to use in order to validate a session. Typically, this would come from $_SERVER. It should be immutable so that it can safely be passed around.
If there's something that users need to be present in this object that is not, they can raise an issue, or send in a PR.
Making the object non-final exposes all of its internals to BC promises.
If you want to allow users to extend the object, use an interface instead, but keep the existing concrete object immutable and final.
Remember that the point of using an object like this is to remove superglobals such as $_SERVER et al from the code. This makes it easier to test and easier to adapt to other environments.
You could ship a factory to produce one, then it would be easier for users to replace it via DI when necessary
fixed in #157