![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/vendor/friendsofsymfony/rest-bundle/Decoder/ |
<?php /* * This file is part of the FOSRestBundle package. * * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace FOS\RestBundle\Decoder; /** * Decodes JSON data and make it compliant with application/x-www-form-encoded style. * * @author Kévin Dunglas <[email protected]> */ final class JsonToFormDecoder implements DecoderInterface { /** * Makes data decoded from JSON application/x-www-form-encoded compliant. */ private function xWwwFormEncodedLike(array &$data): void { foreach ($data as $key => &$value) { if (is_array($value)) { // Encode recursively $this->xWwwFormEncodedLike($value); } elseif (false === $value) { // Checkbox-like behavior removes false data but PATCH HTTP method with just checkboxes does not work // To fix this issue we prefer transform false data to null // See https://github.com/FriendsOfSymfony/FOSRestBundle/pull/883 $value = null; } elseif (!is_string($value)) { // Convert everything to string // true values will be converted to '1', this is the default checkbox behavior $value = strval($value); } } } /** * {@inheritdoc} */ public function decode(string $data) { $decodedData = @json_decode($data, true); if (is_array($decodedData)) { $this->xWwwFormEncodedLike($decodedData); } return $decodedData; } }