Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MemcachedCaster.php

class MemcachedCaster

@author Jan Schädlich <jan.schaedlich@sensiolabs.de>

@final

Hierarchy

  • class \Symfony\Component\VarDumper\Caster\MemcachedCaster

Expanded class hierarchy of MemcachedCaster

File

vendor/symfony/var-dumper/Caster/MemcachedCaster.php, line 21

Namespace

Symfony\Component\VarDumper\Caster
View source
class MemcachedCaster {
    private static array $optionConstants;
    private static array $defaultOptions;
    public static function castMemcached(\Memcached $c, array $a, Stub $stub, bool $isNested) : array {
        $a += [
            Caster::PREFIX_VIRTUAL . 'servers' => $c->getServerList(),
            Caster::PREFIX_VIRTUAL . 'options' => new EnumStub(self::getNonDefaultOptions($c)),
        ];
        return $a;
    }
    private static function getNonDefaultOptions(\Memcached $c) : array {
        self::$defaultOptions ??= self::discoverDefaultOptions();
        self::$optionConstants ??= self::getOptionConstants();
        $nonDefaultOptions = [];
        foreach (self::$optionConstants as $constantKey => $value) {
            if (self::$defaultOptions[$constantKey] !== ($option = $c->getOption($value))) {
                $nonDefaultOptions[$constantKey] = $option;
            }
        }
        return $nonDefaultOptions;
    }
    private static function discoverDefaultOptions() : array {
        $defaultMemcached = new \Memcached();
        $defaultMemcached->addServer('127.0.0.1', 11211);
        $defaultOptions = [];
        self::$optionConstants ??= self::getOptionConstants();
        foreach (self::$optionConstants as $constantKey => $value) {
            $defaultOptions[$constantKey] = $defaultMemcached->getOption($value);
        }
        return $defaultOptions;
    }
    private static function getOptionConstants() : array {
        $reflectedMemcached = new \ReflectionClass(\Memcached::class);
        $optionConstants = [];
        foreach ($reflectedMemcached->getConstants() as $constantKey => $value) {
            if (str_starts_with($constantKey, 'OPT_')) {
                $optionConstants[$constantKey] = $value;
            }
        }
        return $optionConstants;
    }

}

Members

Title Sort descending Modifiers Object type Summary
MemcachedCaster::$defaultOptions private static property
MemcachedCaster::$optionConstants private static property
MemcachedCaster::castMemcached public static function
MemcachedCaster::discoverDefaultOptions private static function
MemcachedCaster::getNonDefaultOptions private static function
MemcachedCaster::getOptionConstants private static function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal