Last active
December 29, 2015 07:39
-
-
Save guweigang/7637720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Message.php --- | |
* | |
* Filename: Message.php | |
* Description: | |
* Author: Gu Weigang * Maintainer: | |
* Created: Sun Nov 10 15:22:06 2013 (+0800) | |
* Version: 117442 | |
* Last-Updated: Wed Nov 13 20:47:38 2013 (+0800) | |
* By: Gu Weigang | |
* Update #: 47 | |
* | |
*/ | |
/* Change Log: | |
* | |
* | |
*/ | |
/* This program is part of "Baidu Darwin PHP Software"; you can redistribute it and/or | |
* modify it under the terms of the Baidu General Private License as | |
* published by Baidu Campus. | |
* | |
* You should have received a copy of the Baidu General Private License | |
* along with this program; see the file COPYING. If not, write to | |
* the Baidu Campus NO.10 Shangdi 10th Street Haidian District, Beijing The People's | |
* Republic of China, 100085. | |
*/ | |
/* Code: */ | |
class Message | |
{ | |
protected $data = array( | |
'nestId' => 0, | |
'pipe' => '', | |
'eventId' => 0, | |
'userId' => 0, | |
'level' => 0, | |
'objectId' => 0, | |
'db' => "", | |
"table" => "", | |
'time' => "0000-00-00 00:00:00", | |
'data' => null, | |
); | |
public function __construct($database, $table) | |
{ | |
$this->data['db'] = $database; | |
$this->data['table'] = $table; | |
$this->data['time'] = date("Y-m-d H:i:s"); | |
$this->data['data'] = new \stdClass(); | |
} | |
public function __set($key, $val) | |
{ | |
if(!isset($this->data[$key])) { | |
throw new \Exception("__set: unknown key in message, " . $key . ":".$val); | |
} | |
$this->data[$key] = $val; | |
} | |
public function __get($key) | |
{ | |
if(!isset($this->data[$key])) { | |
getDI()->get('logger')->error("__get: unknown key in message", $key); | |
throw new \Exception("__get: unknown key in message, " . $key); | |
} | |
return $this->data[$key]; | |
} | |
public function __clone() | |
{ | |
$this->data['data'] = new \stdClass(); | |
} | |
public function toArray() | |
{ | |
$content = $this->data; | |
$content['data'] = (array) $content['data']; | |
return $content; | |
} | |
public function toJson() | |
{ | |
return json_encode($this->data); | |
} | |
public function toLine($pipeInfo="") | |
{ | |
$content = $this->data; | |
$content['pipe'] = $pipeInfo; | |
$content['data'] = json_encode($content['data']); | |
return join("\t", $content); | |
} | |
} | |
/* Message.php ends here */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment