HoldTestSubscriber.php in Drupal 8
File
core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php
View source
<?php
namespace Drupal\hold_test\EventSubscriber;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class HoldTestSubscriber implements EventSubscriberInterface {
const HOLD_REQUEST = 'request';
const HOLD_RESPONSE = 'response';
protected $sitePath;
public function __construct(string $site_path) {
$this->sitePath = $site_path;
}
public function onRequest() {
$this
->hold(static::HOLD_REQUEST);
}
public function onRespond() {
$this
->hold(static::HOLD_RESPONSE);
}
protected function hold($type) {
$path = "{$this->sitePath}/hold_test_{$type}.txt";
do {
$status = (bool) file_get_contents($path);
} while ($status && NULL === usleep(100000));
}
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'onRequest',
];
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}