Exemplo n.º 1
0
 /**
  * Activate query-log
  * @param null|object $additionalParameters
  *     Additional parameters to be stored in query logs
  * @return boolean Returns false if query log is disabled
  * @throws \Exception
  * @uses Phramework\Database\Database
  */
 public function register($additionalParameters = null)
 {
     if ($additionalParameters && !is_object($additionalParameters)) {
         throw new \Exception('additionalParameters must be an object');
     }
     //Ignore registration if disabled setting is set to true
     if (isset($this->settings->disabled) && $this->settings->disabled) {
         return false;
     }
     //Get current global adapter
     $internalAdapter = \Phramework\Database\Database::getAdapter();
     if (!$internalAdapter) {
         throw new \Exception('Global database adapter is not initialized');
     }
     //Create new QueryLogAdapter instance, using current global adapter
     $queryLogAdapter = new QueryLogAdapter($this->settings, $internalAdapter, $additionalParameters);
     //Set newly created QueryLogAdapter instance as global adapter
     \Phramework\Database\Database::setAdapter($queryLogAdapter);
     return true;
 }
Exemplo n.º 2
0
 /**
  * @covers Phramework\QueryLog\QueryLog::register
  */
 public function testRegister()
 {
     $currentDatabaseAdapter = \Phramework\Database\Database::getAdapter();
     $this->assertInstanceOf('Phramework\\QueryLog\\QueryLogAdapter', $currentDatabaseAdapter);
 }