class CssSubscriber in Advanced CSS/JS Aggregation 8.3
Same name and namespace in other branches
- 8.4 advagg_old_ie_compatibility/src/EventSubscriber/CssSubscriber.php \Drupal\advagg_old_ie_compatibility\EventSubscriber\CssSubscriber
Subscribe to CSs asset optimization events and count selectors.
Hierarchy
- class \Drupal\advagg_old_ie_compatibility\EventSubscriber\CssSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of CssSubscriber
1 string reference to 'CssSubscriber'
- advagg_old_ie_compatibility.services.yml in advagg_old_ie_compatibility/
advagg_old_ie_compatibility.services.yml - advagg_old_ie_compatibility/advagg_old_ie_compatibility.services.yml
1 service uses CssSubscriber
File
- advagg_old_ie_compatibility/
src/ EventSubscriber/ CssSubscriber.php, line 11
Namespace
Drupal\advagg_old_ie_compatibility\EventSubscriberView source
class CssSubscriber implements EventSubscriberInterface {
/**
* Scan the asset, count the selectors and save selector count to asset array.
*
* The counting method is very rough and may have inaccuracies - especially if
* there are media queries in the file. Since we only care about the maximum,
* this is acceptable since that reduces performance hit and an exact number
* is unimportant.
*
* @param \Drupal\advagg\Asset\AssetOptimizationEvent $asset
* The asset optimization event.
*/
public function scan(AssetOptimizationEvent $asset) {
$asset_array = $asset
->getAsset();
$asset_array['selectors'] = substr_count($asset
->getContent(), '{');
$asset
->setAsset($asset_array);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
AssetOptimizationEvent::CSS => [
'scan',
100,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CssSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
CssSubscriber:: |
public | function | Scan the asset, count the selectors and save selector count to asset array. |