/** * Start compilation * @return string optimized source */ function compile($path = null) { // process as root script if path not passed $isroot = is_null($path); if ($isroot) { $path = $this->path; $this->incs = array(); $this->dependencies = array(); } // compile initial source for top-level file // $this->inphp = false; $this->lasttoken = null; $src = $this->compile_php($path, null, $isroot); // second pass to replace constants with literals if option set // if ($this->opt(COMPILER_OPTION_LITERALS)) { $tokens = token_get_all($src); $src = ''; do { $tok = current($tokens); $s = is_array($tok) ? $tok[1] : $tok; if (is_array($tok) && T_STRING === $tok[0]) { $c = $tok[1]; if (isset($this->conf_consts[$c])) { // replace current definition with target config value $s = var_export($this->conf_consts[$c], 1); } else { if (defined($c) && $this->opt(COMPILER_OPTION_LITERALS_SYS)) { // WARNING: extension constants could differ on target environment $s = var_export(constant($c), 1); } } } $src .= $s; } while (next($tokens) !== false); } // bytecode compilation with bcompiler extension // if ($this->opt(COMPILER_OPTION_BYTECODE)) { // extension can only operate on files $srcpath = tempfile($stdin, null); file_put_contents($srcpath, $src); unset($src); // run via shell due to conflict bugs in bcompiler PLUG::exec_bin('bcompile', array($srcpath), $src); } return $src; }