Re: RFC Idea - json_validate() validate schema
| From: | Larry Garfield | Date: | Thu, 02 Mar 2023 20:29:33 +0000 |
| Subject: | Re: RFC Idea - json_validate() validate schema | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119660@lists.php.net to get a copy of this message | ||
On Thu, Mar 2, 2023, at 1:31 PM, Jakub Zelenka wrote:
> On Thu, Mar 2, 2023 at 5:53 PM Rowan Tommins <rowan.collins@gmail.com>
> wrote:
>
>> On Thu, 2 Mar 2023 at 12:34, Jakub Zelenka <bukka@php.net> wrote:
>>
>> > It's possible that we might decide to stop supporting some drafts if the
>> > maintenance burden is too big and usage small but I wouldn't see that as
>> > something that happens often. But essentially you are right that there
>> will
>> > be minimum (draft-04 initially) and maximum (latest implemented draft).
>> >
>>
>>
>> Thinking about this, particularly if there is the ability to install a PECL
>> extension which supports different versions from the core PHP version,
>> perhaps it would be useful to expose a function or constant that lists the
>> supported versions, so that code needing a particular version could check
>> for support directly, rather than having to attempt and catch an exception?
>>
>>
> That's a good point. I think a constant should be sufficient. I think the
> different classes make less sense if $schema is specified as I would think
> that the $schema should have a priority. So having just default argument
> using the constant for the cases where it's not specified should be
> sufficient IMHO.
>
> Cheers
>
> Jakub
You mean using the version from the JSON string, and allowing an override? Like this?
new JsonSchema($schema_string, version: JsonSchema::DRAFT_4);
I see two issues there.
1. If I want to see if DRAFT_6 is available, I have to use defined()[1] with strings. This is
fugly.
2. I don't know how to polyfill newer spec versions if I don't want to wait for internals
to get around to adding a new version.
--Larry Garfield
[1] https://www.php.net/manual/en/function.defined