/** * Constructor. * * @param string $connection_name The array index of the connection * to use as defined in config/mysqli.php and set in Registry. */ public function __construct($connection_name = 'primary') { // Load configuration Loader::get('config', 'mysqli'); $config = Registry::$config['mysqli'][$connection_name]; // Create connection $this->connection = new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $config['socket']); }
/** * Run the framework. * * @static * @return bool */ public static function run() { // Router determines controller, method, and arguments Router::current(); // Load controller if it exists $exists = Loader::get('controller' . DIRECTORY_SEPARATOR . Router::$controller); if ($exists) { return self::runController(Router::$controller); } // We couldn't find a controller. self::error404(); }
/** * Run the framework. */ public static function run() { // Router determines controller, method, and arguments Router::current(); // Load controller if it exists $exists = Loader::get('controller', Router::$controller); if ($exists === TRUE) { $controller = ucfirst(Router::$controller . '_Controller'); return self::run_controller($controller); } // We couldn't load the controller. self::error_404(); }
public function __construct() { $this->db = new Mysqli_Component(); // Overload default session handler. session_set_save_handler(array($this, 'open'), array($this, 'close'), array($this, 'read'), array($this, 'write'), array($this, 'destroy'), array($this, 'gc')); Loader::get('config', 'session'); // Set session lifetime. ini_set('session.gc_maxlifetime', Registry::$config['session']['lifetime']); // Set the garbage collection probablity. ini_set('session.gc_probability', Registry::$config['session']['gc_probability']); // Set the session name. session_name(Registry::$config['session']['name']); // Set cookie. session_set_cookie_params(Registry::$config['session']['lifetime'], Registry::$config['session']['cookie']['path'], Registry::$config['session']['cookie']['domain'], Registry::$config['session']['cookie']['secure'], Registry::$config['session']['cookie']['httponly']); // Start new session. session_start(); }
/** * Método que retorna o valor de acordo com os dados informados * @param string $tipo O tipo de informação a ser carregada * @param string $nome O nome especifico da configurações * @param string $dado O nome do dado a ser obtido o valor * @return void Os dados referentes as configurações pedidas * @throws ControllerException */ public static function data($tipo, $nome, $dado) { $loader = new Loader($tipo); $loader->dados($nome); return $loader->get($dado); }
<?php // This file is the most simple version of php magic function __autoload require 'autoloader.php'; // Set initial configuration $init = new Init(); $init->setup(); $init->setLang(); // Get loader for controller and template $loader = new Loader(); $loader->get();
/** * Determines the appropriate controller, method, and arguments * from the current URI request. * Where necessary, defaults will be employed. * Values are stored in local static members for use by the core. */ public static function current() { $current = self::getRequestPath(); // Are we being run from command line? if (PHP_SAPI === 'cli') { // $argv and $argc are disabled by default in some configurations. $argc = isset($argc) ? $argc : $_SERVER['argc']; if ($argc > 0) { $args = isset($argv) ? $argv : $_SERVER['argv']; // Merge all cli arguments as if they were in a uri from web context. $current = implode('/', $args); } else { $current = self::getRequestPath(); } } // Remove dot paths $current = preg_replace('#\\.[\\s./]*/#', '', $current); // Remove leading slash $current = ltrim($current, '/'); // Reduce multiple slashes $current = preg_replace('#//+#', '/', $current); // Remove front controller from URI if present (depends on variable used) $frontController = \Config::get('core.front_controller') . FILE_EXTENSION; if (substr($current, 0, strlen($frontController)) == $frontController) { $current = substr($current, strlen($frontController)); } // Remove any remaining leading/trailing slashes $current = trim($current, '/'); // Check for rewrites matching configuration values. Loader::get('config/rewrite'); $matched = $current; $rewrites = \Config::get('rewrites'); if (!empty($rewrites)) { foreach ($rewrites as $match => $replace) { $match = trim($match, '/'); // Exact match? if ($match == $current) { $matched = $replace; } elseif (preg_match('#^' . $match . '$#u', $current)) { if (strpos($replace, '$')) { // Replacement requires arguments that were parsed during match. $matched = preg_replace('#^' . $match . '$#u', $replace, $current); } else { // Found match, no parsed arguments required. $matched = $replace; } } } } $current = $matched; $parts = array(); if (strlen($current) > 0) { $parts = explode('/', $current); } if (empty($parts)) { self::$controller = \Config::get('core.default_controller'); } else { $controller = ''; while (count($parts)) { $controller .= array_shift($parts); if (Loader::search("controller/{$controller}")) { self::$controller = $controller; if (count($parts)) { self::$method = array_shift($parts); } if (count($parts)) { self::$arguments = $parts; } } else { $controller .= '/'; } } } if (empty(self::$method)) { self::$method = \Config::get('core.default_controller_method'); } }