Skip to main content

Gate registry

Gates run before a sensitive operation — typically file serve, but also download view and other guarded actions. Each gate inspects a GateContext and returns a GateResult: pass, soft-fail (with reason), or hard-fail.

The registry holds an ordered chain. GateChain evaluates gates in registration order and short-circuits on the first hard-fail.

KeyValue
Container keymc_dm.gate_registry
Eventmc_dm_gate_handlers

Built-in gates

Registered in registration order; the chain short-circuits on the first hard-fail.

IDClassWhat it checks
permissionMC\DownloadsManager\Gate\PermissionGatePer-category permissions (viewFiles, download, etc.) via XF\Permission\TreeContentPermissions.
criteriaMC\DownloadsManager\Gate\CriteriaGatePer-category criteria gates configured in the AdminCP (user/group/visitor matching).
passwordMC\DownloadsManager\Gate\PasswordGatePer-download password, with a configurable pass-window before re-prompting.
hotlinkMC\DownloadsManager\Gate\HotlinkGateReferrer check to block off-site hotlinking of file URLs.
captchaMC\DownloadsManager\Gate\CaptchaGateCAPTCHA challenge for unauthenticated or low-trust visitors.
rate_limitMC\DownloadsManager\Gate\RateLimitGatePer-visitor request-rate cap on serve operations.
bandwidthMC\DownloadsManager\Gate\BandwidthGateResolves the visitor's effective bandwidth cap and switches the serve view to a throttled stream. Never fails.

NSFW filtering ships as a separate add-on (see extensions/nsfw-gate) that registers its own gate via this registry.

Interface

namespace MC\DownloadsManager\Gate;

interface Gate
{
public function evaluate(GateContext $context): GateResult;
}

GateContext carries the visitor, the Download, the DownloadVersion, the DownloadFile (when applicable), and the operation (view, serve, etc.). GateResult is one of pass(), softFail($reason), or hardFail($reason).

Wiring an adapter

public static function gateHandlers(GateRegistry $registry)
{
$registry->register('your_gate', new YourAddon\Gate\YourGate());
}

Subscribe to mc_dm_gate_handlers in code_event_listeners.xml.

Lifecycle events fired

  • mc_dm_gate_passed fires after a gate returns pass().
  • mc_dm_gate_failed fires after a gate returns softFail or hardFail. The event includes the GateResult for inspection.

See Gate events.