/** * Get Cache instance, default when no type * is configured it will use var cache. * * @param string $types Cache type * @param bool $fallback fallback to var cache if all types fail? * @param bool $force force new instance * * @return Cache object of the request type * * @throws Exception if $fallback is false and Cache type(s) not found */ public static function getInstance($types = '', $fallback = true, $force = false) { if ($types == '') { $types = Config::getGlobal('cache_method', array()); } if (!is_array($types)) { $types = array($types); } foreach ($types as $type) { try { if (!$force && array_key_exists($type, self::$m_instances) && is_object(self::$m_instances[$type])) { Tools::atkdebug("cache::getInstance -> Using cached instance of {$type}"); return self::$m_instances[$type]; } else { self::$m_instances[$type] = new $type(); self::$m_instances[$type]->setNamespace(Config::getGlobal('cache_namespace', 'default')); self::$m_instances[$type]->setLifetime(self::$m_instances[$type]->getCacheConfig('lifetime', 3600)); self::$m_instances[$type]->setActive(Config::getGlobal('cache_active', true)); Tools::atkdebug("cache::getInstance() -> Using {$type} cache"); return self::$m_instances[$type]; } } catch (Exception $e) { Tools::atknotice("Can't instantatie atkCache class {$type}: " . $e->getMessage()); } } if (!$fallback) { throw new Exception('Cannot instantiate Cache class of the following type(s): ' . implode(', ', $types)); } // Default return var cache Tools::atkdebug('cache::getInstance() -> Using var cache'); return self::getInstance('var', false, $force); }
/** * Returns the query mode. * * @param string $query * * @return string Return r or w mode */ public function getQueryMode($query) { $query = strtolower($query); $regexes = array('^\\s*select(?!\\s+into)', '^\\s*show'); foreach ($regexes as $regex) { if (preg_match("/{$regex}/", $query)) { return 'r'; } } Tools::atknotice('Query mode not detected! Using write mode.'); return 'w'; }