<?php firefly::config('db'); class db { protected static $_connector = null; protected static function _init() { self::$_connector || (self::$_connector = $database['connector']); } public function save($entity, $data) { self::$_connector || self::_init(); call_user_func_array(array(self::$_connector, 'save'), array($entity, $data)); } public function load($entity, $id) { self::$_connector || self::_init(); call_user_func_array(array(self::$_connector, 'load'), array($entity, $id)); } }
<?php firefly::config('mysql'); class mysql { protected static $_connector = null; protected static function _init() { $this->_connector = new mysqli($mysql['host'], $mysql['login'], $mysql['password'], $mysql['database']); $this->_connector->query('set names utf8'); } public static function save($entity, $data) { $sql = "insert into {$entity} (`" . implode("`, `", array_keys($data)) . "`) values ('" . implode("', '", $data) . "')"; $this->_connector->query($sql); } public static function load($entity, $id) { $result = $this->_connector->query("select * from {$entity} where id='{$id}'"); if ($result->num_rows > 0) { return $result->fetch_assoc(); } } }
<?php require_once 'autoload.php'; firefly::config('routes'); $request = str_replace('?' . $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']); if (isset($routes[$request])) { $spam = explode('/', $routes[$request]); count($spam) > 1 || ($spam[1] = 'index'); $classname = 'action_' . $spam[0]; $method = $spam[1]; if (is_callable(array($classname, $method))) { call_user_func($classname, "::{$method}"); } die; } header("HTTP/1.0 404 Not Found"); echo '<h1>Not found</h1>';