HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: //var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/Features/Commerce/RemoteIdBus.php
<?php

namespace GoDaddy\WordPress\MWC\Core\Features\Commerce;

use GoDaddy\WordPress\MWC\Common\Cache\Cache;
use GoDaddy\WordPress\MWC\Common\Cache\Contracts\CacheableContract;
use GoDaddy\WordPress\MWC\Common\Helpers\TypeHelper;
use GoDaddy\WordPress\MWC\Common\Traits\CanGetNewInstanceTrait;

class RemoteIdBus
{
    use CanGetNewInstanceTrait;

    /**
     * @var string A prefix for the cache key.
     */
    protected const KEY_PREFIX = 'commerceRemoteId_';

    /**
     * @var CacheableContract The object storage
     */
    protected CacheableContract $cache;

    final public function __construct(CacheableContract $cache)
    {
        $this->cache = $cache;
    }

    /**
     * Static constructor that uses the specified key for storing the remote ID into the object storage.
     *
     * @param string $key The key to use when setting/getting this remote ID.
     * @return static
     */
    public static function withKey(string $key)
    {
        return new static((new Cache())->key(static::KEY_PREFIX.$key));
    }

    /**
     * Sets the Remote ID to object storage.
     *
     * @param string $remoteId
     * @return $this
     */
    public function set(string $remoteId)
    {
        $this->cache->set($remoteId, false);

        return $this;
    }

    /**
     * Gets the Remote ID from the object storage.
     *
     * @return non-empty-string|null
     */
    public function get() : ?string
    {
        return TypeHelper::string($this->cache->get(), '') ?: null;
    }
}