Same filename in this branch
  1. 6.0.x advagg_css_minify/src/EventSubscriber/MinificationSubscriber.php
  2. 6.0.x advagg_js_minify/src/EventSubscriber/MinificationSubscriber.php
  3. 6.0.x advagg_ext_minify/src/EventSubscriber/MinificationSubscriber.php
Same filename in other branches
  1. 5.0.x advagg_bundler/src/EventSubscriber/MinificationSubscriber.php
  2. 5.0.x advagg_css_minify/src/EventSubscriber/MinificationSubscriber.php
  3. 5.0.x advagg_js_minify/src/EventSubscriber/MinificationSubscriber.php
  4. 5.0.x advagg_ext_minify/src/EventSubscriber/MinificationSubscriber.php
  5. 8.x-3.x advagg_bundler/src/EventSubscriber/MinificationSubscriber.php
  6. 8.x-3.x advagg_css_minify/src/EventSubscriber/MinificationSubscriber.php
  7. 8.x-3.x advagg_js_minify/src/EventSubscriber/MinificationSubscriber.php
  8. 8.x-3.x advagg_ext_minify/src/EventSubscriber/MinificationSubscriber.php
  9. 8.x-4.x advagg_bundler/src/EventSubscriber/MinificationSubscriber.php
  10. 8.x-4.x advagg_css_minify/src/EventSubscriber/MinificationSubscriber.php
  11. 8.x-4.x advagg_js_minify/src/EventSubscriber/MinificationSubscriber.php
  12. 8.x-4.x advagg_ext_minify/src/EventSubscriber/MinificationSubscriber.php

Namespace

Drupal\advagg_bundler\EventSubscriber

Fichier

advagg_bundler/src/EventSubscriber/MinificationSubscriber.php

View source
<?php

namespace Drupal\advagg_bundler\EventSubscriber;

use Drupal\advagg\Asset\AssetOptimizationEvent;
use Drupal\advagg\Asset\SingleAssetOptimizerBase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Subscribe to asset optimization events and minify assets.
 */
class MinificationSubscriber implements EventSubscriberInterface {
    
    /**
     * The minifier.
     *
     * @var \Drupal\advagg\Asset\SingleAssetOptimizerBase
     */
    protected $minifier;
    
    /**
     * Construct the optimizer instance.
     *
     * @param \Drupal\advagg\Asset\SingleAssetOptimizerBase $minifier
     *   The minifier.
     */
    public function __construct(SingleAssetOptimizerBase $minifier) {
        $this->minifier = $minifier;
    }
    
    /**
     * Pass the minification over to the minification service.
     *
     * @param \Drupal\advagg\Asset\AssetOptimizationEvent $asset
     *   The optimization event.
     */
    public function minify(AssetOptimizationEvent $asset) {
        $content = $asset->getContent();
        $content = $this->minifier
            ->optimize($content, $asset->getAsset(), $asset->getData());
        $this->minifier
            ->addLicense($content, $asset->getAsset()['data']);
        $asset->setContent($content);
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() {
        return [
            AssetOptimizationEvent::JS => [
                'minify',
                0,
            ],
        ];
    }

}

Classes

Titre Deprecated Résumé
MinificationSubscriber Subscribe to asset optimization events and minify assets.