Minify JavaScript via the command line.

Paramètres

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 dans advagg_ext_minify/advagg_ext_minify.module
Minify CSS using via command line.
advagg_ext_minify_js_minify dans advagg_ext_minify/advagg_ext_minify.module
Minify Javascript using via command line.

Fichier

advagg_ext_minify/advagg_ext_minify.module, line 74

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;
}