Atrauzzi\LaravelDoctrine\CacheFactory::getCacheProvider PHP Method

getCacheProvider() public static method

public static getCacheProvider ( $type, $configuration, $namespace = null, $providers = [] ) : CacheProvider
$type
$namespace
return Doctrine\Common\Cache\CacheProvider
    public static function getCacheProvider($type, $configuration, $namespace = null, $providers = [])
    {
        $providers = array_merge(static::$supportedProviders, $providers);
        if (!array_key_exists($type, $providers)) {
            throw new \RuntimeException('Unsupported Doctrine cache provider specified: ' . $type . '. Check your configuration.');
        }
        if (class_exists($providers[$type])) {
            $cache = $providers[$type]::getCacheProvider($configuration);
        } else {
            throw new ClassNotFoundException('Class not found [' . $providers[$type] . ']', new \ErrorException());
        }
        $cache->setNamespace($namespace);
        return $cache;
    }

Usage Example

 /**
  * Initializes cache. Defaults to Array cache.
  *
  * @return \Doctrine\Common\Cache\CacheProvider
  * @throws \Exception
  * @throws \Symfony\Component\Debug\Exception\ClassNotFoundException
  */
 protected function createCache()
 {
     if (is_null(config('doctrine.cache.provider'))) {
         return null;
     }
     $cacheProvider = config('doctrine.cache.provider');
     $supportedProviders = config('doctrine.cache.providers', []);
     $cacheConfiguration = config('doctrine.cache.' . $cacheProvider);
     $namespace = config('doctrine.cache.namespace', config('cache.prefix'));
     CacheFactory::setProviders($supportedProviders);
     return CacheFactory::getCacheProvider($cacheProvider, $cacheConfiguration, $namespace);
 }