Same name in this branch
- 8.x-2.x advagg_bundler/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_bundler\EventSubscriber\InitSubscriber
Same name in other branches
- 5.0.x advagg_mod/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_mod\EventSubscriber\InitSubscriber
- 6.0.x advagg_mod/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_mod\EventSubscriber\InitSubscriber
- 8.x-3.x advagg_mod/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_mod\EventSubscriber\InitSubscriber
- 8.x-4.x advagg_mod/src/EventSubscriber/InitSubscriber.php \Drupal\advagg_mod\EventSubscriber\InitSubscriber
Perform initialization tasks for advagg_mod.
Hierarchy
- class \Drupal\advagg_mod\EventSubscriber\InitSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of InitSubscriber
1 string reference to 'InitSubscriber'
- advagg_mod.services.yml dans advagg_mod/
advagg_mod.services.yml - advagg_mod/advagg_mod.services.yml
1 service uses InitSubscriber
Fichier
-
advagg_mod/
src/ EventSubscriber/ InitSubscriber.php, line 12
Namespace
Drupal\advagg_mod\EventSubscriberView source
class InitSubscriber implements EventSubscriberInterface {
/**
* A config object for the advagg_mod configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* An editable config object for the advagg configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $advaggConfig;
/**
* Constructs the Subscriber object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* A config factory for retrieving required config objects.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->config = $config_factory->get('advagg.settings');
$this->advaggConfig = $config_factory->getEditable('advagg.settings');
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => [
'onEvent',
0,
],
];
}
/**
* Synchronize global_counter variable between sites.
*
* Only if using unified_multisite_dir.
*/
public function onEvent() {
$dir = rtrim($this->config
->get('unified_multisite_dir'), '/');
if (empty($dir) || !file_exists($dir) || !is_dir($dir)) {
return;
}
$counter_filename = $dir . '/_global_counter';
$local_counter = advagg_get_global_counter();
if (!file_exists($counter_filename)) {
file_unmanaged_save_data($local_counter, $counter_filename, FILE_EXISTS_REPLACE);
}
else {
$shared_counter = (int) file_get_contents($counter_filename);
if ($shared_counter == $local_counter) {
// Counters are the same, return.
return;
}
elseif ($shared_counter < $local_counter) {
// Local counter is higher, update saved file and return.
ile_unmanaged_save_data($local_counter, $counter_filename, FILE_EXISTS_REPLACE);
return;
}
elseif ($shared_counter > $local_counter) {
// Shared counter is higher, update local copy and return.
$this->advaggConfig
->set('global_counter', $shared_counter)
->save();
return;
}
}
}
}
Members
Titre Trier par ordre décroissant | Modifiers | Object type | Résumé |
---|---|---|---|
InitSubscriber::$advaggConfig | protected | property | An editable config object for the advagg configuration. |
InitSubscriber::$config | protected | property | A config object for the advagg_mod configuration. |
InitSubscriber::getSubscribedEvents | public static | function | |
InitSubscriber::onEvent | public | function | Synchronize global_counter variable between sites. |
InitSubscriber::__construct | public | function | Constructs the Subscriber object. |