laravel-websockets/src/Apps/App.php

90 lines
1.7 KiB
PHP
Raw Normal View History

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 */
public $server;
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
{
2018-12-01 12:57:02 +00:00
return app(AppProvider::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
{
2018-12-01 12:57:02 +00:00
return app(AppProvider::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
{
2018-12-04 09:25:34 +00:00
return app(AppProvider::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 11:36:02 +00:00
public function setServer(string $server)
{
$this->server = $server;
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
public function enableStatistics(bool $enabled = true)
{
$this->statisticsEnabled = $enabled;
return $this;
}
2018-11-25 23:29:35 +00:00
}