/** * @return \Illuminate\Database\Capsule\Manager */ public static function instance() { if (static::$_instance === null) { $config = Config::get("database"); static::$_instance = new \Illuminate\Database\Capsule\Manager(); if ($config["connections"] && is_array($config["connections"])) { foreach ($config["connections"] as $key => $cfg) { static::$_instance->addConnection($cfg, $key); } } static::$_instance->setAsGlobal(); } return static::$_instance; }
/** * @param string $namespace * @return \Predis\Client * @throws \Exception */ public static function connection($namespace = "default") { if (!isset(static::$instance[$namespace]) || !static::$instance[$namespace]) { $config = Config::get("cache.redis"); if (!isset($config[$namespace])) { throw new \Exception("redis cache config has not key {$namespace}", 1); } $config = $config[$namespace]; $parameters = $config["parameters"]; $options = $config["options"]; $redis = new \Predis\Client($parameters, $options); static::$instance[$namespace] = $redis; } return static::$instance[$namespace]; }
/** * @param string $namespace * @return \Memcached * @throws \Exception */ public static function connection($namespace = "default") { if (!isset(static::$instance[$namespace]) || !static::$instance[$namespace]) { $config = Config::get("cache.memcache"); if (!isset($config[$namespace])) { throw new \Exception("cache config has not key {$namespace}", 1); } $config = $config[$namespace]; $memcached = new \Memcached($config["persistent_id"]); $memcached->addServers($config["servers"]); $options = [\Memcached::OPT_LIBKETAMA_COMPATIBLE => true, \Memcached::OPT_COMPRESSION => true]; $options = array_merge($options, (array) $config["options"]); $memcached->setOptions($options); static::$instance[$namespace] = $memcached; } return static::$instance[$namespace]; }
/** * @return null * @throws \Exception */ public static function instance() { if (static::$_instance === null) { $session = Config::get("session"); $storage = "\\Sirius\\Session\\Adapter\\"; switch ($session["adapter"]) { case "Cookie": $config = Config::get("cookie"); break; case "Memcached": $config = Config::get("cache.memcache.session"); break; case "Redis": $config = Config::get("cache.redis.session"); break; default: throw new \Exception("Session adapter not found :" . $session["adapter"]); } $storage .= $session["adapter"]; self::$_instance = new $storage(array_merge($session, $config)); } return static::$_instance; }