You are here

public function MinifyHTMLExit::__construct in Minify Source HTML 8

Constructs a MinifyHTMLExit object.

File

src/EventSubscriber/MinifyHTMLExit.php, line 68

Class

MinifyHTMLExit
Minifies the HTML of the response.

Namespace

Drupal\minifyhtml\EventSubscriber

Code

public function __construct() {

  // To prevent warnings thrown by func_get_arg(), only attempt to get the
  // args if there are exactly 3.
  $arg_error = TRUE;
  if (func_num_args() == 3) {

    // Assigning the arguments this way prevents a signature mismatch
    // exception that will occur until the cache is cleared to update the
    // service definition. However, the cache cannot be cleared due to the
    // exception.
    $this->config = func_get_arg(0);
    $this->time = func_get_arg(1);
    $this->logger = func_get_arg(2);
    if ($this->config) {
      $this->token = 'MINIFYHTML_' . md5($this->time
        ->getRequestTime());
      $arg_error = FALSE;
    }
  }

  // Abort minification until cache is cleared.
  if ($arg_error) {
    \Drupal::messenger()
      ->addWarning(t('Minify HTML has been disabled until the cache has been cleared.'));
    $this->abort = TRUE;
  }
}