Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SecurityPolicy.php

function SecurityPolicy::checkMethodAllowed

Overrides SecurityPolicyInterface::checkMethodAllowed

File

vendor/twig/twig/src/Sandbox/SecurityPolicy.php, line 94

Class

SecurityPolicy
Represents a security policy which need to be enforced when sandbox mode is enabled.

Namespace

Twig\Sandbox

Code

public function checkMethodAllowed($obj, $method) : void {
    if ($obj instanceof Template || $obj instanceof Markup) {
        return;
    }
    $allowed = false;
    $method = strtolower($method);
    foreach ($this->allowedMethods as $class => $methods) {
        if ($obj instanceof $class && \in_array($method, $methods)) {
            $allowed = true;
            break;
        }
    }
    if (!$allowed) {
        $class = \get_class($obj);
        throw new SecurityNotAllowedMethodError(\sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
    }
}
RSS feed
Powered by Drupal