/** * Load and return a file's content * @param String $filename The file * @return String * @throws WFEFileNotFoundException */ public static function content($filename) { $filepath = ROOT . '/' . $filename; if (WFELoader::fileExists($filename)) { return file_get_contents($filepath); } else { throw new WFEFileNotFoundException($filepath); } }
public function img($img) { $response = new WFEResponse(); try { $response->setContent(WFELoader::content('public/img/' . $img)); } catch (WFEFileNotFoundException $e) { WFERouter::run404(); } $response->setFormat('image/' . pathinfo($img, PATHINFO_EXTENSION)); return $response; }
public static function connect() { WFELoader::load("core/libs/redbean/rb.php"); WFELoader::load("core/libs/QueryBuilder/QueryBuilder.php"); $host = WFEConfig::get('db::host'); $name = WFEConfig::get('db::name'); $user = WFEConfig::get('db::user'); $password = WFEConfig::get('db::password'); $dbEnabled = WFEConfig::get('db::enabled'); if ($dbEnabled == true) { R::setup('mysql:host=' . $host . '; dbname=' . $name, $user, $password); } }
/** * Render a smarty template * if $arg1 is a string it will render the template $arg1 with parameters $arg2 * if $arg1 is an array it will load the default template with parameters $arg1 * * @param mixed $arg1 * @param Array $arg2 * @return String Template rendered * @throws WFETemplateException If template does not exists */ public static function render($arg1 = null, $arg2 = array()) { self::init(); if (is_array($arg1)) { $tpl = self::defaultTemplate(); self::setParams($arg1); } elseif (is_string($arg1)) { $tpl = $arg1; self::setParams($arg2); } else { $tpl = self::defaultTemplate(); self::setParams($arg2); } if (!WFELoader::fileExists('app/templates/' . $tpl)) { throw new WFETemplateException($tpl); } $output = self::$smarty->fetch($tpl); return $output; }
/** * Return true if controller exists in app/controllers * @param String $controller * @return Boolean */ private static function controllerExists($controller) { return WFELoader::fileExists('app/controllers/' . $controller . '.php') && class_exists(self::getControllerClass($controller)); }
// set exception handler set_exception_handler(function (Exception $e) { if (WFEConfig::get('env') == 'dev') { exit($e->getMessage()); } elseif (WFEConfig::get('env') == 'prod') { $response = WFERouter::run(new WFERequest('GET', 'WFE500')); $response->send(); } }); // Register autoload WFEAutoload::register(__NAMESPACE__); // Load main config WFELoader::load('app/config/config.php'); // Load Database \core\ORM\WFEDb::connect(); // Load smarty WFELoader::load('core/libs/smarty/Smarty.class.php'); // set environment spec if (WFEConfig::get('env') == 'dev') { error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_ALL); } elseif (WFEConfig::get('env') == 'prod') { error_reporting(0); } else { throw new WFEDefinitionException('Config settings env is not set properly (must be dev or prod)'); } // init session WFEsession::init(); // init request data $request = new WFERequest(); // Routes request and get response WFERouter::run($request);