laravel-websockets/src/Apps/App.php

54 lines
1.1 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
use BeyondCode\LaravelWebSockets\Exceptions\InvalidClient;
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)) {
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-25 23:29:35 +00:00
}