/** * @test */ public function shouldLoadConfigAndGetCorrectValue() { $config = new Config(__DIR__ . '/../src/config.php'); $command = $config->read('php_command'); $this->assertEquals('php', $command); $this->assertTrue($config->has('tmp_dir')); }
<?php use PhpSandbox\Evaluator\Config; // start count memory usage $ev__memory_bootstrap_start = ['usage' => memory_get_usage(), 'peak' => memory_get_peak_usage()]; require __DIR__ . '/../vendor/raveren/kint/Kint.class.php'; require __DIR__ . '/Evaluator/Config.php'; $config = new Config(__DIR__ . '/config.php'); if (file_exists($config->read('vendors_dir') . '/autoload.php')) { require $config->read('vendors_dir') . '/autoload.php'; } // Kint configuration Kint::$displayCalledFrom = false; Kint::$expandedByDefault = true; Kint::$cliDetection = false; Kint::$theme = 'solarized-dark'; // we do not want calculate memory used by bootstrap $ev__memory = ['usage' => memory_get_usage(), 'peak' => memory_get_peak_usage()]; array_walk($ev__memory, function (&$value, $key) use($ev__memory_bootstrap_start) { $value = $value - $ev__memory_bootstrap_start[$key]; });
require __DIR__ . '/../vendor/autoload.php'; use PhpRouter\Exception\RouteNotFoundException; use PhpRouter\Route; use PhpRouter\RouteCollection; use PhpRouter\Router; use PhpRouter\RouteRequest; use PhpSandbox\Evaluator\Config; use PhpSandbox\Evaluator\Evaluator; use PhpSandbox\Library\LibraryRepository; use PhpSandbox\Library\LibraryService; use PhpSandbox\Snippet\SnippetException; use PhpSandbox\Snippet\SnippetRepository; use PhpSandbox\Snippet\SnippetService; // load config file $config = new Config(__DIR__ . '/../src/config.php'); $routing = new RouteCollection(); /** * get last executed script from tmp file */ $routing->attach(new Route('GET /get_last [ajax]', function () use($config) { if (file_exists($config->read('tmp_dir') . '/code.php')) { echo (new Evaluator($config))->getLastCode(); } })); /** * execute code from post */ $routing->attach(new Route('POST /execute/@phpversion.json [ajax]', ['phpversion' => 'null|[\\d\\.]+'], function ($params) use($config) { if (isset($_POST['code'])) { $code = $_POST['code'];