187 lines
3.6 KiB
PHP
187 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
|
|
|
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp;
|
|
|
|
class App
|
|
{
|
|
/** @var int */
|
|
public $id;
|
|
|
|
/** @var string */
|
|
public $key;
|
|
|
|
/** @var string */
|
|
public $secret;
|
|
|
|
/** @var string|null */
|
|
public $name;
|
|
|
|
/** @var string|null */
|
|
public $host;
|
|
|
|
/** @var string|null */
|
|
public $path;
|
|
|
|
/** @var int|null */
|
|
public $capacity = null;
|
|
|
|
/** @var bool */
|
|
public $clientMessagesEnabled = false;
|
|
|
|
/** @var bool */
|
|
public $statisticsEnabled = true;
|
|
|
|
/** @var array */
|
|
public $allowedOrigins = [];
|
|
|
|
/**
|
|
* Find the app by id.
|
|
*
|
|
* @param mixed $appId
|
|
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
|
|
*/
|
|
public static function findById($appId)
|
|
{
|
|
return app(AppManager::class)->findById($appId);
|
|
}
|
|
|
|
/**
|
|
* Find the app by app key.
|
|
*
|
|
* @param mixed $appId
|
|
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
|
|
*/
|
|
public static function findByKey($appKey): ?self
|
|
{
|
|
return app(AppManager::class)->findByKey($appKey);
|
|
}
|
|
|
|
/**
|
|
* Find the app by app secret.
|
|
*
|
|
* @param mixed $appId
|
|
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
|
|
*/
|
|
public static function findBySecret($appSecret): ?self
|
|
{
|
|
return app(AppManager::class)->findBySecret($appSecret);
|
|
}
|
|
|
|
/**
|
|
* Initialize the Web Socket app instance.
|
|
*
|
|
* @param mixed $appId
|
|
* @param mixed $key
|
|
* @param mixed $secret
|
|
* @return void
|
|
* @throws \BeyondCode\LaravelWebSockets\Exceptions\InvalidApp
|
|
*/
|
|
public function __construct($appId, $appKey, $appSecret)
|
|
{
|
|
if ($appKey === '') {
|
|
throw InvalidApp::valueIsRequired('appKey', $appId);
|
|
}
|
|
|
|
if ($appSecret === '') {
|
|
throw InvalidApp::valueIsRequired('appSecret', $appId);
|
|
}
|
|
|
|
$this->id = $appId;
|
|
$this->key = $appKey;
|
|
$this->secret = $appSecret;
|
|
}
|
|
|
|
/**
|
|
* Set the name of the app.
|
|
*
|
|
* @param string $appName
|
|
* @return $this
|
|
*/
|
|
public function setName(string $appName)
|
|
{
|
|
$this->name = $appName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set the app host.
|
|
*
|
|
* @param string $host
|
|
* @return $this
|
|
*/
|
|
public function setHost(string $host)
|
|
{
|
|
$this->host = $host;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set path for the app.
|
|
*
|
|
* @param string $path
|
|
* @return $this
|
|
*/
|
|
public function setPath(string $path)
|
|
{
|
|
$this->path = $path;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Enable client messages.
|
|
*
|
|
* @param bool $enabled
|
|
* @return $this
|
|
*/
|
|
public function enableClientMessages(bool $enabled = true)
|
|
{
|
|
$this->clientMessagesEnabled = $enabled;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set the maximum capacity for the app.
|
|
*
|
|
* @param int|null $capacity
|
|
* @return $this
|
|
*/
|
|
public function setCapacity(?int $capacity)
|
|
{
|
|
$this->capacity = $capacity;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Enable statistics for the app.
|
|
*
|
|
* @param bool $enabled
|
|
* @return $this
|
|
*/
|
|
public function enableStatistics(bool $enabled = true)
|
|
{
|
|
$this->statisticsEnabled = $enabled;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Add whitelisted origins.
|
|
*
|
|
* @param array $allowedOrigins
|
|
* @return $this
|
|
*/
|
|
public function setAllowedOrigins(array $allowedOrigins)
|
|
{
|
|
$this->allowedOrigins = $allowedOrigins;
|
|
|
|
return $this;
|
|
}
|
|
}
|