CoreFiles by mySites.guru
JsonMockResponse.php33 lines, 926 bytes, from Joomla_5.1.2-Stable-Full_Package.zip
Raw History Compare with 5.1.1
md5
3b6328abde4deb790e5b44f41e963e46
sha1
27f83e51b5e212ad32a3d34f4dbbd7a35d133a49
sha256
afdbb41803c248dc94882cefad9cca3587cbde67477a666676b70186faec8936
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\HttpClient\Response;

use Symfony\Component\HttpClient\Exception\InvalidArgumentException;

class JsonMockResponse extends MockResponse
{
    /**
     * @param mixed $body Any value that `json_encode()` can serialize
     */
    public function __construct(mixed $body = [], array $info = [])
    {
        try {
            $json = json_encode($body, \JSON_THROW_ON_ERROR);
        } catch (\JsonException $e) {
            throw new InvalidArgumentException('JSON encoding failed: '.$e->getMessage(), $e->getCode(), $e);
        }

        $info['response_headers']['content-type'] ??= 'application/json';

        parent::__construct($json, $info);
    }
}

The same content is in 17 releases, Joomla 5.1.0-beta1 to 5.2.0-alpha1. See them all, or every version of this file.