/** * Attempts to require a class at runtime if it has not been loaded yet. * * Classes in subdirectories must follow a PEAR style naming convention for classes to be autoloaded into walleye. * For example: controllers/folder/file.php , all classes in file.php must be FOLDER_classname. * This is not case-sensitive. * * If your class name has underscores in it, they will be converted to a slash for file resolution. * * @param string $class_name * @return void */ function __autoload($class_name) { if (strpos($class_name, '\\') !== FALSE) { $class_name_array = explode('\\', $class_name); $class_name = array_pop($class_name_array); } $class_name = str_replace('_', '/', $class_name) . '.php'; if (file_exists(\Walleye\Walleye::getInstance()->getServerBaseDir() . 'includes/app/controllers/' . strtolower($class_name))) { require \Walleye\Walleye::getInstance()->getServerBaseDir() . 'includes/app/controllers/' . strtolower($class_name); } if (file_exists(\Walleye\Walleye::getInstance()->getServerBaseDir() . 'includes/app/models/' . strtolower($class_name))) { require \Walleye\Walleye::getInstance()->getServerBaseDir() . 'includes/app/models/' . strtolower($class_name); } }
require '../includes/core/walleye.php'; $appOptions = \Walleye\Config::getAppOptions(); // perform checks on config file to make sure app can run if ($appOptions['BASE'] == '') { exit('Please define the BASE directory' . "\n"); } if ($appOptions['ENVIRONMENT'] == \Walleye\Config::TESTING) { exit('Change the Environment from TESTING. TESTING should only be used for unit tests.' . "\n"); } if ($appOptions['ENVIRONMENT'] == \Walleye\Config::DEVELOPMENT && $appOptions['DEV_DOMAIN'] == '') { exit('Please define the DEV_DOMAIN.' . "\n"); } if ($appOptions['ENVIRONMENT'] == \Walleye\Config::PRODUCTION && $appOptions['PROD_DOMAIN'] == '') { exit('Please define the PROD_DOMAIN.' . "\n"); } if (!is_bool($appOptions['LOG_ERRORS'])) { exit('LOG_ERRORS must be a boolean.' . "\n"); } if (!is_numeric($appOptions['SESSION_KEY_EXPIRE_TIME'])) { exit('SESSION_KEY_EXPIRE_TIME should be set AND be numeric' . "\n"); } if (!is_bool($appOptions['PRINT_APP_INFO_ON_LOAD'])) { exit('PRINT_APP_INFO_ON_LOAD must be a boolean.' . "\n"); } if ($appOptions['ENVIRONMENT'] == \Walleye\Config::PRODUCTION) { // Turn off all error reporting ini_set('display_errors', 0); } // run the application $app = \Walleye\Walleye::getInstance(); $app->run();
/** * Creates the User model based on the session array. This IS the logged in user. * Use this constructor if the user is not doing something critical * * @static * @return User */ public static function withSession() { $instance = null; if (isset($_SESSION[User::USER_SESSION])) { $db = Database::getInstance(); // get the session in the db $get_session_id_stmt = $db->prepare('SELECT id FROM Sessions WHERE session_key = ?'); $get_session_id_stmt->bind_param('s', $_SESSION[User::USER_SESSION]); $get_session_id_stmt->execute(); $session_id = ($session_row = $db->getRow($get_session_id_stmt)) ? $session_row->id : null; $get_session_id_stmt->close(); // find the user this session is associated with $get_user_id_and_date_created_stmt = $db->prepare('SELECT user_id, date_created FROM UserSessions WHERE session_id = ?'); $get_user_id_and_date_created_stmt->bind_param('i', $session_id); $get_user_id_and_date_created_stmt->execute(); if ($session_id && ($usersession_row = $db->getRow($get_user_id_and_date_created_stmt))) { $user_id = $usersession_row->user_id; $date_created = $usersession_row->date_created; // make sure this session hasn't expired in the database $date_created_array = explode(' ', $date_created); $appOptions = \Walleye\Walleye::getInstance()->getAppOptions(); if (daysFromNow($date_created_array[0]) <= $appOptions['SESSION_KEY_EXPIRE_TIME']) { $instance = User::withId($user_id); } } $get_user_id_and_date_created_stmt->close(); } return $instance; }