2018-08-16 22:30:59 +00:00
|
|
|
<?php
|
2022-03-04 17:10:24 +00:00
|
|
|
|
2018-08-16 22:30:59 +00:00
|
|
|
/*
|
2022-03-04 17:10:24 +00:00
|
|
|
* Copyright (c) 2010-2022 Tim Düsterhus.
|
2018-08-16 22:30:59 +00:00
|
|
|
*
|
|
|
|
* Use of this software is governed by the Business Source License
|
|
|
|
* included in the LICENSE file.
|
|
|
|
*
|
2022-03-04 17:10:24 +00:00
|
|
|
* Change Date: 2026-03-04
|
2018-08-16 22:30:59 +00:00
|
|
|
*
|
|
|
|
* On the date above, in accordance with the Business Source
|
|
|
|
* License, use of this software will be governed by version 2
|
|
|
|
* or later of the General Public License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace chat\data\room;
|
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
use chat\system\cache\builder\RoomCacheBuilder;
|
|
|
|
use wcf\system\SingletonFactory;
|
2018-08-16 22:30:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages the room cache.
|
|
|
|
*/
|
2022-03-04 17:10:24 +00:00
|
|
|
class RoomCache extends SingletonFactory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of cached rooms.
|
|
|
|
*
|
|
|
|
* @var Room[]
|
|
|
|
*/
|
|
|
|
protected $rooms = [ ];
|
2018-08-16 22:30:59 +00:00
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
/**
|
|
|
|
* Cached user counts for the rooms.
|
|
|
|
*
|
|
|
|
* @var int[]
|
|
|
|
*/
|
|
|
|
protected $userCount = [ ];
|
2018-08-16 22:30:59 +00:00
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
protected function init()
|
|
|
|
{
|
|
|
|
$this->rooms = RoomCacheBuilder::getInstance()->getData();
|
|
|
|
}
|
2018-08-16 22:30:59 +00:00
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
/**
|
|
|
|
* Returns a specific room.
|
|
|
|
*/
|
2022-03-04 18:12:37 +00:00
|
|
|
public function getRoom(int $roomID): ?Room
|
2022-03-04 17:10:24 +00:00
|
|
|
{
|
|
|
|
if (isset($this->rooms[$roomID])) {
|
|
|
|
return $this->rooms[$roomID];
|
|
|
|
}
|
2018-08-16 22:30:59 +00:00
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
2018-08-16 22:30:59 +00:00
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
/**
|
|
|
|
* Returns all rooms.
|
|
|
|
*
|
|
|
|
* @return Room[]
|
|
|
|
*/
|
|
|
|
public function getRooms()
|
|
|
|
{
|
|
|
|
return $this->rooms;
|
|
|
|
}
|
2018-08-16 22:30:59 +00:00
|
|
|
}
|