Exemple #1
0
 /**
  * Get connection to database
  *
  * @param string $name Connection name
  * @param array $config Connection config (not required)
  *
  * @return \Kalibri\Db\Driver\Base
  */
 public function getConnection($name = null, $config = null)
 {
     // Use default connection name if name is not passed
     $name = $name ?: $this->_defaultConnectName;
     // Check is driver already connected
     if ($this->isConnected($name)) {
         return $this->_connections[$name];
     }
     // Is config not passed and we have stored config
     if (!$config && isset($this->_config['connection'][$name])) {
         $config = $this->_config['connection'][$name];
     } else {
         // Config not passed and not available in config file
         \Kalibri::error()->show("Invalid DB connection name '{$name}'.");
     }
     // Calculate driver name
     $driverName = '\\Kalibri\\Db\\Driver\\' . \ucfirst($config['driver']);
     try {
         $this->_connections[$name] = new $driverName($config);
         \Kalibri::logger()->add(Logger::L_INFO, "Connected to database: driverName={$driverName}, connection={$name}");
     } catch (Exception $e) {
         \Kalibri::error()->showException($e);
     }
     // Return connected driver
     return $this->_connections[$name];
 }
Exemple #2
0
 public function remove($key)
 {
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'REMOVE: ' . $key, $this);
     }
     unset($this->_local[$key]);
     return $this->_memcache->delete($key);
 }
Exemple #3
0
 /**
  * Show page not found page
  */
 public function show404()
 {
     \Kalibri::event()->trigger('pageNotFoundError');
     @ob_end_clean();
     \Kalibri::logger()->add(Logger::L_ERROR, 'Page not found: ' . \Kalibri::uri()->getUri());
     $viewName = \Kalibri::config()->get('error.view.404');
     if ($viewName) {
         (new \Kalibri\View($viewName))->assignArray(['pageUrl' => \Kalibri::uri()->getUri()])->render();
     }
     exit;
 }
 protected function init()
 {
     \Kalibri::config()->load();
     if ($this->_mode) {
         \Kalibri::config()->load($this->_mode);
     }
     // Set list of classes that will be auto inited on use
     \Kalibri::setAutoInitClasses(\Kalibri::config()->get('init.classes'));
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'init', $this);
     }
 }
Exemple #5
0
 public function execStatment($query, array $params = null)
 {
     if (\Kalibri::config()->get('debug.log.is-enabled', false) && \Kalibri::config()->get('debug.log.collect-db-queries', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'SQL query:' . $query, $this);
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'SQL params:' . var_export($params, true), $this);
     }
     try {
         $stmt = $this->connect()->prepare($query);
         $stmt->execute($params);
     } catch (\Exception $e) {
         $exception = new \Kalibri\Db\Exception($e->getMessage());
         $exception->setQueryinfo($query, $params);
         throw $exception;
     }
     return new \Kalibri\Db\Result\Mysql($stmt);
 }
Exemple #6
0
 protected function init()
 {
     K_COMPILE_ROUTES && \Kalibri::compiler()->compile(Compiler::NAME_BASE);
     \Kalibri::config()->load();
     if ($this->_mode) {
         try {
             \Kalibri::config()->load($this->_mode);
         } catch (\Exception $e) {
         }
     }
     // Set list of classes that will be auto inited on use
     \Kalibri::setAutoInitClasses(\Kalibri::config()->get('init.classes'));
     //\Kalibri::logger()->init( \Kalibri::config()->get('debug.log') );
     \Kalibri::router()->setSegments(\Kalibri::uri()->getSegments());
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'init', $this);
     }
     ob_start();
 }