Bisna\Doctrine\Container::startCacheInstance PHP Метод

startCacheInstance() приватный Метод

Initialize Cache Instance.
private startCacheInstance ( array $config = [] ) : Doctrine\Common\Cache\Cache
$config array Cache Instance configuration.
Результат Doctrine\Common\Cache\Cache
    private function startCacheInstance(array $config = array())
    {
        $adapterClass = $config['adapterClass'];
        // FilesystemCache (extending abstract FileCache class) expects the directory as a parameter in the constructor
        if ($adapterClass == 'Doctrine\\Common\\Cache\\FilesystemCache') {
            $directory = isset($config['options']['directory']) ? $config['options']['directory'] : '/tmp/doctrine';
            $extension = isset($config['options']['extension']) ? $config['options']['extension'] : null;
            $adapter = new $adapterClass($directory, $extension);
        } else {
            $adapter = new $adapterClass();
        }
        // Define namespace for cache
        if (isset($config['namespace']) && !empty($config['namespace'])) {
            $adapter->setNamespace($config['namespace']);
        }
        if (method_exists($adapter, 'initialize')) {
            $adapter->initialize($config);
        } else {
            if ($adapter instanceof \Doctrine\Common\Cache\CouchbaseCache) {
                // Couchbase configuration
                $hosts = isset($config['options']['hosts']) ? $config['options']['hosts'] : array('localhost');
                $user = isset($config['options']['user']) ? $config['options']['user'] : '';
                $password = isset($config['options']['password']) ? $config['options']['password'] : '';
                $bucket = isset($config['options']['bucket']) ? $config['options']['bucket'] : 'default';
                $persistent = isset($config['options']['persistent']) ? $config['options']['persistent'] : true;
                // Prevent stupid PHP error of missing extension (if other driver is being used)
                $couchbaseClassName = 'Couchbase';
                $couchbase = new $couchbaseClassName($hosts, $user, $password, $bucket, $persistent);
                $adapter->setCouchbase($couchbase);
            } else {
                if ($adapter instanceof \Doctrine\Common\Cache\MemcacheCache) {
                    // Prevent stupid PHP error of missing extension (if other driver is being used)
                    $memcacheClassName = 'Memcache';
                    $memcache = new $memcacheClassName();
                    // Default server configuration
                    $defaultServer = array('host' => 'localhost', 'port' => 11211, 'persistent' => true, 'weight' => 1, 'timeout' => 1, 'retryInterval' => 15, 'status' => true);
                    if (isset($config['options']['servers'])) {
                        foreach ($config['options']['servers'] as $server) {
                            $server = array_replace_recursive($defaultServer, $server);
                            $memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retryInterval'], $server['status']);
                        }
                    }
                    $adapter->setMemcache($memcache);
                } else {
                    if ($adapter instanceof \Doctrine\Common\Cache\MemcachedCache) {
                        // Prevent stupid PHP error of missing extension (if other driver is being used)
                        $memcacheClassName = 'Memcached';
                        $memcache = new $memcacheClassName();
                        // Default server configuration
                        $defaultServer = array('host' => 'localhost', 'port' => 11211, 'weight' => 1);
                        if (isset($config['options']['servers'])) {
                            foreach ($config['options']['servers'] as $server) {
                                $server = array_replace_recursive($defaultServer, $server);
                                $memcache->addServer($server['host'], $server['port'], $server['weight']);
                            }
                        }
                        $adapter->setMemcached($memcache);
                    } else {
                        if ($adapter instanceof \Doctrine\Common\Cache\RedisCache) {
                            // Prevent stupid PHP error of missing extension (if other driver is being used)
                            $redisClassName = 'Redis';
                            $redis = new $redisClassName();
                            // Default server configuration
                            $defaultServer = array('host' => 'localhost', 'port' => 6379, 'timeout' => 0, 'persistent' => false, 'persistentId' => null, 'prefix' => null, 'password' => null, 'database' => 0);
                            $server = isset($config['options']) ? array_replace_recursive($defaultServer, $config['options']) : $defaultServer;
                            if (isset($server['persistent']) && $server['persistent']) {
                                $redis->pconnect($server['host'], $server['port'], $server['timeout'], isset($server['persistentId']) ? $server['persistentId'] : null);
                            } else {
                                $redis->connect($server['host'], $server['port'], $server['timeout']);
                            }
                            if (isset($server['password'])) {
                                $redis->auth($server['password']);
                            }
                            if (isset($server['prefix'])) {
                                $redis->setOption(\Redis::OPT_PREFIX, $server['prefix']);
                            }
                            $redis->select($server['database']);
                            $adapter->setRedis($redis);
                        }
                    }
                }
            }
        }
        return $adapter;
    }