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(); }
/** * Rebuild a cache using defined $CACHE settings in it's extensions file * * @param string Cache path * @param string Application * @return @e void */ public static function rebuildCache($path, $app = '') { $app = kxFunc::alphaNum($app); $caches = array(); if ($app) { if ($app == 'base') { $caches = self::_implodeConfig(kxEnv::fetchCoreConfig('cache')); } else { if (isset(kxEnv::$applications[$app]) && !kxFunc::isAppEnabled($app)) { return; } $caches = self::_implodeConfig(kxEnv::fetchAppConfig($app, 'cache')); } } else { $caches = self::_implodeConfig(kxEnv::fetchCoreConfig('cache')); foreach (array_keys($kxEnv::$applications) as $appName) { $appCache = self::_implodeConfig(kxEnv::fetchAppConfig($appName, 'cache')); if (is_array($appCache)) { $caches = array_merge($caches, $appCache); } } } if (isset($caches[$path])) { $recacheFile = $caches[$path]['recache_file']; if ($recacheFile && is_file($recacheFile)) { // If the recache function is in the modules directory, check if we're using a module extender for this module if (strpos($recacheFile, '/modules') !== FALSE) { $className = kxFunc::loadModule($recacheFile, $caches[$key]['recache_class']); } elseif ($app) { $className = kxFunc::loadHelper($recacheFile, $caches[$key]['recache_class'], $app == 'global' ? 'core' : $app); } if (!$className) { $className = $caches[$key]['recache_class']; } $recache = new $className(kxEnv::getInstance()); if (method_exists($recache, 'makeRegistryShortcuts')) { $recache->makeRegistryShortcuts(kxEnv::getInstance()); } $recache->{$caches}[$path]['recache_function'](); } } }