예제 #1
0
 public function __construct()
 {
     $this->config = (require 'app/config/database.php');
     $driver = $this->config['connections'][$this->config['default']];
     $username = isset($driver['user']) ? $driver['user'] : null;
     $password = isset($driver['password']) ? $driver['password'] : null;
     $options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
     try {
         switch ($driver['driver']) {
             case 'mysql':
                 $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database'];
                 break;
             case 'pgsql':
                 $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database'] . ';port=' . $driver['port'];
                 break;
             case 'sqlite':
                 $options = null;
                 $dsn = $driver['driver'] . ':' . $driver['database'];
                 break;
             default:
                 $dsn = $driver['driver'] . ':host=' . $driver['host'] . ';dbname=' . $driver['database'];
         }
         parent::__construct($dsn, $username, $password, $options);
         $this->pdo = new TraceablePDO($this);
         Config::getInstance()->set(array('pdo' => $this->pdo));
     } catch (PDOException $e) {
         throw new Exception($e->getMessage());
     }
 }
예제 #2
0
 public function __construct()
 {
     $config = (require 'app/config/database.php');
     $driver = 'pdo_mysql';
     $db_config = $config['connections'][$config['default']];
     $username = isset($db_config['user']) ? $db_config['user'] : null;
     $password = isset($db_config['password']) ? $db_config['password'] : null;
     $database = isset($db_config['database']) ? $db_config['database'] : null;
     // set up the configuration
     $configDoctrine = new Configuration();
     foreach (Config::get('settings', 'modules') as $controller) {
         if (is_dir('src/' . $controller . '/Entity')) {
             $paths[] = 'src/' . $controller . '/Entity';
         }
     }
     $isDevMode = true;
     $driverImpl = $configDoctrine->newDefaultAnnotationDriver($paths, false);
     $configDoctrine->setMetadataDriverImpl($driverImpl);
     if ($isDevMode) {
         // set up simple array caching for development mode
         $cache = new ArrayCache();
     } else {
         // set up caching with APC for production mode
         $cache = new ApcCache();
     }
     $configDoctrine->setMetadataCacheImpl($cache);
     $configDoctrine->setQueryCacheImpl($cache);
     // set up proxy configuration
     $configDoctrine->setProxyDir('cache/Proxies');
     $configDoctrine->setProxyNamespace('Proxies');
     // auto-generate proxy classes if we are in development mode
     $configDoctrine->setAutoGenerateProxyClasses($isDevMode);
     // the connection configuration
     $dbParams = array('driver' => $driver, 'user' => $username, 'password' => $password, 'dbname' => $database, 'driverOptions' => array(1002 => 'SET NAMES utf8'));
     $debugStack = new DebugStack();
     $this->em = EntityManager::create($dbParams, $configDoctrine);
     $this->getEm()->getConnection()->getConfiguration()->setSQLLogger($debugStack);
     Config::getInstance()->set(array('doctrine' => $this->getEm()));
 }
예제 #3
0
 public static function get($key = null, $subkey = null)
 {
     $config = Config::getInstance()->config['database'];
     // If 'use_db_settings' = true, get settings from Database
     if ($config['use_db'] === true && $config['use_db_settings'] === true) {
         $db = new Database();
         $settings = $db->select("SELECT data FROM {$config['table_db_settings']} WHERE 1");
         // Add settings to the global config
         Config::getInstance()->combineSettings(array('settings' => json_decode($settings[0]['data'], true)));
     }
     foreach (Config::getInstance()->config['settings']['modules'] as $module) {
         if (is_file('App/' . $module . '/config/config.php')) {
             $config = (require 'App/' . $module . '/config/config.php');
             Config::getInstance()->combineSettings(array('settings' => $config));
         }
     }
     if ($key) {
         if (array_key_exists($key, Config::getInstance()->config)) {
             if ($subkey) {
                 if (array_key_exists($subkey, Config::getInstance()->config[$key])) {
                     return Config::getInstance()->config[$key][$subkey];
                 } else {
                     return false;
                 }
             } else {
                 return Config::getInstance()->config[$key];
             }
         } else {
             return null;
         }
     } else {
         return Config::getInstance()->config;
     }
 }
예제 #4
0
 /**
  * Application::__construct()
  *  
  * @param array $config
  */
 public function __construct(array $config)
 {
     isset($config['debug']) ? error_reporting(E_ALL | E_STRICT) && define('DEBUGING', true) : error_reporting(0) && define('DEBUGING', false);
     isset($config['default_controller']) ? $this->defaultFile = trim($config['default_controller'], '/') : null;
     Config::getInstance()->set(array('default_controller' => $config['default_controller']));
 }