getMessage()); PageLayout::addBodyElements(MessageBox::error(__METHOD__ . ': ' . $e->getMessage())); $class = self::DEFAULT_CACHE_CLASS; $cache = new $class(); } return $cache; } /** * Load configured cache class and return its name. * * @return string the name of the configured cache class */ public static function loadCacheClass() { $cacheConfig = self::getConfig()->SYSTEMCACHE; $cache_class = $cacheConfig['type'] ?: null; # default class if ($cache_class === null) { $version = new DBSchemaVersion(); if ($version->get(1) < 224) { // db cache is not yet available, use StudipMemoryCache return MemoryCache::class; } return self::DEFAULT_CACHE_CLASS; } if (!class_exists($cache_class)) { throw new UnexpectedValueException("Could not find class: '$cache_class'"); } return $cache_class; } /** * Return an array of arguments required for instantiation of the cache * class. * * @return array the array of arguments */ public static function retrieveConstructorArguments() { $cacheConfig = self::getConfig()->SYSTEMCACHE; return $cacheConfig ?: []; } /** * Return an instance of a given class using some arguments. Unless the * memory cache is instantiated, the cache will be wrapped in a wrapper * class that uses a memory cache to reduce accesses to the cache. * * @param string $class the name of the class * @param array $arguments an array of arguments to be used by the constructor * * @return Cache an instance of the specified class * @throws \ReflectionException */ public static function instantiateCache($class, $arguments) { $reflection_class = new ReflectionClass($class); $cache = (is_array($arguments['config']) && count($arguments['config']) > 0) ? $reflection_class->newInstanceArgs($arguments['config']) : $reflection_class->newInstance(); if ($class !== MemoryCache::class) { return new Wrapper($cache); } return $cache; } }