<?php
require_once 'User.php';
class Chatroom
{
private $_users = array();
public function login(User $user)
{
$user->setChatroom($this);
if (!array_key_exists($user->getName(), $this->_users)) {
$this->_users[$user->getName()] = $user;
echo '<em>' . $user->getName() . '</em>さんが入室しました。<hr />';
}
}
public function sendMessage($from, $to, $message)
{
if (array_key_exists($to, $this->_users)) {
$this->_users[$to]->receiveMessage($from, $message);
} else {
echo '<em>' . $to . '</em>さんは入室していないようです。<hr />';
}
}
}