Beispiel #1
0
 /**
  * Class constructor
  *
  * Setup Memcache(d)
  *
  * @return void
  */
 public function __construct()
 {
     // Try to load memcached server info from the config file.
     $defaults = $this->_memcacheConf['default'];
     $config = Config::getSoul()->CACHE;
     $memcacheConf = isset($config['MEMCACHED']) ? $config['MEMCACHED'] : null;
     if (is_array($memcacheConf)) {
         $this->_memcacheConf = array();
         foreach ($memcacheConf as $name => $conf) {
             $this->_memcacheConf[$name] = $conf;
         }
     }
     if (class_exists('Memcached', false)) {
         $this->_memcached = new \Memcached();
     } elseif (class_exists('Memcache', false)) {
         $this->_memcached = new \Memcache();
     } else {
         Log::normal('[Error] Failed to create Memcache(d) object; extension not loaded?');
     }
     foreach ($this->_memcacheConf as $cacheServer) {
         isset($cacheServer['HOST']) or $cacheServer['HOST'] = $defaults['HOST'];
         isset($cacheServer['PORT']) or $cacheServer['PORT'] = $defaults['PORT'];
         isset($cacheServer['WEIGHT']) or $cacheServer['WEIGHT'] = $defaults['WEIGHT'];
         if (get_class($this->_memcached) === 'Memcache') {
             // Third parameter is persistance and defaults to TRUE.
             $this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], true, $cacheServer['WEIGHT']);
         } else {
             $this->_memcached->addServer($cacheServer['HOST'], $cacheServer['PORT'], $cacheServer['WEIGHT']);
         }
     }
     Hook::listen(__CLASS__);
 }
Beispiel #2
0
 /**
  * Shutdown Handler
  *
  * This is the shutdown handler that is declared in framework.
  * The main reason we use this is to simulate
  * a complete custom exception handler.
  *
  * E_STRICT is purposively neglected because such events may have
  * been caught. Duplication or none? None is preferred for now.
  *
  * @return  void
  */
 public static function end()
 {
     $last_error = error_get_last();
     if (isset($last_error) && $last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)) {
         $type = self::getErrorType($last_error['type']);
         $text = self::renderHaltBody($type, $last_error['message'], $last_error['line'], $last_error['file']);
         $txt = self::renderLogBody($type, $last_error['message'], $last_error['file'], $last_error['line']);
         Log::normal($txt);
         self::halt($text, 500);
     }
 }
Beispiel #3
0
 public function exec($query)
 {
     array_push($this->logs, $query);
     Log::sql($this->last_query());
     array_push($this->queries, $this->last_query());
     return parent::exec($query);
 }
Beispiel #4
0
 /**
  * Constructor
  *
  * Initialize class properties based on the configuration array.
  *
  * @return void
  */
 public function __construct()
 {
     $config = Config::getSoul()->CACHE;
     isset($config['ADAPTER']) && ($this->_adapter = $config['ADAPTER']);
     isset($config['PREFIX']) && ($this->keyPrefix = $config['PREFIX']);
     $className = '\\Kotori\\Core\\Cache\\' . ucfirst($this->_adapter);
     $this->{$this->_adapter} = new $className();
     if (!$this->isSupported($this->_adapter)) {
         Log::normal('[Error] Cache adapter "' . $this->_adapter . '" is unavailable. Cache is now using "Dummy" adapter.');
         $this->_adapter = 'dummy';
     }
     Hook::listen(__CLASS__);
 }