public function __construct() { //bypass namespaces? if (Config::get('namespaces') !== null && Config::get('namespaces') === false) { LazyLoad::on(); } //start the session class Session::init(); //sets the protected url $this->_getUrl(); }
/** * Load a given model. * @param string path to file * @example load('blog/model/blog') * @example load('blog/model/blog.php') * @return object */ public static function load($model = false) { $path = DOC_ROOT . Config::get('paths', 'modules'); if ($model && File::isFile($path . $model . '.php')) { $array = explode('/', $model); $modelName = end($array); require $path . $model . '.php'; return new $modelName(); } return false; }
/** * Load a given JavaScript file. * @param string path to file * @return boolean */ public static function js($file = false) { if ($file && !Text::contains($file, '.js')) { $file .= '.js'; } $path = DOC_ROOT . Config::get('paths', 'js'); if ($file && File::isFile($path . $file)) { echo '<script>'; require $path . $file; echo '</script>'; return true; } return false; }
public static function errorMessage($error, $print_error = false, $error_file = 'errorlog.html') { $error_file = realpath(Config::get('root_dir') . '/../log') . '/log.html'; $date = date('M d, Y G:iA'); $log_message = "<p>Error on {$date} - {$error}</p>"; if (is_file($error_file) === false) { file_put_contents($error_file, ''); } $content = file_get_contents($error_file); file_put_contents($error_file, $log_message . $content); if ($print_error == true) { echo $log_message; exit; } }
/** * Initialise a session. * Contains session_start(); */ public static function init() { if (self::$_sessionStarted == false) { self::start(); self::$_sessionStarted = true; } // Thanks Jon - http://stackoverflow.com/questions/8311320/how-to-change-the-session-timeout-in-php $now = time(); if (isset($_SESSION['expiration_time']) && $now > $_SESSION['expiration_time']) { self::destroy(); self::start(); } $timeout = 3600; if (!empty(Config::get('session', 'timeout'))) { $timeout = Config::get('session', 'timeout'); } $_SESSION['expiration_time'] = $now + $timeout; }
<?php use Prototypemvc\Core\Config; use Prototypemvc\Core\Bootstrap; ini_set('display_errors', false); require '../vendor/autoload.php'; ob_start(); define('DOC_ROOT', realpath(dirname(__FILE__) . '/../')); define('BASE_URL', 'http://' . $_SERVER['HTTP_HOST']); $environment = Config::get('environment', 'live'); $timezone = config::get('environment', $environment, 'timezone'); date_default_timezone_set($timezone); $app = new Bootstrap(); $app->setController('welcome'); $app->init(); ob_flush();