PHP code example of machy8 / google-closure-compiler
1. Go to this page and download the library: Download machy8/google-closure-compiler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
machy8 / google-closure-compiler example snippets
$compiler = new GoogleClosureCompiler\Compiler;
$response = $compiler->setJsCode($code)->compile();
if ($response && $response->isWithoutErrors()) {
echo $response->getCompiledCode();
} else {
echo $code;
}
use GoogleClosureCompiler\Compiler;
/**
* @var Compiler
*/
private $compiler;
public function __construct(Compiler $compiler)
{
$this->compiler = $compiler;
}
public function renderDefault()
{
$code = file_get_contents('/path/to/script.js');
$response = $this->compiler->setJsCode($code)->compile();
if ($response && $response->isWithoutErrors()) {
$code = $response->getCompiledCode();
}
$this->template->jsCode = $code;
}