trait DoTrustedCallbackTrait (View source)

Ensures that TrustedCallbackInterface can be enforced for callback methods.

Methods

mixed
doTrustedCallback(callable $callback, array $args, $message, string $error_type = TrustedCallbackInterface::THROW_EXCEPTION, string $extra_trusted_interface = NULL)

Performs a callback.

Details

mixed doTrustedCallback(callable $callback, array $args, $message, string $error_type = TrustedCallbackInterface::THROW_EXCEPTION, string $extra_trusted_interface = NULL)

Performs a callback.

If the callback is trusted the callback will occur. Trusted callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or $extra_trusted_interface or be an anonymous function. If the callback is not trusted then whether or not the callback is called and what type of error is thrown depends on $error_type. To provide time for dependent code to use trusted callbacks use TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION and then at a later date change this to TrustedCallbackInterface::THROW_EXCEPTION.

Parameters

callable $callback

The callback to call. Note that callbacks which are objects and use the magic method __invoke() are not supported.

array $args

The arguments to pass the callback.

$message

The error message if the callback is not trusted. If the message contains "%s" it will be replaced in with the resolved callback.

string $error_type

(optional) The type of error to trigger. One of:

  • TrustedCallbackInterface::THROW_EXCEPTION
  • TrustedCallbackInterface::TRIGGER_WARNING
  • TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION Defaults to TrustedCallbackInterface::THROW_EXCEPTION.
string $extra_trusted_interface

(optional) An additional interface that if implemented by the callback object means any public methods on that object are trusted.

Return Value

mixed

The callback's return value.

Exceptions

UntrustedCallbackException

See also

TrustedCallbackInterface