function advagg_ext_minify_execute_cmd in Advanced CSS/JS Aggregation 8.2
Minify JavaScript via the command line.
Parameters
string $input_file: The file containing the unaltered js data.
string $ext: The string css or js.
Return value
string The file containing the minified js data.
2 calls to advagg_ext_minify_execute_cmd()
- advagg_ext_minify_css_minify in advagg_ext_minify/
advagg_ext_minify.module - Minify CSS using via command line.
- advagg_ext_minify_js_minify in advagg_ext_minify/
advagg_ext_minify.module - Minify Javascript using via command line.
File
- advagg_ext_minify/
advagg_ext_minify.module, line 74 - Advanced CSS/JS aggregation external minification module.
Code
function advagg_ext_minify_execute_cmd($input_file, $ext = '') {
// Get file extension.
if (empty($ext)) {
$ext = strtolower(pathinfo($input_file, PATHINFO_EXTENSION));
if ($ext !== 'css' && $ext !== 'js') {
$info = \Drupal::service('state.advagg.files')
->get($input_file);
$ext = $info['fileext'];
}
}
// Generate temp file.
$temp_file = \Drupal::service("file_system")
->tempnam('temporary://', 'file_advagg_');
$new_temp_file = $temp_file . '.' . basename($input_file);
@rename($temp_file, $new_temp_file);
$output = \Drupal::service('file_system')
->realpath($new_temp_file);
$run = \Drupal::config('advagg_ext_minify.settings')
->get($ext . '_cmd');
$run = str_replace([
'{%CWD%}',
'{%IN%}',
'{%IN_URL_ENC%}',
'{%OUT%}',
], [
\Drupal::root(),
$input_file,
urlencode(file_create_url($input_file)),
escapeshellarg(realpath($output)),
], $run);
// Run command and return the output file.
shell_exec($run);
return $output;
}