public function Twig_Sandbox_SecurityPolicy::checkMethodAllowed

Overrides Twig_Sandbox_SecurityPolicyInterface::checkMethodAllowed

File

drupal/core/vendor/twig/twig/lib/Twig/Sandbox/SecurityPolicy.php, line 83

Class

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

Code

public function checkMethodAllowed($obj, $method) {
  if ($obj instanceof Twig_TemplateInterface || $obj instanceof Twig_Markup) {
    return true;
  }
  $allowed = false;
  $method = strtolower($method);
  foreach ($this->allowedMethods as $class => $methods) {
    if ($obj instanceof $class) {
      $allowed = in_array($method, $methods);
      break;
    }
  }
  if (!$allowed) {
    throw new Twig_Sandbox_SecurityError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, get_class($obj)));
  }
}