Sha256: 2b6fdebbb6071aea2f814a9729b52c084abbff06f51d1dbd9ae26d4ebfa7e6a5

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

<?php

namespace Predis\Options;

use Predis\Network\IConnectionCluster;
use Predis\Network\PredisCluster;

class ClientCluster extends Option {
    protected function checkInstance($cluster) {
        if (!$cluster instanceof IConnectionCluster) {
            throw new \InvalidArgumentException(
                'Instance of Predis\Network\IConnectionCluster expected'
            );
        }
        return $cluster;
    }

    public function validate($value) {
        if (is_callable($value)) {
            return $this->checkInstance(call_user_func($value));
        }
        $initializer = $this->getInitializer($value);
        return $this->checkInstance($initializer());
    }

    protected function getInitializer($fqnOrType) {
        switch ($fqnOrType) {
            case 'predis':
                return function() { return new PredisCluster(); };
            default:
                return function() use($fqnOrType) {
                    return new $fqnOrType();
                };
        }
    }

    public function getDefault() {
        return new PredisCluster();
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.25.1 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.25.0 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.24.0 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.23.5 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.23.4 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.23.3 doc/benchmarks/Predis/Options/ClientCluster.php
appstats-0.23.2 doc/benchmarks/Predis/Options/ClientCluster.php