VuFind API Documentation

RateLimiterManager
in package
implements LoggerAwareInterface, TranslatorAwareInterface Uses LoggerAwareTrait, TranslatorAwareTrait

Rate limiter manager.

Tags
category

VuFind

author

Ere Maijala ere.maijala@helsinki.fi

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Main Page

Interfaces, Classes, Traits and Enums

LoggerAwareInterface
TranslatorAwareInterface
Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).

Table of Contents

$clientIp  : string
$clientLogDetails  : string
Client details for logging
$config  : array<string|int, mixed>
$eventDesc  : string
Current event description for logging
$ipUtils  : IpAddressUtils
$rateLimiterFactoryCallback  : Closure
$translator  : TranslatorInterface
Translator
$userId  : int|null
__construct()  : mixed
Constructor
check()  : array<string|int, mixed>
Check if the given event is allowed
getTranslator()  : TranslatorInterface
Get translator object.
getTranslatorLocale()  : string
Get the locale from the translator.
isEnabled()  : bool|string
Check if rate limiter is enabled
setTranslator()  : TranslatorAwareInterface
Set a translator
translate()  : string
Translate a string (or string-castable object)
translateWithPrefix()  : string
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
debug()  : void
Log a debug message.
eventMatchesFilter()  : bool
Check if an event matches a filter
extractTextDomain()  : array<string|int, mixed>
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
getDebugTranslation()  : string
Build a debug-mode translation
getPolicyIdForEvent()  : string|null
Try to find a policy that matches an event
getTooManyRequestsResponseMessage()  : string
Get a response message for too many requests
isCrawlerRequest()  : bool
Check if the request is from a crawler
log()  : void
Send a message to the logger.
logError()  : void
Log an error message.
logWarning()  : void
Log a warning message.
sanitizeTranslationKey()  : string
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
translateString()  : string
Get translation for a string
verboseDebug()  : void
Log a verbose debug message if configured

Properties

$eventDesc

Current event description for logging

protected string $eventDesc = '??'

Methods

__construct()

Constructor

public __construct(array<string|int, mixed> $config, string $clientIp, int|null $userId, Closure $rateLimiterFactoryCallback, IpAddressUtils $ipUtils) : mixed
Parameters
$config : array<string|int, mixed>

Rate limiter configuration

$clientIp : string

Client's IP address

$userId : int|null

User ID or null if not logged in

$rateLimiterFactoryCallback : Closure

Rate limiter factory callback

$ipUtils : IpAddressUtils

IP address utilities

Return values
mixed

check()

Check if the given event is allowed

public check(EventInterface $event) : array<string|int, mixed>
Parameters
$event : EventInterface

Event

Return values
array<string|int, mixed>

Associative array with the following keys: bool allow Whether to allow the request ?int requestsRemaining Remaining requests ?int retryAfter Retry after seconds if limit exceeded ?int requestLimit Current limit ?string message Response message if limit reached

getTranslator()

Get translator object.

public getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getTranslatorLocale()

Get the locale from the translator.

public getTranslatorLocale([string $default = 'en' ]) : string
Parameters
$default : string = 'en'

Default to use if translator absent.

Return values
string

isEnabled()

Check if rate limiter is enabled

public isEnabled() : bool|string
Return values
bool|string

False if disabled, true if enabled and enforcing, 'report_only' if enabled for logging only (not enforcing the limits)

translate()

Translate a string (or string-castable object)

public translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

translateWithPrefix()

Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.

public translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$prefix : string

Translation key prefix

$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

debug()

Log a debug message.

protected debug(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

eventMatchesFilter()

Check if an event matches a filter

protected eventMatchesFilter(MvcEvent $event, array<string|int, mixed> $filter) : bool
Parameters
$event : MvcEvent

Event

$filter : array<string|int, mixed>

Filter from configuration

Return values
bool

extractTextDomain()

Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.

protected extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

Return values
array<string|int, mixed>

getDebugTranslation()

Build a debug-mode translation

protected getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
$domain : string

Text domain

$str : string

String to translate

$tokens : array<string|int, mixed>

Tokens to inject into the translated string

Return values
string

getPolicyIdForEvent()

Try to find a policy that matches an event

protected getPolicyIdForEvent(MvcEvent $event) : string|null
Parameters
$event : MvcEvent

Event

Return values
string|null

policy id or null if no match

getTooManyRequestsResponseMessage()

Get a response message for too many requests

protected getTooManyRequestsResponseMessage(MvcEvent $event, array<string|int, mixed> $result) : string
Parameters
$event : MvcEvent

Request event

$result : array<string|int, mixed>

Rate limiter result

Return values
string

isCrawlerRequest()

Check if the request is from a crawler

protected isCrawlerRequest(MvcEvent $event) : bool
Parameters
$event : MvcEvent

Request event

Return values
bool

log()

Send a message to the logger.

protected log(string $level, string $message[, array<string|int, mixed> $context = [] ][, bool $prependClass = false ]) : void
Parameters
$level : string

Log level

$message : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = false

Prepend class name to message?

Return values
void

logError()

Log an error message.

protected logError(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

logWarning()

Log a warning message.

protected logWarning(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
$msg : string

Log message

$context : array<string|int, mixed> = []

Log context

$prependClass : bool = true

Prepend class name to message?

Return values
void

sanitizeTranslationKey()

Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.

protected sanitizeTranslationKey(string $key) : string
Parameters
$key : string

Key to sanitize

Return values
string

Sanitized key

translateString()

Get translation for a string

protected translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
$rawStr : string

String to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$domain : string = 'default'

Text domain (omit for default)

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

Return values
string

verboseDebug()

Log a verbose debug message if configured

protected verboseDebug(string $msg) : void
Parameters
$msg : string

Message

Return values
void

Search results