Giter Site home page Giter Site logo

Comments (5)

Sammyjo20 avatar Sammyjo20 commented on May 3, 2024 2

Hey @Whizboy-Arnold really sorry for the delay on this!

I will get a fix out for you soon which will allow you to customise the JSON flags.

from saloon.

juse-less avatar juse-less commented on May 3, 2024 1

@Sammyjo20 Hey.

I think what @Whizboy-Arnold means is that he'd like to add/overwrite the JSON flags in the JsonBodyRepository.
JSON should be escaped, like PHP does, but isn't required.
AFAIK, most people also don't escape it, unlike PHP.
I've also faced issues with escaped JSON in the past, where APIs don't actually support JSON, even though that's their 'data format'.
So I can relate to the situation.

That being said, you should be able to straight-off snag my 'HasJsonFlags' trait in my private concept repo (src/Concerns/HasJsonFlags), you've been invited to.
Then you should be able to add it to the JsonBodyRepository, and change

public function __toString(): string
{
    return json_encode($this->all(), JSON_THROW_ON_ERROR);
}

to something like

public function __toString(): string
{
   $json = is_null($this->getJsonFlags())
        ? json_encode($this->all())
        : json_encode($this->all(), $this->getJsonFlags());

    // If JSON_THROW_ON_ERROR is not set, turn `false` into an empty string.
    return $json === false ? '' : $json;
}

Or if you want to enforce a JSON Exception, something like:

public function __toString(): string
{
    return json_encode($this->all(), $this->getJsonFlags() | JSON_THROW_ON_ERROR);
}

Keep in mind, though, if this is done - using interface type hints will not resolve the new JSON flag methods.

from saloon.

Sammyjo20 avatar Sammyjo20 commented on May 3, 2024

Sorry I'm a little confused @Whizboy-Arnold - do you mind clarifying a little bit? Thanks!

from saloon.

Whizboy-Arnold avatar Whizboy-Arnold commented on May 3, 2024

Ok thank you for the support

from saloon.

Sammyjo20 avatar Sammyjo20 commented on May 3, 2024

Hey @Whizboy-Arnold I've made a PR (#229) to add support for this. Please could you take a look over it to see if it would be suitable for you?

from saloon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.