ContentCreationLimitTrait
Limits content creation by a logged-in user in an Api manager.
One implementation for responses (Bazaar, Comcat), discussion posts and reports, advert reports and
contact messages. Called from beforeSave(), so it applies to the front end (ApiBridge) and to an
external save with a JWT.
The class must implement ContentCreationLimitedInterface; the limiter is injected by a DI decorator. Without it (unit tests building the manager by hand) the guard limits nothing, the same fail-open behavior as an outage of the limit storage.
Table of Contents
Properties
Methods
- setContentCreationLimiter() : void
- guardAnonymousInsert() : Result|null
- Returns `RATE_LIMIT_EXCEEDED` when a guest visitor exceeded the quota of anonymous records of the kind `$scope` (per IP and per normalized `$email`), otherwise `null`. Only an insert by a guest (`$userId` null); a logged-in user is counted by {@see guardContentCreation()}.
- guardContentCreation() : Result|null
- Returns `RATE_LIMIT_EXCEEDED` when the quota is exceeded, otherwise `null`. Only an insert by a logged-in user is counted (see {@see ContentCreationLimiter::isAllowed()}).
- isActivationMailAllowed() : bool
- Tells whether another activation e-mail may be sent to `$email`. Unlike {@see guardContentCreation()} it applies to guests too (it protects the recipient); see {@see ContentCreationLimiter::isActivationMailAllowed()}.
Properties
$contentCreationLimiter
private
ContentCreationLimiter|null
$contentCreationLimiter
= null
Methods
setContentCreationLimiter()
public
setContentCreationLimiter(ContentCreationLimiter $contentCreationLimiter) : void
Parameters
- $contentCreationLimiter : ContentCreationLimiter
guardAnonymousInsert()
Returns `RATE_LIMIT_EXCEEDED` when a guest visitor exceeded the quota of anonymous records of the kind `$scope` (per IP and per normalized `$email`), otherwise `null`. Only an insert by a guest (`$userId` null); a logged-in user is counted by {@see guardContentCreation()}.
private
guardAnonymousInsert(bool $isInsert, string $scope, int|null $userId, string $email) : Result|null
Parameters
- $isInsert : bool
- $scope : string
- $userId : int|null
- $email : string
Return values
Result|nullguardContentCreation()
Returns `RATE_LIMIT_EXCEEDED` when the quota is exceeded, otherwise `null`. Only an insert by a logged-in user is counted (see {@see ContentCreationLimiter::isAllowed()}).
private
guardContentCreation(bool $isInsert, string $scope, int|null $userId) : Result|null
Parameters
- $isInsert : bool
- $scope : string
- $userId : int|null
Return values
Result|nullisActivationMailAllowed()
Tells whether another activation e-mail may be sent to `$email`. Unlike {@see guardContentCreation()} it applies to guests too (it protects the recipient); see {@see ContentCreationLimiter::isActivationMailAllowed()}.
private
isActivationMailAllowed(string $scope, string $email) : bool
Parameters
- $scope : string
- $email : string