class FossabotCommander implements FossabotCommander, LoggerAwareInterface (View source)

Main class to invoke a given \Brandon14\FossabotCommander\Contracts\FossabotCommand instance.

Traits

LoggerAwareTrait
LoggerTrait

Constants

private FOSSABOT_API_VERSION

Fossabot API version.

private FOSSABOT_API_ROUTE

Fossabot API route.

private FOSSABOT_CONTEXT_ROUTE

Fossabot context route.

private FOSSABOT_VALIDATE_ROUTE

Fossabot validate route.

private FOSSABOT_API_BASE_URL

Fossabot API base URL.

Methods

__construct(ClientInterface $httpClient, RequestFactoryInterface $requestFactory, LoggerInterface|null $logger = null, bool $logging = false)

Constructs a new FossabotCommander class.

ClientInterface
getHttpClient()

Get \Psr\Http\Client\ClientInterface instance.

setHttpClient(ClientInterface $httpClient)

Set a new \Psr\Http\Client\ClientInterface instance.

RequestFactoryInterface
getRequestFactory()

Get \Psr\Http\Message\RequestFactoryInterface instance.

setRequestFactory(RequestFactoryInterface $requestFactory)

Set a new \Psr\Http\Message\RequestFactoryInterface instance.

LoggerInterface|null
getLogger()

Get \Psr\Log\LoggerInterface instance.

setLog(LoggerInterface|null $logger)

Fluent setter for setting a new \Psr\Log\LoggerInterface instance.

enableLogging()

Enable logging. Will throw an \Brandon14\FossabotCommander\Contracts\Exceptions\NoValidLoggerProvidedException when enabling this without providing a valid \Psr\Log\LoggerInterface instance.

setLogging(bool $logging)

Sets whether to log or not for the \Brandon14\FossabotCommander\Contracts\FossabotCommander instance.

bool
getLogging()

Gets the configured logging setting.

string
runCommand(FossabotCommand|callable $command, string $customApiToken, bool $getContext = true)

Will execute a given \Brandon14\FossabotCommander\Contracts\FossabotCommand instance. If this method throws a \Brandon14\FossabotCommander\Contracts\Exceptions\CannotValidateRequestException, then it was unable to verify that the request came from Fossabot, and should be treated as a critical error.

void
log($level, $message, array $context = [])

{@inheritDoc}

array
getLoggingContext()

Gets general class information used for providing additional logging context.

Details

__construct(ClientInterface $httpClient, RequestFactoryInterface $requestFactory, LoggerInterface|null $logger = null, bool $logging = false)

Constructs a new FossabotCommander class.

Parameters

ClientInterface $httpClient

PSR HTTP client instance

RequestFactoryInterface $requestFactory

PSR HTTP request factory instance

LoggerInterface|null $logger

PSR logger instance

bool $logging

Whether to enable logging or not

Exceptions

NoValidLoggerProvidedException

ClientInterface getHttpClient()

Get \Psr\Http\Client\ClientInterface instance.

Return Value

ClientInterface

PSR HTTP client instance

FossabotCommander setHttpClient(ClientInterface $httpClient)

Set a new \Psr\Http\Client\ClientInterface instance.

Parameters

ClientInterface $httpClient

PSR HTTP client interface

Return Value

FossabotCommander

RequestFactoryInterface getRequestFactory()

Get \Psr\Http\Message\RequestFactoryInterface instance.

Return Value

RequestFactoryInterface

Request factory instance

FossabotCommander setRequestFactory(RequestFactoryInterface $requestFactory)

Set a new \Psr\Http\Message\RequestFactoryInterface instance.

Parameters

RequestFactoryInterface $requestFactory

PSR request factory instance

Return Value

FossabotCommander

LoggerInterface|null getLogger()

Get \Psr\Log\LoggerInterface instance.

Return Value

LoggerInterface|null

Logger instance

FossabotCommander setLog(LoggerInterface|null $logger)

Fluent setter for setting a new \Psr\Log\LoggerInterface instance.

Parameters

LoggerInterface|null $logger

PSR logger instance

Return Value

FossabotCommander

Exceptions

NoValidLoggerProvidedException

FossabotCommander enableLogging()

Enable logging. Will throw an \Brandon14\FossabotCommander\Contracts\Exceptions\NoValidLoggerProvidedException when enabling this without providing a valid \Psr\Log\LoggerInterface instance.

FossabotCommander disableLogging()

Return Value

FossabotCommander

FossabotCommander setLogging(bool $logging)

Sets whether to log or not for the \Brandon14\FossabotCommander\Contracts\FossabotCommander instance.

If enabling, and no valid PSR logging is provided, it will throw an exception.

Parameters

bool $logging

Whether to enable logging or not

Return Value

FossabotCommander

Exceptions

NoValidLoggerProvidedException

bool getLogging()

Gets the configured logging setting.

Return Value

bool Logging

string runCommand(FossabotCommand|callable $command, string $customApiToken, bool $getContext = true)

Will execute a given \Brandon14\FossabotCommander\Contracts\FossabotCommand instance. If this method throws a \Brandon14\FossabotCommander\Contracts\Exceptions\CannotValidateRequestException, then it was unable to verify that the request came from Fossabot, and should be treated as a critical error.

If this method throws a \Brandon14\FossabotCommander\Contracts\Exceptions\RateLimitException then that means that Fossabot's API is throttling your requests, and you should check the rate limit parameters available in the exception to determine how to handle it.

To get the $customApiToken, you can obtain it from the Fossabot request header 'x-fossabot-customapitoken'.

Parameters

FossabotCommand|callable $command

Fossabot command instance

string $customApiToken

Fossabot API token to validate and get data from

bool $getContext

Whether to fetch additional context from Fossabot API command

Return Value

string

Text response to return to Fossabot

Exceptions

RateLimitException
CannotGetContextException
CannotCreateContextException
CannotValidateRequestException

void log($level, $message, array $context = [])

{@inheritDoc}

Parameters

$level
$message
array $context

Return Value

void

array getLoggingContext()

Gets general class information used for providing additional logging context.

Return Value

array