public static function initialize($environment, $configdir) { if (self::$instance instanceof self) { return; } $configuration = array(); // Load config foreach (self::getConfigFiles($configdir) as $configfile) { $configuration = array_merge_recursive(array_reduce(array_intersect_key(self::loadConfigFile($configfile), array_flip(array('all', $environment))), array('self', 'mergeWrapper')), $configuration); } // Set our instance, load kxConfig self::$instance = new self($environment, new kxConfig($configuration)); // Add any classes we want added to the autoloader. foreach (kxEnv::get('kx:autoload:load') as $repo => $opts) { kxEnv::set(sprintf('kx:autoload:repository:%s:id', $repo), kxAutoload::registerRepository(sprintf('%s/%s/%s', KX_ROOT, 'application/lib', $opts['path']), array('prefix' => $opts['prefix']))); } // Set up our input, remove any magic quotes if (is_array($_POST) and !empty($_POST)) { foreach ($_POST as $BUTTER => $TOAST) { // Skip arrays if (!is_array($TOAST)) { $_POST[$BUTTER] = kxFunc::strip_magic($TOAST); } } } // Clean up all of our input (cookies, get/post requests, etc) kxFunc::cleanInput($_GET); kxFunc::cleanInput($_POST); kxFunc::cleanInput($_COOKIE); kxFunc::cleanInput($_REQUEST); //Okay NOW let's parse our input $input = kxFunc::parseInput($_GET, array()); // Allow $_POST to overwrite $_GET self::$request = kxFunc::parseInput($_POST, $input) + self::$request; // Grab our app $_application = preg_replace("/[^a-zA-Z0-9\\-\\_]/", "", isset($_REQUEST['app']) && trim($_REQUEST['app']) ? $_REQUEST['app'] : "core"); // Make sure we get (hopefully) a string if (is_array($_application)) { $_application = array_shift($_application); } define('KX_CURRENT_APP', $_application); kxEnv::$current_application = KX_CURRENT_APP; kxEnv::$current_module = isset(self::$request['module']) ? self::$request['module'] : ''; kxEnv::$current_section = isset(self::$request['section']) ? self::$request['section'] : ''; // Cleanup kxEnv::$current_module = kxFunc::alphaNum(kxEnv::$current_module); kxEnv::$current_section = kxFunc::alphaNum(kxEnv::$current_section); // Load the cache self::$cache = kxCache::instance(); }