Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Introduce ELASTICA_JSON_UNESCAPED_UNICODE ELASTICA_JSON_UNESCAPED_SLASHES #613

wants to merge 1 commit into from

Conversation

demon
Copy link

@demon demon commented May 12, 2014

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+

…SHES

Avoids using the global defines from PHP. Follows up #559.
@demon
Copy link
Author

demon commented May 12, 2014

Eh, not perfect yet. Emits some notices.

@ruflin
Copy link
Owner

ruflin commented May 12, 2014

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?

@demon
Copy link
Author

demon commented May 12, 2014

Yes, I shall fix it up shortly, just hadn't finished it and got sucked into a bunch of meetings :)

@ruflin
Copy link
Owner

ruflin commented May 12, 2014

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()
Elastica\Util::getJsonUnescapedUnicode()

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?

@mal
Copy link
Contributor

mal commented May 13, 2014

Given that these flags only feed json_encode, it might be nicer to wrap the functionality as a whole, avoiding both globals and slightly odd constant methods; i.e.

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 Util, but it might be more intuitive to have a new Elastica\JSON class or something, so you can simply do JSON::stringify($array);. Thoughts?

@ruflin
Copy link
Owner

ruflin commented May 13, 2014

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?

@demon
Copy link
Author

demon commented May 13, 2014

I think doing it either of your ways is fine and avoids the global define problem entirely.

@mal mal mentioned this pull request May 13, 2014
@demon
Copy link
Author

demon commented May 15, 2014

Closing in favor of pull #614 instead.

@demon demon closed this May 15, 2014
@demon demon deleted the global-define-fix branch May 15, 2014 01:44
@afm-mike afm-mike mentioned this pull request Jan 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants