예제 #1
0
 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();
 }
예제 #2
0
 /**
  * Get started
  */
 private function init()
 {
     if (self::$initiated !== TRUE) {
         //---------------------------------------------------------------------------------
         // Are we using a caching engine?
         // Check in the following order (most ideal to least):
         // WinCache, APC, Memcache, Xcache, eaccelerator (yuck), disk cache (double yuck)
         //---------------------------------------------------------------------------------
         // Wincache
         if (function_exists('wincache_ucache_info') && kxEnv::Get('kx:cache:wincache')) {
             require KX_LIB . '/kxCache/cacheInterface.php';
             require KX_LIB . '/kxCache/cacheWincache.php';
             self::$cacheLib = new cacheWincache(kxEnv::Get('kx:paths:main:path'));
         } else {
             if (function_exists('apc_cache_info') && kxEnv::Get('kx:cache:apc')) {
                 require KX_LIB . '/kxCache/engines/cacheInterface.php';
                 require KX_LIB . '/kxCache/engines/cacheApc.php';
                 self::$cacheLib = new classCacheApc(kxEnv::Get('kx:paths:main:path'));
             } else {
                 if (function_exists('memcache_connect') && kxEnv::Get('kx:cache:memcache:enabled')) {
                     require KX_LIB . '/kxCache/engines/cacheInterface.php';
                     require KX_LIB . '/kxCache/engines/cacheMemcache.php';
                     self::$cacheLib = new classCacheMemcache(kxEnv::Get('kx:paths:main:path'), kxEnv::Get('kx:cache:memcache'));
                 } else {
                     if (function_exists('xcache_info') && kxEnv::Get('kx:cache:xcache')) {
                         require KX_LIB . '/kxCache/engines/cacheInterface.php';
                         require KX_LIB . '/kxCache/engines/cacheXcache.php';
                         require IPS_KERNEL_PATH . 'classCacheXcache.php';
                         /*noLibHook*/
                         self::$cacheLib = new classCacheXcache(kxEnv::Get('kx:paths:main:path'));
                     } else {
                         if (function_exists('eaccelerator_put') && kxEnv::Get('kx:cache:eaccelerator')) {
                             require KX_LIB . '/kxCache/engines/cacheInterface.php';
                             require KX_LIB . '/kxCache/engines/cacheEaccelerator.php';
                             self::$cacheLib = new classCacheEaccelerator(kxEnv::Get('kx:paths:main:path'));
                         } else {
                             if (kxEnv::Get('kx:cache:diskcache')) {
                                 require KX_LIB . '/kxCache/engines/cacheInterface.php';
                                 require KX_LIB . '/kxCache/engines/cacheDisk.php';
                                 self::$cacheLib = new classCacheDiskcache(kxEnv::Get('kx:paths:main:path'));
                             }
                         }
                     }
                 }
             }
         }
         if (is_object(self::$cacheLib) && self::$cacheLib->fail) {
             // Failsafe in case the cache library somehow manages to load despite not having it installed?
             self::$cacheLib = NULL;
         }
         $caches = array();
         for ($i = 0; $i < 2; $i++) {
             if ($i == 0) {
                 // Load the global cache
                 $cacheData = kxEnv::fetchCoreConfig('cache');
                 $caches = self::_implodeConfig($cacheData);
                 $loads = kxEnv::fetchCoreConfig('cachetoload');
             } else {
                 // Load the cache for this app
                 $cacheData = kxEnv::fetchAppConfig(KX_CURRENT_APP, 'cache');
                 $caches = self::_implodeConfig($cacheData);
                 $loads = kxEnv::fetchAppConfig(KX_CURRENT_APP, 'cachetoload');
             }
             if (is_array($caches)) {
                 foreach ($caches as $path => $info) {
                     if (!IN_MANAGE && !empty($info['manage'])) {
                         continue;
                     }
                     if ($info['force_load']) {
                         $loadCaches[$path] = $path;
                     }
                 }
                 if (count($loads)) {
                     foreach (array_keys($loads) as $path) {
                         $loadCaches[$path] = $path;
                     }
                 }
             }
         }
         // Let's do it
         self::_loadCaches($loadCaches);
     }
     self::$initiated = TRUE;
 }