Same filename in other branches
  1. 6.0.x advagg_mod/src/Asset/RemoveConsoleLog.php
  2. 8.x-3.x advagg_mod/src/Asset/RemoveConsoleLog.php
  3. 8.x-4.x advagg_mod/src/Asset/RemoveConsoleLog.php

Namespace

Drupal\advagg_mod\Asset

Fichier

advagg_mod/src/Asset/RemoveConsoleLog.php

View source
<?php

namespace Drupal\advagg_mod\Asset;


/**
 * Remove console.log() calls from JavaScript Files.
 */
class RemoveConsoleLog {
    
    /**
     * Scan asset contents for console.log() calls and remove them.
     *
     * @param string $contents
     *   The asset contents.
     *
     * @return string
     *   The updated contents.
     */
    public function optimize($contents) {
        $pattern = "/ console.log(.*)/";
        return preg_replace_callback($pattern, [
            $this,
            'removeCallback',
        ], $contents);
    }
    
    /**
     * Remove the console.log() call.
     *
     * @param array $matches
     *   Array of matches from preg_replace_callback().
     *
     * @return string
     *   Replaced string.
     */
    protected function removeCallback(array $matches) {
        return '';
    }

}

Classes

Titre Deprecated Résumé
RemoveConsoleLog Remove console.log() calls from JavaScript Files.