Beispiel #1
0
 /**
  * Loads a staging configuration file and overloads the given array
  *
  * @param array the array to overload
  * @return array Merged configuration.
  */
 public static function overloadWithStagingConfig($array_to_overload)
 {
     // load staging config
     $staging_config = \Koch\Config\Adapter\Ini::readConfig(self::getFilename());
     // keys/values of array_to_overload are replaced with those of the staging_config
     return array_replace_recursive($array_to_overload, $staging_config);
 }
Beispiel #2
0
 public static function getDoctrineEntityManager($connectionParams = null)
 {
     try {
         if (is_array($connectionParams) === false) {
             include ROOT . 'core/config/adapter/ini.php';
             // get clansuite config
             $clansuite_config = \Koch\Config\Adapter\Ini::readConfig(ROOT_APP . 'configuration/clansuite.php');
             // reduce config array to the dsn/connection settings
             $connectionParams = $clansuite_config['database'];
         }
         // connect
         $config = new \Doctrine\DBAL\Configuration();
         $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
         $connection->setCharset('UTF8');
         // get Event and Config
         $event = $connection->getEventManager();
         $config = new \Doctrine\ORM\Configuration();
         // add Table Prefix
         $prefix = $connectionParams['prefix'];
         $tablePrefix = new \DoctrineExtensions\TablePrefix\TablePrefix($prefix);
         $event->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
         // setup Cache
         $cache = new \Doctrine\Common\Cache\ArrayCache();
         $config->setMetadataCacheImpl($cache);
         // setup Proxy Dir
         $config->setProxyDir(realpath(ROOT . 'application\\doctrine'));
         $config->setProxyNamespace('proxies');
         // setup Annotation Driver
         $driverImpl = $config->newDefaultAnnotationDriver(Helper::getModelPathsForAllModules());
         $config->setMetadataDriverImpl($driverImpl);
         // finally: instantiate EntityManager
         $entityManager = \Doctrine\ORM\EntityManager::create($connection, $config, $event);
         return $entityManager;
     } catch (\Exception $e) {
         $msg = 'The initialization of Doctrine2 failed!' . NL . NL . 'Reason: ' . $e->getMessage();
         throw new Exception($msg);
     }
 }
Beispiel #3
0
 /**
  *  ==========================================
  *          Load Configuration
  *  ==========================================
  *
  * 1. Load clansuite.config.php
  * 2. Load specific staging configuration (overloading clansuite.config.php)
  * 3. Maintenance check
  * 4. Alter php.ini settings
  */
 private static function initialize_Config()
 {
     // 1. load the main clansuite configuration file
     $clansuite_cfg_cached = false;
     if (APC === true and apc_exists('clansuite.config')) {
         self::$config = apc_fetch('clansuite.config');
         $clansuite_cfg_cached = true;
     }
     if ($clansuite_cfg_cached === false) {
         self::$config = \Koch\Config\Adapter\Ini::readConfig(ROOT . 'configuration/clansuite.php');
         if (APC === true) {
             apc_add('application.ini', self::$config);
         }
     }
     unset($clansuite_cfg_cached);
     // 2. Maintenance check
     if (isset(self::$config['maintenance']['maintenance']) and true === (bool) self::$config['maintenance']['maintenance']) {
         $token = false;
         // incoming maintenance token via GET
         if ($_GET['mnt'] !== null) {
             $tokenstring = $_GET['mnt'];
             $token = Clansuite_Securitytoken::ckeckToken($tokenstring);
         }
         // if token is false (or not valid) show maintenance
         if (false === $token) {
             Clansuite_Maintenance::show(self::$config);
         } else {
             self::$config['maintenance']['maintenance'] = 0;
             \Koch\Config\Ini::writeConfig(ROOT . 'configuration/clansuite.config.php', self::$config);
             // redirect to remove the token from url
             header('Location: ' . SERVER_URL);
         }
     }
     // 3. load staging configuration (overloading clansuite.config.php)
     if (true === (bool) self::$config['config']['staging']) {
         self::$config = \Koch\Config\Staging::overloadWithStagingConfig(self::$config);
     }
     /**
      * Deny service, if the system load is too high.
      */
     if (defined('DEBUG') and DEBUG == false) {
         $max_load = isset(self::$config['load']['max']) ? (double) self::$config['load']['max'] : 80;
         if (\Koch\Functions::get_server_load() > $max_load) {
             $retry = (int) mt_rand(45, 90);
             header('Retry-After: ' . $retry);
             header('HTTP/1.1 503 Too busy, try again later');
             die('HTTP/1.1 503 Server too busy. Please try again later.');
         }
     }
     /**
      *  ================================================
      *          4. Alter php.ini settings
      *  ================================================
      */
     set_time_limit(0);
     ini_set('short_open_tag', 'off');
     ini_set('arg_separator.input', '&');
     ini_set('arg_separator.output', '&');
     ini_set('default_charset', 'utf-8');
     self::setMemoryLimit('32');
     if (false === gc_enabled()) {
         gc_enable();
     }
 }