Exemple #1
0
 /**
  * Sandbox constructor.
  * @param string $knitCompiledPhp
  * @param array $data
  * @throws KnitException
  */
 public function __construct(string $knitCompiledPhp, array $data = [])
 {
     $this->data = $data;
     $startTimer = microtime(true);
     ob_start();
     include $knitCompiledPhp;
     $this->output = ob_get_contents();
     ob_end_clean();
     if (!defined("COMELY_KNIT") || !defined("COMELY_KNIT_PARSE_TIMER") || !defined("COMELY_KNIT_COMPILED_ON")) {
         throw KnitException::sandBoxError("Bad or incomplete Knit compiled script");
     }
     if (!is_float(COMELY_KNIT_PARSE_TIMER) || !is_float(COMELY_KNIT_COMPILED_ON)) {
         throw KnitException::sandBoxError("Compiled PHP script is missing timestamps");
     }
     $this->timers = [COMELY_KNIT_PARSE_TIMER, COMELY_KNIT_COMPILED_ON, microtime(true) - $startTimer];
 }
Exemple #2
0
 /**
  * @param string $script
  * @param array $data
  * @return Sandbox
  * @throws KnitException
  */
 protected function runSandbox(string $script, array $data) : Sandbox
 {
     try {
         return new Sandbox($script, $data);
     } catch (\Throwable $e) {
         throw KnitException::sandBoxError($e->getMessage());
     }
 }