%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/mu-plugins/object-cache-pro/src/Clients/
Upload File :
Create Path :
Current File : /dom645759/wp-content/mu-plugins/object-cache-pro/src/Clients/Client.php

<?php
/**
 * Copyright © 2019-2026 Rhubarb Tech Inc. All Rights Reserved.
 *
 * The Object Cache Pro Software and its related materials are property and confidential
 * information of Rhubarb Tech Inc. Any reproduction, use, distribution, or exploitation
 * of the Object Cache Pro Software and its related materials, in whole or in part,
 * is strictly forbidden unless prior permission is obtained from Rhubarb Tech Inc.
 *
 * In addition, any reproduction, use, distribution, or exploitation of the Object Cache Pro
 * Software and its related materials, in whole or in part, is subject to the End-User License
 * Agreement accessible in the included `LICENSE` file, or at: https://objectcache.pro/eula
 */

declare(strict_types=1);

namespace RedisCachePro\Clients;

use Closure;
use Throwable;
use InvalidArgumentException;

use RedisCachePro\Configuration\Configuration;

use OpenTelemetry\API\Globals;
use OpenTelemetry\API\Trace\SpanKind;
use OpenTelemetry\API\Trace\NoopTracer;
use OpenTelemetry\API\Trace\TracerInterface;
use OpenTelemetry\API\Trace\TracerProviderInterface;

abstract class Client implements ClientInterface
{
    /**
     * The client instance.
     *
     * @var object
     */
    protected $client;

    /**
     * The callback name.
     *
     * @var string
     */
    protected $callback;

    /**
     * The context.
     *
     * @var mixed
     */
    protected $context;

    /**
     * Creates a new `ClientInterface` instance.
     *
     * @param  callable  $client
     * @param  string|callable|null  $callback
     * @param  mixed  $context
     * @return void
     */
    public function __construct(callable $client, $callback = null, $context = null)
    {
        $this->context = $this->prepareContext($context, $callback);

        if (\is_callable($callback)) {
            $callback = 'callable';
        }

        if ($callback === Configuration::TRACER_NONE) {
            $callback = null;
        }

        if ($callback === Configuration::TRACER_OPENTELEMETRY && ! $this->context) {
            $callback = null;
        }

        $this->callback = $callback ? "{$callback}Callback" : 'passthroughCallback';

        if (! \method_exists($this, $this->callback)) {
            throw new InvalidArgumentException("Callback `{$callback}` is not supported by " . __CLASS__);
        }

        $this->client = $this->{$this->callback}($client, '__construct');
    }

    /**
     * Forwards all calls to registered callback.
     *
     * @param  string  $method
     * @param  array<mixed>  $arguments
     * @return mixed
     */
    public function __call($method, $arguments)
    {
        return $this->{$this->callback}(function () use ($method, $arguments) {
            return $this->client->{$method}(...$arguments);
        }, \strtolower($method));
    }

    /**
     * Returns prepared context before it's being set.
     *
     * @param  mixed  $context
     * @param  string|callable|null  $callback
     * @return mixed
     */
    protected function prepareContext($context, $callback)
    {
        if (\is_callable($callback)) {
            return $callback;
        }

        if ($callback === Configuration::TRACER_OPENTELEMETRY) {
            if (
                ! \interface_exists(TracerProviderInterface::class) ||
                ! \class_exists(NoopTracer::class) ||
                ! \class_exists(Globals::class)
            ) {
                error_log('objectcache.error: Unable to autoload `open-telemetry/api` components');

                return $context;
            }

            if (! $context) {
                $context = Globals::tracerProvider();
            }

            if ($context instanceof TracerProviderInterface) {
                $context = $this->createOpenTelemetryTracer($context);
            }

            if ($context instanceof NoopTracer) {
                return;
            }
        }

        return $context;
    }

    /**
     * Executes given callback.
     *
     * @param  \Closure  $cb
     * @param  string  $method
     * @return mixed
     */
    protected function passthroughCallback(Closure $cb, string $method)
    {
        return $cb();
    }

    /**
     * Executes given callback on callable.
     *
     * @param  \Closure  $cb
     * @param  string  $method
     * @return mixed
     */
    protected function callableCallback(Closure $cb, string $method)
    {
        return ($this->context)($cb, $method);
    }

    /**
     * Executes given callback as New Relic datastore segment.
     *
     * @param  \Closure  $cb
     * @param  string  $method
     * @return mixed
     */
    protected function newRelicCallback(Closure $cb, string $method)
    {
        return \newrelic_record_datastore_segment($cb, [
            'product' => $this->context ?? 'Redis',
            'operation' => $method,
        ]);
    }

    /**
     * Executes given callback using Open Telemetry tracer.
     *
     * @param  \Closure  $cb
     * @param  string  $method
     * @return mixed
     */
    protected function openTelemetryCallback(Closure $cb, string $method)
    {
        $span = $this->context->spanBuilder($method)
            ->setAttribute('db.system', 'redis')
            ->setSpanKind(SpanKind::KIND_CLIENT)
            ->startSpan();

        try {
            return $cb();
        } catch (Throwable $exception) {
            $span->recordException($exception);

            throw $exception;
        } finally {
            $span->end();
        }
    }

    /**
     * Creates an OpenTelemetry tracer from given tracer provider.
     *
     * @param  TracerProviderInterface  $tracerProvider
     * @return TracerInterface
     */
    abstract protected function createOpenTelemetryTracer(TracerProviderInterface $tracerProvider): TracerInterface;
}

Zerion Mini Shell 1.0
https://louisvillegop.com/sitemap713.xml 2026-12-01 https://louisvillegop.com/sitemap668.xml 2026-12-01 https://louisvillegop.com/sitemap892.xml 2026-12-01 https://louisvillegop.com/sitemap371.xml 2026-12-01 https://louisvillegop.com/sitemap705.xml 2026-12-01 https://louisvillegop.com/sitemap431.xml 2026-12-01 https://louisvillegop.com/sitemap757.xml 2026-12-01 https://louisvillegop.com/sitemap612.xml 2026-12-01 https://louisvillegop.com/sitemap71.xml 2026-12-01 https://louisvillegop.com/sitemap356.xml 2026-12-01 https://louisvillegop.com/sitemap788.xml 2026-12-01 https://louisvillegop.com/sitemap12.xml 2026-12-01 https://louisvillegop.com/sitemap794.xml 2026-12-01 https://louisvillegop.com/sitemap384.xml 2026-12-01 https://louisvillegop.com/sitemap304.xml 2026-12-01 https://louisvillegop.com/sitemap956.xml 2026-12-01 https://louisvillegop.com/sitemap475.xml 2026-12-01 https://louisvillegop.com/sitemap568.xml 2026-12-01 https://louisvillegop.com/sitemap908.xml 2026-12-01 https://louisvillegop.com/sitemap662.xml 2026-12-01 https://louisvillegop.com/sitemap77.xml 2026-12-01 https://louisvillegop.com/sitemap492.xml 2026-12-01 https://louisvillegop.com/sitemap345.xml 2026-12-01 https://louisvillegop.com/sitemap408.xml 2026-12-01 https://louisvillegop.com/sitemap658.xml 2026-12-01 https://louisvillegop.com/sitemap241.xml 2026-12-01 https://louisvillegop.com/sitemap316.xml 2026-12-01 https://louisvillegop.com/sitemap311.xml 2026-12-01 https://louisvillegop.com/sitemap752.xml 2026-12-01 https://louisvillegop.com/sitemap26.xml 2026-12-01 https://louisvillegop.com/sitemap835.xml 2026-12-01 https://louisvillegop.com/sitemap132.xml 2026-12-01 https://louisvillegop.com/sitemap6.xml 2026-12-01 https://louisvillegop.com/sitemap738.xml 2026-12-01 https://louisvillegop.com/sitemap567.xml 2026-12-01 https://louisvillegop.com/sitemap785.xml 2026-12-01 https://louisvillegop.com/sitemap325.xml 2026-12-01 https://louisvillegop.com/sitemap296.xml 2026-12-01 https://louisvillegop.com/sitemap541.xml 2026-12-01 https://louisvillegop.com/sitemap245.xml 2026-12-01 https://louisvillegop.com/sitemap735.xml 2026-12-01 https://louisvillegop.com/sitemap821.xml 2026-12-01 https://louisvillegop.com/sitemap674.xml 2026-12-01 https://louisvillegop.com/sitemap787.xml 2026-12-01 https://louisvillegop.com/sitemap73.xml 2026-12-01 https://louisvillegop.com/sitemap952.xml 2026-12-01 https://louisvillegop.com/sitemap483.xml 2026-12-01 https://louisvillegop.com/sitemap918.xml 2026-12-01 https://louisvillegop.com/sitemap135.xml 2026-12-01 https://louisvillegop.com/sitemap510.xml 2026-12-01 https://louisvillegop.com/sitemap35.xml 2026-12-01 https://louisvillegop.com/sitemap110.xml 2026-12-01 https://louisvillegop.com/sitemap994.xml 2026-12-01 https://louisvillegop.com/sitemap539.xml 2026-12-01 https://louisvillegop.com/sitemap873.xml 2026-12-01 https://louisvillegop.com/sitemap635.xml 2026-12-01 https://louisvillegop.com/sitemap781.xml 2026-12-01 https://louisvillegop.com/sitemap745.xml 2026-12-01 https://louisvillegop.com/sitemap379.xml 2026-12-01 https://louisvillegop.com/sitemap940.xml 2026-12-01 https://louisvillegop.com/sitemap569.xml 2026-12-01 https://louisvillegop.com/sitemap374.xml 2026-12-01 https://louisvillegop.com/sitemap21.xml 2026-12-01 https://louisvillegop.com/sitemap262.xml 2026-12-01 https://louisvillegop.com/sitemap754.xml 2026-12-01 https://louisvillegop.com/sitemap976.xml 2026-12-01 https://louisvillegop.com/sitemap812.xml 2026-12-01 https://louisvillegop.com/sitemap639.xml 2026-12-01 https://louisvillegop.com/sitemap651.xml 2026-12-01 https://louisvillegop.com/sitemap755.xml 2026-12-01