当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::fromGitterObject方法代码示例

本文整理汇总了PHP中app\Message::fromGitterObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::fromGitterObject方法的具体用法?PHP Message::fromGitterObject怎么用?PHP Message::fromGitterObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Message的用法示例。


在下文中一共展示了Message::fromGitterObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Execute the console command.
  *
  * @param Repository $config
  * @param Container $container
  *
  * @return mixed
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \LogicException
  * @throws \Exception
  */
 public function handle(Repository $config, Container $container)
 {
     $this->syncUsers($config, $container);
     $config->set('gitter.output', false);
     $client = Client::make($config->get('gitter.token'), $this->argument('room'));
     $room = $container->make(Room::class);
     $this->karma = new Validator();
     $request = $this->cursor($client, $room);
     $count = 1;
     // Start number
     $page = 0;
     // Current page
     $chunk = 100;
     // Per page
     while (true) {
         $messageChunk = $request($chunk, $chunk * $page++);
         if (!count($messageChunk)) {
             $this->output->write(sprintf("\r Well done. <comment>%s</comment> Messages was be loaded.", $count));
             break;
         }
         foreach ($messageChunk as $m) {
             echo "\rLoad message: {$count} ";
             $count++;
         }
         $name = 'sync/' . $page . '.json';
         echo '...dump to ' . $name;
         file_put_contents(storage_path($name), json_encode($messageChunk));
     }
     echo "\n";
     $this->output->write('Flush database karma increments');
     Karma::query()->where('room_id', $room->id)->delete();
     $this->output->write('Start message parsing.');
     $finder = (new Finder())->files()->in(storage_path('sync'))->name('*.json')->sort(function ($a, $b) {
         $parse = function (\SplFileInfo $file) {
             return str_replace('.json', '', $file->getFilename());
         };
         return $parse($b) <=> $parse($a);
     });
     $count = 1;
     foreach ($finder as $file) {
         $messages = json_decode($file->getContents(), true);
         foreach ($messages as $message) {
             $message = Message::fromGitterObject($message);
             echo "\r" . $count++ . ' messages parsing: ' . $message->created_at;
             usleep(100);
             $this->onMessage($message);
         }
         unlink($file->getRealPath());
     }
 }
开发者ID:Dualse,项目名称:GitterBot,代码行数:62,代码来源:GitterSync.php

示例2: listen

 /**
  * @throws InvalidArgumentException
  * @return Client
  */
 public function listen()
 {
     $client = $this->client->stream('messages', ['roomId' => $this->id])->on(Stream::EVENT_MESSAGE, function ($stream, $data) {
         $this->onMessage(Message::fromGitterObject($data));
     })->on(Stream::EVENT_END, [$this, 'onClose'])->on(Stream::EVENT_ERROR, [$this, 'onError']);
     return $client;
 }
开发者ID:Dualse,项目名称:GitterBot,代码行数:11,代码来源:Room.php


注:本文中的app\Message::fromGitterObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。