public static function serve() { self::$config = Config::get('Router'); if (!empty(self::$config['hooks'])) { api::hook()->add(self::$config['hooks']); } api::hook()->run('Router.init'); $routes = !empty(self::$config['routes']) ? self::$config['routes'] : false; if (!is_array($routes) || empty($routes)) { api::hook()->run('Router.no_routes'); return; } $request_bits = explode("?", getenv("REQUEST_URI"), 2); self::$request = array_shift($request_bits); if (isset($routes[self::$request])) { self::$success = self::processRule($routes[self::$request]); } else { foreach ($routes as $regex => $class) { if (preg_match("#^" . $regex . "\$#si", self::$request, $match)) { array_shift($match); self::$success = self::processRule($class, $match); break; } } } if (!self::$success) { api::hook()->run('Router.404'); } api::hook()->run('Router.shutdown'); return; }
public function __construct($host = false, $username = false, $password = false, $database = false) { if (null === self::$config) { // Load static configuration on first instance of class self::$config = \Distynct\Config::get('Database'); } $this->host = $host; $this->username = $username; $this->password = $password; $this->database = $database; }
public function __construct() { $this->config = Config::get('Template'); if (!empty($this->config['path'])) { $this->path = rtrim($this->config['path'], "/\\") . DIRECTORY_SEPARATOR; } else { throw new Exception("Template.path configuration key not set."); } $this->debug = !empty($this->config['path']); if (!empty($this->config['hooks'])) { api::hook()->add($this->config['hooks']); } api::hook()->run('Template.init'); }
public function __construct($db_host = false, $db_user = false, $db_pass = false, $db_name = false, $persistent = false, $db_port = false) { $this->_server['db_host'] = false !== $db_host ? $db_host : Config::get('Database.host', 'localhost'); $this->_server['db_user'] = false !== $db_user ? $db_user : Config::get('Database.user'); $this->_server['db_pass'] = false !== $db_pass ? $db_pass : Config::get('Database.pass'); $this->_server['db_name'] = false !== $db_name ? $db_name : Config::get('Database.name'); $this->_server['persistent'] = false !== $persistent ? $persistent : Config::get('Database.persistent', false); $this->_server['db_port'] = false !== $db_port ? $db_port : Config::get('Database.port', 3306); if (true === Config::get("Database.log_enabled", false)) { $this->start_log(); } if (true === Config::get("Database.show_errors", false)) { $this->show_errors(); } return $this; }
public function __construct() { if (null === self::$config) { self::$config = Config::get('Session', array()); if (!isset(self::$config['cookie_name']) || "" === self::$config['cookie_name']) { self::$config['cookie_name'] = "session"; } if (!isset(self::$config['expires'])) { self::$config['expires'] = 7; // number of days } if (!isset(self::$config['salt'])) { self::$config['salt'] = substr(md5(getenv("HTTP_HOST")), 0, 8); } } $this->data = api::cookie()->get(self::$config['cookie_name'], null); $this->logged_in = null !== $this->data; }
public function __construct() { if (!class_exists('Memcache')) { throw new \Exception("Required class 'Memcache' not found."); } $this->handler = new \Memcache(); $config = Config::get('Cache.Memcache'); if (empty($config['servers'])) { throw new \Exception("Config 'Cache.Memcache.servers' is required yet empty."); } foreach ($config['servers'] as $server) { $this->handler->addServer($server['host'], !empty($server['port']) ? $server['port'] : 11211); } if (!empty($config['hash_key'])) { $this->hash_key = !empty($config['hash_key']); } if (isset($config['key_prefix']) && "" !== $config['key_prefix'] && false !== $config['key_prefix'] && null !== $config['key_prefix']) { $this->key_prefix = !empty($config['key_prefix']); } return $this; }