laravel-websockets/src/ClientProviders/Client.php

58 lines
1.1 KiB
PHP
Raw Normal View History

2018-11-24 00:25:40 +00:00
<?php
namespace BeyondCode\LaravelWebSockets\ClientProviders;
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
class Client
{
/** @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-11-24 00:53:20 +00:00
public static function findByAppId(int $appId)
2018-11-24 00:25:40 +00:00
{
2018-11-24 00:53:20 +00:00
return app(ClientProvider::class)->findByAppId($appId);
}
public static function findByAppKey(string $appKey): ?Client
{
return app(ClientProvider::class)->findByAppKey($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)) {
throw InvalidClient::appIdIsNotNumeric($appId);
}
if ($appKey === '') {
throw InvalidClient::valueIsRequired('appKey', $appId);
}
if ($appSecret === '') {
throw InvalidClient::valueIsRequired('appSecret', $appId);
}
$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-24 00:53:20 +00:00
2018-11-24 00:25:40 +00:00
}