Last active
August 29, 2015 14:12
-
-
Save codex-corp/a1646c14b1b1fd02cc09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ScrambleVariable extends ScramblerVisitor | |
{ | |
use TrackingRenamerTrait; | |
use ReportArraysTrait; | |
/** | |
* Constructor | |
* | |
* @param StringScrambler $scrambler | |
* @return void | |
**/ | |
public function __construct(StringScrambler $scrambler) | |
{ | |
parent::__construct($scrambler); | |
$this->setIgnore(array("_ENV","PHPSESSID","PHP_SELF","GLOBALS","_COOKIE","_GET","_POST", | |
"_SESSION","_FILES","_REQUEST","_SERVER","this")); | |
} | |
/** | |
* Check all variable nodes | |
* | |
* @param Node $node | |
* @return void | |
**/ | |
public function enterNode(Node $node) | |
{ | |
// Function param or variable use | |
if ($node instanceof Param || $node instanceof Variable) { | |
if (!is_string($node->name)) { | |
return; | |
} | |
if ($this->isRenamed($node->name)) { | |
$node->name = $this->getNewName($node->name); | |
return $node; | |
} | |
} | |
// try {} catch () {} | |
if ($node instanceof CatchStatement) { | |
return $this->scramble($node, 'var'); | |
} | |
// Function() use ($x, $y) {} | |
if ($node instanceof ClosureUse) { | |
return $this->scramble($node, 'var'); | |
} | |
} | |
public function leaveNode(Node $node) { | |
if ($node instanceof Param || $node instanceof Variable) { | |
$originalName = $node->name; | |
if(!in_array($originalName, $this->getRenamed())){ | |
$this->scramble($node); | |
$this->renamed($originalName, $node->name); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment