コード例 #1
0
ファイル: ArrayTest.php プロジェクト: sometumi/yun-lib
 public function test_rekey()
 {
     $target = array('id' => 9, 'name' => 'jim');
     $arr = array(array('id' => 8, 'name' => 'tom'), $target, array('id' => 10, 'name' => 'tom'));
     $re = Yun_Array::rekey($arr, 'id');
     $this->assertArrayHasKey(8, $re);
     $this->assertArrayHasKey(9, $re);
     $this->assertArrayHasKey(10, $re);
     $this->assertEquals($re[9], $target);
 }
コード例 #2
0
 /** 
  * @see Yun_Db_Mysql_Adapter_Interface::connect()
  */
 public function connect(array $conf)
 {
     $socket = Yun_Array::get($conf, 'socket', '');
     $host = Yun_Array::get($conf, 'host');
     $port = Yun_Array::get($conf, 'port');
     $dbname = Yun_Array::get($conf, 'dbname');
     $user = Yun_Array::get($conf, 'user');
     $pass = Yun_Array::get($conf, 'pass');
     $this->mysqli = new mysqli($host, $user, $pass, $dbname, $port, $socket);
     if ($this->mysqli->connect_errno) {
         $this->error_code = $this->mysqli->connect_errno;
         $this->error_info = $this->mysqli->connect_error;
         return false;
     } else {
         return true;
     }
 }
コード例 #3
0
 /**
  * 
  * @see Yun_Db__Adapter_Interface::connect()
  */
 public function connect(array $conf)
 {
     try {
         $host = Yun_Array::get($conf, 'host');
         $port = Yun_Array::get($conf, 'port');
         $dbname = Yun_Array::get($conf, 'dbname');
         $user = Yun_Array::get($conf, 'user');
         $pass = Yun_Array::get($conf, 'pass');
         $dsn = "pgsql:host={$host};port={$port};dbname={$dbname}";
         $pdo = new Pdo($dsn, $user, $pass);
         $this->initPdo($pdo);
         return true;
     } catch (Exception $e) {
         $this->error_code = $e->getCode();
         $this->error_info = $e->getMessage();
         return false;
     }
 }
コード例 #4
0
 protected function getAdapterInstance(array $conf)
 {
     $server = Yun_Array::rand($conf);
     $hash = implode('_', $server);
     if (!isset($this->adapter_instance[$hash])) {
         $class_name = $this->adapter_class_name;
         $this->adapter_instance[$hash] = new $class_name();
         if (!$this->adapter_instance[$hash] instanceof Yun_Db_Adapter_Interface) {
             $error_msg = 'Yun_Db_Postgre_Conf\'s adapter must be implements Yun_Db_Postgre_Adapter_Interface.';
             trigger_error($error_msg, E_USER_ERROR);
         }
         $retry_time = $this->retry_time_connect;
         while (true) {
             $retry_time--;
             $re = $this->adapter_instance[$hash]->connect($server);
             if (true === $re) {
                 break;
             }
             if ($retry_time <= 0) {
                 $this->error_code = $this->adapter_instance[$hash]->errorCode();
                 $this->error_info = $this->adapter_instance[$hash]->errorInfo();
                 return false;
             }
         }
         //end while
     }
     //endif
     return $this->adapter_instance[$hash];
 }
コード例 #5
0
ファイル: Yun_Log.php プロジェクト: sometumi/yun-lib
 private function log($level, $msg, $handler_id)
 {
     $handler = Yun_Array::get($this->handler, $handler_id);
     if (!$handler instanceof Yun_Log_Handler_Interface) {
         return $this->error($msg, $error, self::DEFAULT_HANDLER_ID);
     }
     $loginfo = sprintf("%s %s {$level} %s\n", date('Ymd-H:i:s'), self::$request_id, $msg);
     $handler->log($loginfo);
 }