public function __construct(Config $config) { $this->config = $config; $set_names = sprintf("SET NAMES '%s';", str_replace('-', '', $config->encoding)); $this->db = new \PDO('mysql:host=' . $config->db_host . ';dbname=' . $config->db_db, $config->db_user, $config->db_pwd, array(\PDO::MYSQL_ATTR_INIT_COMMAND => $set_names)); Services::set($this->db); }
public function __construct(Config $config = null, $url = null) { if (!$url) { $url = get_current_path(); } spl_autoload_register(array($this, 'load_class')); $this->config = $config ? $config : new Config(); if (empty($this->config->encoding)) { $this->config->encoding = 'UTF-8'; } $this->config->lib_url = guess_lib_url(); $this->config->lib_dir = dirname(__FILE__); $this->config->app_dir = dirname($_SERVER['SCRIPT_FILENAME']); $this->config->app_url = guess_app_url(); $this->config->data_dir = $this->config->app_dir . '/data'; $this->config->data_url = $this->config->app_url . '/data'; Services::set($this->config); $this->method = strtolower($_SERVER['REQUEST_METHOD']); if ($this->method == 'post' && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) { if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'DELETE' || $_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') { $this->method = strtolower($_SERVER['HTTP_X_HTTP_METHOD']); } } $request_body = json_decode(file_get_contents('php://input'), true); if ($request_body === null) { $request_body = []; } $request_data = array_merge($request_body, $_GET, $_POST); $this->request = new Request(explode('?', $url)[0], $this->method, $request_data); Services::set($this->request); Services::set(new TemplateEngine()); $this->router = Services::inject_set(Router::class); }