PhpSandbox\PHPSandbox::validate PHP Méthode

validate() public méthode

Validate passed callable for execution
public validate ( callable | string $code )
$code callable | string The callable or string of code to validate
    public function validate($code)
    {
        $this->preparsed_code = $this->disassemble($code);
        $factory = new ParserFactory();
        $parser = $factory->create(ParserFactory::PREFER_PHP5);
        try {
            $this->parsed_ast = $parser->parse($this->preparsed_code);
        } catch (ParserError $error) {
            $this->validationError("Could not parse sandboxed code!", Error::PARSER_ERROR, null, $this->preparsed_code, $error);
        }
        $prettyPrinter = new Standard();
        if ($this->allow_functions && $this->auto_whitelist_functions || $this->allow_constants && $this->auto_whitelist_constants || $this->allow_classes && $this->auto_whitelist_classes || $this->allow_interfaces && $this->auto_whitelist_interfaces || $this->allow_traits && $this->auto_whitelist_traits || $this->allow_globals && $this->auto_whitelist_globals) {
            $traverser = new NodeTraverser();
            $whitelister = new SandboxWhitelistVisitor($this);
            $traverser->addVisitor($whitelister);
            $traverser->traverse($this->parsed_ast);
        }
        $traverser = new NodeTraverser();
        $validator = new ValidatorVisitor($this);
        $traverser->addVisitor($validator);
        $this->prepared_ast = $traverser->traverse($this->parsed_ast);
        $this->prepared_code = $prettyPrinter->prettyPrint($this->prepared_ast);
        return $this;
    }
PHPSandbox