Ejemplo n.º 1
0
 /**
  * Common public method to create a cache instance given a definition.
  *
  * This is used by the static make methods.
  *
  * @param cache_definition $definition
  * @return cache_application|cache_session|cache_store
  * @throws coding_exception
  */
 public function create_cache(cache_definition $definition)
 {
     $class = $definition->get_cache_class();
     if ($this->is_initialising()) {
         // Do nothing we just want the dummy store.
         $stores = array();
     } else {
         $stores = cache_helper::get_cache_stores($definition);
     }
     if (count($stores) === 0) {
         // Hmm no stores, better provide a dummy store to mimick functionality. The dev will be none the wiser.
         $stores[] = $this->create_dummy_store($definition);
     }
     $loader = null;
     if ($definition->has_data_source()) {
         $loader = $definition->get_data_source();
     }
     while (($store = array_pop($stores)) !== null) {
         $loader = new $class($definition, $store, $loader);
     }
     return $loader;
 }