示例#1
0
 public function testSetDatadirBasePath()
 {
     $storage = new YamlStorage();
     $this->assertEquals(null, $storage->getDatadirBasePath());
     $storage->setDatadirBasePath('test_data');
     $this->assertEquals('test_data', $storage->getDatadirBasePath());
 }
示例#2
0
文件: Node.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     #fwrite(STDOUT, 'load node'."\n");
     if (parent::load()) {
         $this->setIdHexStr($this->data['id']);
         if ($this->data) {
             if (array_key_exists('sslKeyPub', $this->data)) {
                 if ($this->data['sslKeyPub']) {
                     $this->setSslKeyPub(base64_decode($this->data['sslKeyPub']));
                 }
                 unset($this->data['sslKeyPub']);
             }
             if (array_key_exists('uri', $this->data)) {
                 #fwrite(STDOUT, 'load node: uri /'.$this->data['uri'].'/'."\n");
                 if ($this->data['uri']) {
                     $this->setUri($this->data['uri']);
                 }
                 unset($this->data['uri']);
             }
         }
         return true;
     }
     return false;
 }
示例#3
0
 public function __construct($filePath = null)
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     parent::__construct($filePath);
     $this->data['timeCreated'] = time();
     $this->data['nodesId'] = 0;
     $this->data['nodes'] = array();
 }
示例#4
0
文件: Msg.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     if (parent::load()) {
         $this->setSrcSslKeyPub(base64_decode($this->data['srcSslKeyPub']));
         unset($this->data['srcSslKeyPub']);
         return true;
     }
     return false;
 }
示例#5
0
文件: MsgDb.php 项目: thefox/imapd
 public function load()
 {
     if (parent::load()) {
         if (array_key_exists('msgs', $this->data) && $this->data['msgs']) {
             foreach ($this->data['msgs'] as $msgId => $msgAr) {
                 $this->msgsByPath[$msgAr['path']] = $msgAr;
             }
         }
         return true;
     }
     return false;
 }
示例#6
0
文件: Table.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     if (parent::load()) {
         if ($this->data) {
             /*if(array_key_exists('buckets', $this->data) && $this->data['buckets']){
             			foreach($this->data['buckets'] as $bucketId => $bucketAr){
             				if(file_exists($bucketAr['path'])){
             					$bucket = new Bucket($bucketAr['path']);
             					$bucket->setDatadirBasePath($this->getDatadirBasePath());
             					$bucket->setLocalNode($this->getLocalNode());
             					
             					if($bucket->load()){
             						$this->buckets[$bucketId] = $bucket;
             						$this->bucketsByMask[$bucket->getMask()] = $bucket;
             					}
             				}
             			}
             		}*/
             /*if(array_key_exists('childBucketUpper', $this->data) && $this->data['childBucketUpper']){
             			$this->childBucketUpper = new Bucket($this->data['childBucketUpper']);
             			$this->childBucketUpper->setDatadirBasePath($this->getDatadirBasePath());
             			$this->childBucketUpper->setLocalNode($this->getLocalNode());
             			$this->childBucketUpper->load();
             		}
             		if(array_key_exists('childBucketLower', $this->data) && $this->data['childBucketLower']){
             			$this->childBucketLower = new Bucket($this->data['childBucketLower']);
             			$this->childBucketLower->setDatadirBasePath($this->getDatadirBasePath());
             			$this->childBucketLower->setLocalNode($this->getLocalNode());
             			$this->childBucketLower->load();
             		}*/
             if (array_key_exists('rootBucket', $this->data) && $this->data['rootBucket']) {
                 $this->rootBucket = new Bucket($this->data['rootBucket']);
                 $this->rootBucket->setDatadirBasePath($this->getDatadirBasePath());
                 $this->rootBucket->setLocalNode($this->getLocalNode());
                 $this->rootBucket->load();
             }
         }
         #unset($this->data['buckets']);
         #unset($this->data['childBucketUpper']);
         #unset($this->data['childBucketLower']);
         unset($this->data['rootBucket']);
         #$this->data['bucketsId'] = (int)$this->data['bucketsId'];
         return true;
     }
     return false;
 }
示例#7
0
 public function load()
 {
     #fwrite(STDOUT, __CLASS__.'->'.__FUNCTION__.''."\n");
     if (parent::load()) {
         if (isset($this->data['hashcashs']) && $this->data['hashcashs']) {
             foreach ($this->data['hashcashs'] as $hashcashId => $hashcashAr) {
                 $this->hashcashsId = $hashcashId;
                 #fwrite(STDOUT, __CLASS__.'->'.__FUNCTION__.': '.$this->hashcashsId."\n");
                 $hashcash = new Hashcash();
                 if ($hashcash->verify($hashcashAr['stamp'])) {
                     $this->hashcashs[$hashcashId] = $hashcash;
                 }
             }
         }
         unset($this->data['hashcashs']);
         return true;
     }
     return false;
 }
示例#8
0
文件: MsgDb.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     if (parent::load()) {
         if (array_key_exists('msgs', $this->data) && $this->data['msgs']) {
             foreach ($this->data['msgs'] as $msgId => $msgAr) {
                 if (file_exists($msgAr['path'])) {
                     $msg = new Msg($msgAr['path']);
                     $msg->setDatadirBasePath($this->getDatadirBasePath());
                     if ($msg->load()) {
                         #print __CLASS__.'->'.__FUNCTION__.': '.$msg->getId().', '.$msg->getStatus()."\n";
                         $this->msgs[$msg->getId()] = $msg;
                     }
                 }
             }
         }
         unset($this->data['msgs']);
         return true;
     }
     return false;
 }
示例#9
0
 public function __construct($filePath = null)
 {
     parent::__construct($filePath);
     $this->data['version'] = PhpChat::VERSION;
     $this->data['release'] = PhpChat::RELEASE;
     $this->data['datadir'] = 'data';
     $this->data['firstRun'] = true;
     $this->data['timeCreated'] = time();
     $this->data['node'] = array();
     $this->data['node']['uriLocal'] = 'tcp://0.0.0.0:25000';
     $this->data['node']['uriPub'] = '';
     $this->data['node']['id'] = '';
     $this->data['node']['sslKeyPrvPass'] = '';
     $this->data['node']['sslKeyPrvPath'] = 'id_rsa.prv';
     $this->data['node']['sslKeyPubPath'] = 'id_rsa.pub';
     $this->data['node']['traffic'] = array();
     $this->data['node']['traffic']['in'] = '0';
     $this->data['node']['traffic']['out'] = '0';
     $this->data['node']['bridge'] = array();
     $this->data['node']['bridge']['server'] = array();
     $this->data['node']['bridge']['server']['enabled'] = false;
     $this->data['node']['bridge']['client'] = array();
     $this->data['node']['bridge']['client']['enabled'] = false;
     $this->data['user'] = array();
     $this->data['user']['nickname'] = '';
     $this->data['console'] = array();
     $this->data['console']['history'] = array();
     $this->data['console']['history']['enabled'] = true;
     $this->data['console']['history']['entriesMax'] = 1000;
     $this->data['console']['history']['saveToFile'] = true;
     $this->load();
     if ($this->isLoaded()) {
         $this->data['version'] = PhpChat::VERSION;
         $this->data['release'] = PhpChat::RELEASE;
     } else {
         $this->data['user']['nickname'] = 'user_' . substr(md5(time()), 0, 4);
         $this->setDataChanged(true);
         $this->save();
     }
 }
示例#10
0
文件: Bucket.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     #fwrite(STDOUT, __FUNCTION__.': '.$this->getFilePath().''."\n");
     if (parent::load()) {
         if ($this->data) {
             if (array_key_exists('nodes', $this->data) && $this->data['nodes']) {
                 foreach ($this->data['nodes'] as $nodeId => $nodeAr) {
                     if (file_exists($nodeAr['path'])) {
                         #$this->nodesId = $nodeId;
                         $node = new Node($nodeAr['path']);
                         $node->setDatadirBasePath($this->getDatadirBasePath());
                         $node->setBucket($this);
                         if ($node->load()) {
                             #$this->nodes[$this->nodesId] = $node;
                             $this->nodes[$nodeId] = $node;
                         }
                     }
                 }
             }
             if (array_key_exists('childBucketUpper', $this->data) && $this->data['childBucketUpper']) {
                 $this->childBucketUpper = new Bucket($this->data['childBucketUpper']);
                 $this->childBucketUpper->setDatadirBasePath($this->getDatadirBasePath());
                 $this->childBucketUpper->setLocalNode($this->getLocalNode());
                 $this->childBucketUpper->load();
             }
             if (array_key_exists('childBucketLower', $this->data) && $this->data['childBucketLower']) {
                 $this->childBucketLower = new Bucket($this->data['childBucketLower']);
                 $this->childBucketLower->setDatadirBasePath($this->getDatadirBasePath());
                 $this->childBucketLower->setLocalNode($this->getLocalNode());
                 $this->childBucketLower->load();
             }
         }
         unset($this->data['nodes']);
         unset($this->data['childBucketUpper']);
         unset($this->data['childBucketLower']);
         return true;
     }
     return false;
 }
示例#11
0
文件: Table.php 项目: thefox/phpchat
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     if (parent::load()) {
         if ($this->data) {
             if (array_key_exists('nodes', $this->data) && $this->data['nodes']) {
                 foreach ($this->data['nodes'] as $nodeId => $nodeAr) {
                     if (file_exists($nodeAr['path'])) {
                         $node = new Node($nodeAr['path']);
                         $node->setDatadirBasePath($this->getDatadirBasePath());
                         if ($node->load()) {
                             $this->nodes[$nodeId] = $node;
                         }
                     }
                 }
             }
         }
         unset($this->data['nodes']);
         return true;
     }
     return false;
 }
示例#12
0
 public function load()
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     if (parent::load()) {
         if (isset($this->data['contacts']) && $this->data['contacts']) {
             foreach ($this->data['contacts'] as $contactId => $contactAr) {
                 #$this->contactsId++;
                 $this->contactsId = (int) $contactId;
                 #print __CLASS__.'->'.__FUNCTION__.': '.$this->contactsId."\n";
                 $contact = new Contact();
                 $contact->setId($this->contactsId);
                 $contact->setNodeId($contactAr['nodeId']);
                 $contact->setUserNickname($contactAr['userNickname']);
                 $contact->setTimeCreated($contactAr['timeCreated']);
                 $this->contacts[$contact->getId()] = $contact;
                 $this->contactsByNodeId[$contact->getNodeId()] = $contact;
             }
         }
         unset($this->data['contacts']);
         return true;
     }
     return false;
 }
示例#13
0
 public function shutdown()
 {
     #print __CLASS__.'->'.__FUNCTION__.': '.(int)$this->ipcKernelShutdown."\n";
     if (!TEST) {
         fwrite(STDOUT, PHP_EOL);
     }
     $this->getLog()->info('shutdown');
     #$this->msgAdd('Shutting down...', true, true);
     if ($this->getModeChannel()) {
         $this->talkCloseSend();
     }
     #if(!$this->ipcKernelShutdown){ $this->ipcKernelConnection->execSync('shutdown'); }
     if ($this->settings->data['console']['history']['enabled'] && $this->settings->data['console']['history']['saveToFile']) {
         $historyStoragePath = $this->settings->data['datadir'] . '/history.yml';
         $historyStorage = new YamlStorage($historyStoragePath);
         if ($this->settings->data['console']['history']['entriesMax']) {
             $historyStorage->data = array_slice($this->history, 0, $this->settings->data['console']['history']['entriesMax']);
         } else {
             $historyStorage->data = $this->history;
         }
         $historyStorage->setDataChanged(true);
         $historyStorage->save();
     }
     if (!TEST) {
         $this->sttyReset();
     }
 }