function TwigSandboxPolicy::checkMethodAllowed
Same name in other branches
- 9 core/lib/Drupal/Core/Template/TwigSandboxPolicy.php \Drupal\Core\Template\TwigSandboxPolicy::checkMethodAllowed()
- 8.9.x core/lib/Drupal/Core/Template/TwigSandboxPolicy.php \Drupal\Core\Template\TwigSandboxPolicy::checkMethodAllowed()
- 10 core/lib/Drupal/Core/Template/TwigSandboxPolicy.php \Drupal\Core\Template\TwigSandboxPolicy::checkMethodAllowed()
File
-
core/
lib/ Drupal/ Core/ Template/ TwigSandboxPolicy.php, line 92
Class
- TwigSandboxPolicy
- Default sandbox policy for Twig templates.
Namespace
Drupal\Core\TemplateCode
public function checkMethodAllowed($obj, $method) : void {
foreach ($this->allowed_classes as $class => $key) {
if ($obj instanceof $class) {
return;
}
}
// Return quickly for an exact match of the method name.
if (isset($this->allowed_methods[$method])) {
return;
}
// If the method name starts with an allowed prefix, allow it. Note:
// strpos() is between 3x and 7x faster than preg_match() in this case.
foreach ($this->allowed_prefixes as $prefix) {
if (str_starts_with($method, $prefix)) {
return;
}
}
throw new SecurityError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, get_class($obj)));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.