public function testCompile() { $compression = 'none'; $namespaced = 'yes'; $selection = array('_phpjs_shared_bc' => true, 'array_shift' => true, 'bcadd' => true); $options = array('pref_title' => 'test.php', 'compression' => $compression, 'namespaced' => $namespaced); #$selection = array_flip(array_keys($this->PHPJS->Functions)); // Set selection $this->PHPJS->clearSelection(); foreach ($selection as $functionName => $bool) { $this->PHPJS->addToSelection('function::' . $functionName); } #pr($this->PHPJS->getSelection()); // Set flags $flags = 0; if ($options['namespaced'] == 'yes') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_NAMESPACED; } elseif ($options['namespaced'] == 'commonjs') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_COMMONJS; } if ($options['compression'] == 'minified') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_MINFIED; } if ($options['compression'] == 'packed') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_PACKED; } $code = $this->PHPJS->compile($flags, 't' . date("H:i:s")); $tmp = tempnam('/tmp', 'phpjstest') . '.js'; echo "You could run: \n rhino -debug " . $tmp . "\n"; file_put_contents($tmp, $code); }
public function testCompile() { $compression = 'none'; $namespaced = 'yes'; $selection = array('array_shift' => true, 'bcadd' => true); $options = array('pref_title' => 'test.php', 'compression' => $compression, 'namespaced' => $namespaced); $selection = array_flip(array_keys($this->PHPJS->Functions)); // Set selection $this->PHPJS->clearSelection(); foreach ($selection as $functionName => $bool) { $this->PHPJS->addToSelection('function::' . $functionName); } // Set flags $flags = 0; if ($options['namespaced'] == 'yes') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_NAMESPACED; } if ($options['compression'] == 'minified') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_MINFIED; } if ($options['compression'] == 'packed') { $flags = $flags | PHPJS_Library_Compiler::COMPILE_PACKED; } $code = $this->PHPJS->compile($flags, 't000'); $tmp = tempnam('/tmp', 'phpjstest'); file_put_contents($tmp, $code); }