2018-11-24 00:25:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-12-01 12:57:02 +00:00
|
|
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-12-01 12:58:25 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-12-01 12:57:02 +00:00
|
|
|
class App
|
2018-11-24 00:25:40 +00:00
|
|
|
{
|
|
|
|
|
/** @var int */
|
2018-12-01 13:12:15 +00:00
|
|
|
public $id;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2018-12-01 13:12:15 +00:00
|
|
|
public $key;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
|
|
|
|
/** @var string */
|
2018-12-01 13:12:15 +00:00
|
|
|
public $secret;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-11-24 22:52:55 +00:00
|
|
|
/** @var string|null */
|
|
|
|
|
public $name;
|
|
|
|
|
|
2018-12-05 11:36:02 +00:00
|
|
|
/** @var string|null */
|
2018-12-05 12:58:30 +00:00
|
|
|
public $host;
|
2018-12-05 11:36:02 +00:00
|
|
|
|
2020-01-24 11:24:01 +00:00
|
|
|
/** @var string|null */
|
|
|
|
|
public $path;
|
|
|
|
|
|
2019-05-11 06:48:33 +00:00
|
|
|
/** @var int|null */
|
|
|
|
|
public $capacity = null;
|
|
|
|
|
|
2018-12-01 14:47:55 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
public $clientMessagesEnabled = false;
|
|
|
|
|
|
2018-12-03 10:58:42 +00:00
|
|
|
/** @var bool */
|
|
|
|
|
public $statisticsEnabled = true;
|
|
|
|
|
|
2018-12-03 09:06:40 +00:00
|
|
|
public static function findById($appId)
|
2018-11-24 00:25:40 +00:00
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
return app(AppManager::class)->findById($appId);
|
2018-11-24 00:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-04 21:22:33 +00:00
|
|
|
public static function findByKey(string $appKey): ?self
|
2018-11-24 00:53:20 +00:00
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
return app(AppManager::class)->findByKey($appKey);
|
2018-11-24 00:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-04 21:22:33 +00:00
|
|
|
public static function findBySecret(string $appSecret): ?self
|
2018-12-04 09:15:37 +00:00
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
return app(AppManager::class)->findBySecret($appSecret);
|
2018-12-04 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-01 14:47:55 +00:00
|
|
|
public function __construct($appId, string $appKey, string $appSecret)
|
2018-11-24 00:25:40 +00:00
|
|
|
{
|
|
|
|
|
if ($appKey === '') {
|
2018-12-01 12:58:25 +00:00
|
|
|
throw InvalidApp::valueIsRequired('appKey', $appId);
|
2018-11-24 00:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($appSecret === '') {
|
2018-12-01 12:58:25 +00:00
|
|
|
throw InvalidApp::valueIsRequired('appSecret', $appId);
|
2018-11-24 00:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-01 13:12:15 +00:00
|
|
|
$this->id = $appId;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-12-01 13:12:15 +00:00
|
|
|
$this->key = $appKey;
|
2018-11-24 00:25:40 +00:00
|
|
|
|
2018-12-01 13:12:15 +00:00
|
|
|
$this->secret = $appSecret;
|
2018-12-01 14:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setName(string $appName)
|
|
|
|
|
{
|
|
|
|
|
$this->name = $appName;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-05 12:58:30 +00:00
|
|
|
public function setHost(string $host)
|
2018-12-05 11:36:02 +00:00
|
|
|
{
|
2018-12-05 12:58:30 +00:00
|
|
|
$this->host = $host;
|
2018-12-05 11:36:02 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 11:24:01 +00:00
|
|
|
public function setPath(string $path)
|
|
|
|
|
{
|
|
|
|
|
$this->path = $path;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-01 14:47:55 +00:00
|
|
|
public function enableClientMessages(bool $enabled = true)
|
|
|
|
|
{
|
|
|
|
|
$this->clientMessagesEnabled = $enabled;
|
2018-11-24 22:52:55 +00:00
|
|
|
|
2018-12-01 14:47:55 +00:00
|
|
|
return $this;
|
2018-11-24 00:25:40 +00:00
|
|
|
}
|
2018-12-03 10:58:42 +00:00
|
|
|
|
2019-05-11 06:48:33 +00:00
|
|
|
public function setCapacity(?int $capacity)
|
|
|
|
|
{
|
|
|
|
|
$this->capacity = $capacity;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-03 10:58:42 +00:00
|
|
|
public function enableStatistics(bool $enabled = true)
|
|
|
|
|
{
|
|
|
|
|
$this->statisticsEnabled = $enabled;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2018-11-25 23:29:35 +00:00
|
|
|
}
|