Slackwolf\Game\Formatter\PlayerListFormatter::format PHP Method

format() public static method

public static format ( array $players, $withRoles = false ) : string
$players array
return string
    public static function format(array $players, $withRoles = false)
    {
        $playerList = [];
        foreach ($players as $player) {
            $str = '@' . $player->getUsername();
            if ($withRoles) {
                $str .= ' (' . $player->role->getName() . ')';
            }
            $playerList[] = $str;
        }
        return implode(', ', $playerList);
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function fire()
 {
     $this->game->removeLobbyPlayer($this->userId);
     $playersList = PlayerListFormatter::format($this->game->getLobbyPlayers());
     if ($playersList) {
         $this->gameManager->sendMessageToChannel($this->game, "Current lobby: " . $playersList);
     } else {
         $this->gameManager->sendMessageToChannel($this->game, "Lobby is now empty");
     }
 }
All Usage Examples Of Slackwolf\Game\Formatter\PlayerListFormatter::format
PlayerListFormatter