mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 12:09:20 +03:00
Predis to v2.2.2
This commit is contained in:
parent
9510347d3a
commit
969dca5f7e
449 changed files with 22013 additions and 2 deletions
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Predis package.
|
||||
*
|
||||
* (c) 2009-2020 Daniele Alessandri
|
||||
* (c) 2021-2023 Till Krüss
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Predis\Command\Redis\Container;
|
||||
|
||||
use Predis\ClientConfiguration;
|
||||
use Predis\ClientInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class ContainerFactory
|
||||
{
|
||||
private const CONTAINER_NAMESPACE = "Predis\Command\Redis\Container";
|
||||
|
||||
/**
|
||||
* Mappings for class names that corresponds to PHP reserved words.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $specialMappings = [
|
||||
'FUNCTION' => FunctionContainer::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates container command.
|
||||
*
|
||||
* @param ClientInterface $client
|
||||
* @param string $containerCommandID
|
||||
* @return ContainerInterface
|
||||
*/
|
||||
public static function create(ClientInterface $client, string $containerCommandID): ContainerInterface
|
||||
{
|
||||
$containerCommandID = strtoupper($containerCommandID);
|
||||
$commandModule = self::resolveCommandModuleByPrefix($containerCommandID);
|
||||
|
||||
if (null !== $commandModule) {
|
||||
if (class_exists($containerClass = self::CONTAINER_NAMESPACE . '\\' . $commandModule . '\\' . $containerCommandID)) {
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('Given module container command is not supported.');
|
||||
}
|
||||
|
||||
if (class_exists($containerClass = self::CONTAINER_NAMESPACE . '\\' . $containerCommandID)) {
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
if (array_key_exists($containerCommandID, self::$specialMappings)) {
|
||||
$containerClass = self::$specialMappings[$containerCommandID];
|
||||
|
||||
return new $containerClass($client);
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('Given container command is not supported.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $commandID
|
||||
* @return string|null
|
||||
*/
|
||||
private static function resolveCommandModuleByPrefix(string $commandID): ?string
|
||||
{
|
||||
$modules = ClientConfiguration::getModules();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if (preg_match("/^{$module['commandPrefix']}/", $commandID)) {
|
||||
return $module['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue