<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
californiamountainsnake / longmantelegrambot-laravel-api-auth-system example snippets
class BaseCommand extends Command {
use AuthBotAccessUtils;
use AuthApiUtils;
use AuthUserUtils;
/**
* Get user's entity. Just specify return type hint.
* @return UserEntity|null
*/
protected function getUserEntity(): ?AuthUserEntity
{
return $this->userUtilsGetUserEntity();
}
/**
* Get user's role. Just specify return type hint.
* @return UserRoleEnum
*/
protected function getUserRole(): AuthUserRoleEnum
{
return $this->userUtilsGetUserRole();
}
/**
* Get user's account type. Just specify return type hint.
* @return UserAccountTypeEnum
*/
protected function getUserAccountType(): AuthUserAccountTypeEnum
{
return $this->userUtilsGetUserAccountType();
}
}
class BaseCommand extends Command {
use AuthBotAccessUtils;
use AuthApiUtils;
use AuthUserUtils;
public function preExecute(): ServerResponse
{
$this->initTelegramParams();
$this->reInitUserParams();
try {
// If user try to execute a wrong command, the exception will throw.
$this->assertUserHasAccessToMainRoute($this->getUserEntity());
return parent::preExecute();
} catch (ApiProxyException $e) {
// handle the error!
} catch (UserRoleNotEqualsException $e) {
// handle the error!
} catch (UserAccountTypeNotEqualsException $e) {
// handle the error!
} catch (\Throwable $t) {
// A good idea is to handle other exceptions.
}
}
}
class MyCommand extends BaseCommand {
public function execute (): ServerResponse {
$json = $this->callApiNotAuth($this->getMainRoute(), [
'email' => '[email protected]',
])->getContent();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.