コード例 #1
0
ファイル: Controller.php プロジェクト: phxlol/lol-php-api
 /**
  * @param null|callable $callback This callback will format the results array
  */
 protected function sendResponse(\Closure $callback = null)
 {
     $this->apiManager->getLoop()->addPeriodicTimer(0.0001, function (TimerInterface $timer) use($callback) {
         if ($this->hasError) {
             $timer->cancel();
             return;
         }
         if (0 < $this->invokeCount && $this->invokeCount == $this->responseCount) {
             // Convert indexed array to associative if count = 1
             if (isset($this->results[0]) && !isset($this->results[1])) {
                 $this->results = $this->results[0];
             }
             $this->conn->emit('api-response', [['success' => true, 'result' => null != $callback ? $callback($this->results) : $this->results]]);
             $timer->cancel();
         }
     });
 }