예제 #1
0
 public function testTableName()
 {
     $users = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'users');
     $user_db = new \Database($users);
     \Connections::add('user', $user_db);
     $userModel = new \UserModel();
     $user_table = $userModel->table_name();
     $this->assertEquals($user_table, 'user');
 }
예제 #2
0
 /**
  * @param $applicationID
  * @param $channel
  * @param $payload
  * @param bool|Connection\ClientConnection $exclude
  */
 public function publish($applicationID, $channel, $payload, $exclude = false)
 {
     $clients = $this->connections->getAllByAppIDAndChannel($applicationID, $channel);
     $payload = ['channel' => $channel, 'payload' => $payload];
     foreach ($clients as $client) {
         if ($client !== $exclude) {
             $client->writePayload('payload', $payload);
         }
     }
     $this->permanence->addPayloadBySubscription($channel, json_encode($payload));
 }
예제 #3
0
파일: Tools.php 프로젝트: kranack/frmwrk
 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));
 }
예제 #4
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);
 }
예제 #5
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();
 }
예제 #6
0
 public static function createInstance($t1_name = NULL, $t2_name = NULL, $t1_id = NULL, $t2_id = NULL)
 {
     $temp = Connections::getByField($t1_name, $t1_id);
     // return $temp;
     if (!$temp) {
         $flag = true;
         foreach ($temp as $item) {
             if ($item->t2_name == $t2_name && $item->t2_id == $t2_id) {
                 $flag = false;
                 $found = $item;
             }
         }
         if ($flag) {
             $init = new Connections();
             $init->id = null;
             $init->t1_name = $t1_name;
             $init->t2_name = $t2_name;
             $init->t1_id = $t1_id;
             $init->t2_id = $t2_id;
             $init->save();
             return $init;
         }
     }
     $init = recast('Connections', $found);
     return $init;
 }
예제 #7
0
 public static function getCrypt()
 {
     if (!self::$crypt) {
         $crypt = mcrypt_module_open('tripledes', '', 'ecb', '');
         $random_seed = strstr(PHP_OS, "WIN") ? MCRYPT_RAND : MCRYPT_DEV_RANDOM;
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($crypt), $random_seed);
         $expected_key_size = mcrypt_enc_get_key_size($crypt);
         $key = substr(md5(EDITOR_BLOWFISH), 0, $expected_key_size);
         mcrypt_generic_init($crypt, $key, $iv);
         self::$crypt = $crypt;
     }
     return self::$crypt;
 }
예제 #8
0
파일: Model.php 프로젝트: alkemann/h2l
 /**
  * @return data\Source
  * @throws exceptions\ConfigMissing
  */
 public static function db() : data\Source
 {
     $name = isset(static::$connection) ? static::$connection : 'default';
     return Connections::get($name);
 }
예제 #9
0
 public function testOkToCallCloseWithoutCloseConfigured()
 {
     static::$ref_connections->setValue(['tested' => true]);
     static::$ref_open->setValue(['tested' => function () {
     }]);
     Connections::close('tested');
 }
예제 #10
0
파일: Model.php 프로젝트: kranack/frmwrk
 public function migrate()
 {
     $vars = $this->get_vars();
     $db = Connections::get($this->table_name());
     $db->import_model($vars);
 }
예제 #11
0
<?php

/* Database configuration */
$users = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'users');
$posts = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3307', 'database' => 'posts');
$core = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'core');
$test = array('engine' => 'mysql', 'host' => 'localhost', 'username' => 'root', 'password' => '', 'port' => '3306', 'database' => 'test');
$user_db = new Database($users);
Connections::add('user', $user_db);
$post_db = new Database($posts);
Connections::add('post', $post_db);
$core_db = new Database($core);
Connections::add('core', $core_db);
$test_db = new Database($test);
Connections::add('test', $test_db);
//Connections::add('test', "string");
/* Migration */
$user = new UserModel();
//$user->migrate();
$post = new PostModel($post_db);
//$post->migrate();
예제 #12
0
 public function __construct()
 {
     parent::__construct(Connections::get('user'));
     $this->from($this->table_name());
 }