Airship\Engine\Gears::coreEval PHP Method

coreEval() protected static method

Execute a block of code.
protected static coreEval ( string $code, boolean $cache = false, boolean $do_not_eval = false ) : mixed
$code string
$cache boolean
$do_not_eval boolean
return mixed
    protected static function coreEval(string $code, bool $cache = false, bool $do_not_eval = false)
    {
        \clearstatcache();
        if ($do_not_eval || \Airship\is_disabled('eval')) {
            if ($cache) {
                if (!\file_exists(ROOT . "/tmp/cache/gear")) {
                    \mkdir(ROOT . "/tmp/cache/gear", 0777);
                    \clearstatcache();
                }
                $hashed = Base64UrlSafe::encode(CryptoUtil::raw_hash($code, 33));
                if (!\file_exists(ROOT . '/tmp/cache/gear/' . $hashed . '.tmp.php')) {
                    \file_put_contents(ROOT . '/tmp/cache/gear/' . $hashed . '.tmp.php', '<?php' . "\n" . $code);
                }
                return self::sandboxRequire(ROOT . '/cache/' . $hashed . '.tmp.php');
            } else {
                if (!\file_exists(ROOT . '/tmp/gear')) {
                    \mkdir(ROOT . '/tmp/gear', 0777);
                    \clearstatcache();
                }
                $file = \Airship\tempnam('gear-', 'php', ROOT . '/tmp/gear');
                \file_put_contents($file, '<?php' . "\n" . $code);
                \clearstatcache();
                $ret = self::sandboxRequire($file);
                \unlink($file);
                \clearstatcache();
                return $ret;
            }
        } else {
            return eval($code);
        }
    }