-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ELASTICA_JSON_UNESCAPED_UNICODE ELASTICA_JSON_UNESCAPED_SLASHES #613
Conversation
…SHES Avoids using the global defines from PHP. Follows up #559.
Eh, not perfect yet. Emits some notices. |
That is a nasty one. To be honest I don't like the the usage / overwriting of the globals at all, but I don't see a better way at the moment. So in general it looks good. Somehow it didn't trigger a travis build. Not sure why. I assume your last comment means, some more changes are coming? |
Yes, I shall fix it up shortly, just hadn't finished it and got sucked into a bunch of meetings :) |
I thought about a better implementation. Instead of using the ugly constants I would suggest to introduce two static functions in Elastica\Util Elastica\Util::getJsonUnescapedSlashes() These functions are called and deal with, if the constants are set or not. Like this we don't have duplicated code and no new global constants. What do you think? |
Given that these flags only feed class Util { ...
public static stringify($input)
{
return json_encode(
$input,
(defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 64)
| (defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 256)
);
}
} The example adds a method to |
I like that it is obvious in the code that it is stringified to a json. With your additional mapper, that would be hidden a little bit. Because of this I like the JSON idea. Here I worry that we could get in conflicts with other JSON objects / mapper which probably exist. Not sure if we add too much complexity with an additional object if it only does one thing and is not used everywhere else where we deal with JSON. @demon Your thoughts? |
I think doing it either of your ways is fine and avoids the global define problem entirely. |
Closing in favor of pull #614 instead. |
Avoids using the global defines from PHP. Follows up #559.
This lead to https://bugzilla.wikimedia.org/show_bug.cgi?id=65110 being filed downstream by myself. We use the existence of JSON_UNESCAPED_* defines to detect 5.3/5.4 behavior and handle fallbacks more gracefully. Elastica unconditionally defining these on 5.3 and below breaks our behavior detection.
Proposed PR should work on 5.3 as well as 5.4+