![]() 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/old/vendor/magento/framework/Reflection/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Framework\Reflection; use Magento\Framework\Serialize\Serializer\Json; /** * Casts values to the type given. */ class TypeCaster { /** * @var Json */ private $serializer; /** * @param Json $serializer */ public function __construct(Json $serializer) { $this->serializer = $serializer; } /** * Cast the output type to the documented type. This helps for consistent output (e.g. JSON). * * @param mixed $value * @param string $type * @return mixed * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function castValueToType($value, $type) { if ($value === null) { return null; } /** * Type caster does not complicated arrays according to restrictions in JSON/SOAP API * but interface and class implementations should be processed as is. * Function `class_exists()` is called to do not break code which return an array instead * interface implementation. */ if (is_array($value) && !interface_exists($type) && !class_exists($type)) { return $this->serializer->serialize($value); } if ($type === "int" || $type === "integer") { return (int)$value; } if ($type === "string") { return (string)$value; } if ($type === "bool" || $type === "boolean" || $type === "true" || $type == "false") { return (bool)$value; } if ($type === "float") { return (float)$value; } if ($type === "double") { return (double)$value; } return $value; } }