HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/vertex/module-tax/Model/Cache/Serializer.php
<?php
/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @author     Mediotype                     https://www.mediotype.com/
 */

namespace Vertex\Tax\Model\Cache;

/**
 * Handle data exchange serialization for StorageInterface.
 *
 * This is a compatibility fill for unsupported SerializerInterface in Magento < 2.2.
 */
class Serializer
{
    const MAX_ARRAY_DEPTH = 255;

    /**
     * Declaration of accepted types for serialization.
     *
     * @var array
     */
    private $supportedTypes = [
        'string',
        'integer',
        'double',
        'boolean',
        'NULL',
        'array',
        'object',
    ];

    /**
     * {@inheritdoc}
     */
    public function serialize($data)
    {
        $this->validate($data);

        return \json_encode($data);
    }

    /**
     * {@inheritdoc}
     */
    public function unserialize($string)
    {
        // Resets last error state
        \json_decode('{}');

        $result = \json_decode($string, false);

        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new \InvalidArgumentException('Cannot unserialize input');
        }

        return $result;
    }

    /**
     * Perform input validation to ensure that only supported data types are accepted for serialization.
     *
     * @param mixed $input
     * @param int $depth
     * @return void
     * @throws \InvalidArgumentException
     */
    private function validate($input, $depth = 0)
    {
        if (!in_array(gettype($input), $this->supportedTypes)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot serialize unsupported type "%s"', gettype($input))
            );
        } elseif (is_object($input) && !($input instanceof \stdClass)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot serialize unsupported object type "%s"', get_class($input))
            );
        } elseif (is_array($input)) {
            $depth++;

            if ($depth > self::MAX_ARRAY_DEPTH) {
                throw new \InvalidArgumentException(
                    sprintf('Serializable array depth cannot exceed %d', self::MAX_ARRAY_DEPTH)
                );
            }

            foreach ($input as $item) {
                $this->validate($item, $depth);
            }
        }
    }
}