Exemplo n.º 1
0
 public function testGetWithConnect()
 {
     $status = false;
     // not connected at start
     $open = function () use(&$status) {
         if ($status) {
             throw new \Exception("Already connected");
         }
         $status = true;
         return "FAKE DB CONNECTION";
     };
     $close = function ($db) use(&$status) {
         if (!$status) {
             throw new \Exception("Already closed");
         }
         $status = false;
     };
     Connections::add('tested', $open, $close);
     $this->assertEquals(false, static::$ref_connections->getValue()['tested']);
     $this->assertSame($open, static::$ref_open->getValue()['tested']);
     $this->assertSame($close, static::$ref_close->getValue()['tested']);
     $expected = "FAKE DB CONNECTION";
     $result = Connections::get('tested');
     $this->assertTrue($status);
     $this->assertEquals($expected, $result);
     $this->assertEquals($expected, static::$ref_connections->getValue()['tested']);
     // This should NOT throw MissingConfig
     $result = Connections::get('tested');
     $this->assertEquals($expected, $result);
     Connections::close('tested');
     $this->assertFalse($status);
     $this->assertEquals(false, static::$ref_connections->getValue()['tested']);
 }
Exemplo n.º 2
0
 public static function add_admin($login, $pwd)
 {
     /* Password encryption */
     $p = Security::encrypt('blowfish', $pwd);
     /* Add to db new admin */
     $db = Connections::get('core');
     $db->insert('a', array('b' => $p['ciphertext']));
     $aid = $db->last_id;
     $db->insert('m', array('n' => base64_encode($p['key']), 's' => $p['iv_size']));
     $mid = $db->last_id;
     $r = $db->insert('core_admin', array('login' => $login, 'a' => $aid, 'm' => $mid));
 }
Exemplo n.º 3
0
 public function testMultipleDatabase()
 {
     $database = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'test');
     $database1 = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3307', 'database' => 'test1');
     $db = new \Database($database);
     \Connections::add('test', $db);
     $db1 = new \Database($database1);
     \Connections::add('test1', $db1);
     $this->assertEquals($db, \Connections::get('test'));
     $this->assertEquals($db1, \Connections::get('test1'));
     $this->assertFalse($db === $db1);
 }
Exemplo n.º 4
0
 /**
  * Users statistic view
  *
  */
 public function users()
 {
     Tools::admin_logged();
     $db = Connections::get('user');
     $r = $db->fetchAll($db->select('user', array('username'))->statement);
     $datas = array('title' => 'Admin Dashboard - Users statistics', 'users' => $r);
     $this->__view->set_content_type('html');
     $this->__view->set_js(array('script.js'));
     $this->__view->set_body('admin', 'bo/users.tpl')->set_template('admin/bo/default.tpl');
     $this->__view->attach_data($datas);
     return $this->display();
 }
Exemplo n.º 5
0
 /**
  * @return data\Source
  * @throws exceptions\ConfigMissing
  */
 public static function db() : data\Source
 {
     $name = isset(static::$connection) ? static::$connection : 'default';
     return Connections::get($name);
 }
Exemplo n.º 6
0
 public function migrate()
 {
     $vars = $this->get_vars();
     $db = Connections::get($this->table_name());
     $db->import_model($vars);
 }
Exemplo n.º 7
0
 public function __construct()
 {
     parent::__construct(Connections::get('user'));
     $this->from($this->table_name());
 }