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 */
|
|
|
|
|
public $appId;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
public $appKey;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
public $appSecret;
|
|
|
|
|
|
2018-11-24 22:52:55 +00:00
|
|
|
/** @var string|null */
|
|
|
|
|
public $name;
|
|
|
|
|
|
2018-12-01 12:57:02 +00:00
|
|
|
public static function findById(int $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-01 12:57:02 +00:00
|
|
|
public static function findByKey(string $appKey): ?App
|
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-11-24 22:52:55 +00:00
|
|
|
public function __construct($appId, string $appKey, string $appSecret, ?string $name)
|
2018-11-24 00:25:40 +00:00
|
|
|
{
|
|
|
|
|
if (!is_numeric($appId)) {
|
2018-12-01 12:58:25 +00:00
|
|
|
throw InvalidApp::appIdIsNotNumeric($appId);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->appId = $appId;
|
|
|
|
|
|
|
|
|
|
$this->appKey = $appKey;
|
|
|
|
|
|
|
|
|
|
$this->appSecret = $appSecret;
|
2018-11-24 22:52:55 +00:00
|
|
|
|
|
|
|
|
$this->name = $name;
|
2018-11-24 00:25:40 +00:00
|
|
|
}
|
2018-11-25 23:29:35 +00:00
|
|
|
}
|