You are here

class RemoveConsoleLog in Advanced CSS/JS Aggregation 8.3

Same name and namespace in other branches
  1. 8.4 advagg_mod/src/Asset/RemoveConsoleLog.php \Drupal\advagg_mod\Asset\RemoveConsoleLog

Remove console.log() calls from JavaScript Files.

Hierarchy

Expanded class hierarchy of RemoveConsoleLog

1 file declares its use of RemoveConsoleLog
InitSubscriber.php in advagg_mod/src/EventSubscriber/InitSubscriber.php
1 string reference to 'RemoveConsoleLog'
advagg_mod.services.yml in advagg_mod/advagg_mod.services.yml
advagg_mod/advagg_mod.services.yml
1 service uses RemoveConsoleLog
advagg_mod.remove_console_log in advagg_mod/advagg_mod.services.yml
Drupal\advagg_mod\Asset\RemoveConsoleLog

File

advagg_mod/src/Asset/RemoveConsoleLog.php, line 8

Namespace

Drupal\advagg_mod\Asset
View source
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 '';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoveConsoleLog::optimize public function Scan asset contents for console.log() calls and remove them.
RemoveConsoleLog::removeCallback protected function Remove the console.log() call.