public function whitelistInterface($name) { if (func_num_args() > 1) { return $this->whitelistInterface(func_get_args()); } $name = $this->normalizeInterface($name); return $this->whitelist('interfaces', $name); }
/** Examine the current PhpParser\Node node against the PHPSandbox configuration for whitelisting sandboxed code * * @param Node $node The sandboxed $node to examine * * @return null */ public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Class_ && is_string($node->name) && $this->sandbox->allow_classes && $this->sandbox->auto_whitelist_classes && !$this->sandbox->hasBlacklistedClasses()) { $this->sandbox->whitelistClass($node->name); $this->sandbox->whitelistType($node->name); } else { if ($node instanceof Node\Stmt\Interface_ && is_string($node->name) && $this->sandbox->allow_interfaces && $this->sandbox->auto_whitelist_interfaces && !$this->sandbox->hasBlacklistedInterfaces()) { $this->sandbox->whitelistInterface($node->name); } else { if ($node instanceof Node\Stmt\Trait_ && is_string($node->name) && $this->sandbox->allow_traits && $this->sandbox->auto_whitelist_traits && !$this->sandbox->hasBlacklistedTraits()) { $this->sandbox->whitelistTrait($node->name); } else { if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && $node->name->toString() == 'define' && $this->sandbox->allow_constants && $this->sandbox->auto_whitelist_constants && !$this->sandbox->isDefinedFunc('define') && !$this->sandbox->hasBlacklistedConsts()) { $name = isset($node->args[0]) ? $node->args[0] : null; if ($name && $name instanceof Node\Arg && $name->value instanceof Node\Scalar\String_ && is_string($name->value->value) && $name->value->value) { $this->sandbox->whitelistConst($name->value->value); } } else { if ($node instanceof Node\Stmt\Global_ && $this->sandbox->allow_globals && $this->sandbox->auto_whitelist_globals && $this->sandbox->hasWhitelistedVars()) { foreach ($node->vars as $var) { /** * @var Node\Expr\Variable $var */ if ($var instanceof Node\Expr\Variable) { $this->sandbox->whitelistVar($var->name); } } } else { if ($node instanceof Node\Stmt\Function_ && is_string($node->name) && $node->name && $this->sandbox->allow_functions && $this->sandbox->auto_whitelist_functions && !$this->sandbox->hasBlacklistedFuncs()) { $this->sandbox->whitelistFunc($node->name); } } } } } } }