Corveda / PHPSandbox

A PHP-based sandboxing library with a full suite of configuration and validation options.
https://phpsandbox.org
Other
220 stars 46 forks source link

Get all executed functions #38

Closed m4n50n closed 8 months ago

m4n50n commented 9 months ago

Hello,

is there any way to get, at the end of the execution, all the functions that have been executed? Something similar to saving in an array all the $name that pass through the checkFunc method of PHPSandbox.php.

Thanks!

fieryprophet commented 8 months ago

Not that I can think of off the top of my head, but it would potentially be an intriguing feature to be able to observe what is actually executed in the sandbox via some sort of hook system. Food for thought for future development.

fieryprophet commented 8 months ago

@m4n50n Actually I think one way you could handle this is by adding a custom function validator that simply logs the functions it checks but returns true for all inputs. You would need the validate_functions flag set to true of course.

Like so:

$logger = new Logger(); //example logger object

$sandbox->setFuncValdiator(function(string $function, PHPSandbox $instance)use($logger){
    $logger->debug($function);
    return true;
});
m4n50n commented 7 months ago

@fieryprophet your solution works for now, thanks!