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\CasterView 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 |