Spamworldpro Mini Shell
Spamworldpro


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/cartforge.co/app/code/StripeIntegration/Tax/Model/StripeTax/Request/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/cartforge.co/app/code/StripeIntegration/Tax/Model/StripeTax/Request/Cache.php
<?php

namespace StripeIntegration\Tax\Model\StripeTax\Request;

use \Magento\Framework\App\CacheInterface;
use Magento\Framework\Serialize\SerializerInterface;

class Cache
{
    public const STRIPE_CACHE_TAG = 'stripe_tax';

    private $cache;
    private $hash;
    private $serializer;

    public function __construct(
        CacheInterface $cache,
        SerializerInterface $serializer
    )
    {
        $this->cache = $cache;
        $this->serializer = $serializer;
    }

    public function sortRecursiveByKeys(&$request)
    {
        foreach ($request as &$component) {
            if (is_array($component))
                $this->sortRecursiveByKeys($component);
        }
        ksort($request);
    }

    public function setRequest($request)
    {
        $preparedRequest = $this->prepareRequest($request);
        $this->sortRecursiveByKeys($preparedRequest);
        $hash = hash('sha256', $this->serializer->serialize($preparedRequest));
        $this->setHash($hash);
    }

    /**
     * Take out the request components which are not needed
     *
     * @param $request
     * @return array
     */
    private function prepareRequest($request)
    {
        unset($request['customer_details']['address']['line1']);

        return $request;
    }

    private function setHash($hash)
    {
        $this->hash = $hash;
    }

    public function getCachedResponse()
    {
        $response = $this->cache->load($this->hash);
        if ($response) {
            return $this->serializer->unserialize($response);
        }

        return $response;
    }

    public function cacheResponse($response)
    {
        $serializedResponse = $this->serializer->serialize($response);
        $result = $this->cache->save($serializedResponse, $this->hash, [self::STRIPE_CACHE_TAG], 60 * 60);

        return $result ? $serializedResponse : $result;
    }

    public function invalidate()
    {
        $this->cache->clean([self::STRIPE_CACHE_TAG]);
    }
}

Spamworldpro Mini