malkusch\lock\mutex\MutexConcurrencyTest::provideMutexFactories PHP Метод

provideMutexFactories() публичный Метод

Provides Mutex factories.
public provideMutexFactories ( ) : callable[][]
Результат callable[][] The mutex factories.
    public function provideMutexFactories()
    {
        $path = stream_get_meta_data(tmpfile())["uri"];
        $cases = ["flock" => [function ($timeout = 3) use($path) {
            $file = fopen($path, "w");
            return new FlockMutex($file);
        }], "semaphore" => [function ($timeout = 3) use($path) {
            $semaphore = sem_get(ftok($path, "b"));
            $this->assertTrue(is_resource($semaphore));
            return new SemaphoreMutex($semaphore);
        }]];
        if (getenv("MEMCACHE_HOST")) {
            $cases["memcached"] = [function ($timeout = 3) {
                $memcached = new \Memcached();
                $memcached->addServer(getenv("MEMCACHE_HOST"), 11211);
                return new MemcachedMutex("test", $memcached, $timeout);
            }];
        }
        if (getenv("REDIS_URIS")) {
            $uris = explode(",", getenv("REDIS_URIS"));
            $cases["PredisMutex"] = [function ($timeout = 3) use($uris) {
                $clients = array_map(function ($uri) {
                    return new Client($uri);
                }, $uris);
                return new PredisMutex($clients, "test", $timeout);
            }];
            $cases["PHPRedisMutex"] = [function ($timeout = 3) use($uris) {
                $apis = array_map(function ($uri) {
                    $redis = new Redis();
                    $uri = parse_url($uri);
                    if (!empty($uri["port"])) {
                        $redis->connect($uri["host"], $uri["port"]);
                    } else {
                        $redis->connect($uri["host"]);
                    }
                    return $redis;
                }, $uris);
                return new PHPRedisMutex($apis, "test", $timeout);
            }];
        }
        return $cases;
    }