PHP Class PhpSandbox\ValidatorVisitor

This class takes parsed AST code and checks it against the passed PHPSandbox instance configuration for errors, and throws exceptions if they are found
Author: Elijah Horton ([email protected])
Inheritance: extends PhpParser\NodeVisitorAbstract
Show file Open project: Corveda/PHPSandbox

Protected Properties

Property Type Description
$sandbox PHPSandbox The PHPSandbox instance to check against

Public Methods

Method Description
__construct ( PHPSandbox $sandbox ) ValidatorVisitor class constructor
leaveNode ( PhpParser\Node $node ) : PhpParser\Node | boolean | null Examine the current PhpParser_Node node against the PHPSandbox configuration for validating sandboxed code

Protected Methods

Method Description
isKeyword ( PhpParser\Node $node ) : string | null Test the current PhpParser_Node node to see if it is a keyword, and return the name if it is and null if it is not
isMagicConst ( PhpParser\Node $node ) : string | null Test the current PhpParser_Node node to see if it is a magic constant, and return the name if it is and null if it is not
isOperator ( PhpParser\Node $node ) : string | null Test the current PhpParser_Node node to see if it is an operator, and return the name if it is and null if it is not
isPrimitive ( PhpParser\Node $node ) : string | null Test the current PhpParser_Node node to see if it is a primitive, and return the name if it is and null if it is not

Method Details

__construct() public method

This constructor takes a passed PHPSandbox instance to check against for validating sandboxed code.
public __construct ( PHPSandbox $sandbox )
$sandbox PHPSandbox The PHPSandbox instance to check against

isKeyword() protected method

Test the current PhpParser_Node node to see if it is a keyword, and return the name if it is and null if it is not
protected isKeyword ( PhpParser\Node $node ) : string | null
$node PhpParser\Node The sandboxed $node to test
return string | null Return string name of node, or null if it is not a keyword

isMagicConst() protected method

Test the current PhpParser_Node node to see if it is a magic constant, and return the name if it is and null if it is not
protected isMagicConst ( PhpParser\Node $node ) : string | null
$node PhpParser\Node The sandboxed $node to test
return string | null Return string name of node, or null if it is not a magic constant

isOperator() protected method

Test the current PhpParser_Node node to see if it is an operator, and return the name if it is and null if it is not
protected isOperator ( PhpParser\Node $node ) : string | null
$node PhpParser\Node The sandboxed $node to test
return string | null Return string name of node, or null if it is not an operator

isPrimitive() protected method

Test the current PhpParser_Node node to see if it is a primitive, and return the name if it is and null if it is not
protected isPrimitive ( PhpParser\Node $node ) : string | null
$node PhpParser\Node The sandboxed $node to test
return string | null Return string name of node, or null if it is not a primitive

leaveNode() public method

Examine the current PhpParser_Node node against the PHPSandbox configuration for validating sandboxed code
public leaveNode ( PhpParser\Node $node ) : PhpParser\Node | boolean | null
$node PhpParser\Node The sandboxed $node to validate
return PhpParser\Node | boolean | null Return rewritten node, false if node must be removed, or null if no changes to the node are made

Property Details

$sandbox protected property

The PHPSandbox instance to check against
protected PHPSandbox,phpsandbox $sandbox
return PHPSandbox