class HoldTestSubscriber
Same name in other branches
- 9 core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php \Drupal\hold_test\EventSubscriber\HoldTestSubscriber
- 8.9.x core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php \Drupal\hold_test\EventSubscriber\HoldTestSubscriber
- 11.x core/modules/system/tests/modules/hold_test/src/EventSubscriber/HoldTestSubscriber.php \Drupal\hold_test\EventSubscriber\HoldTestSubscriber
Response subscriber to test hold.
Hierarchy
- class \Drupal\hold_test\EventSubscriber\HoldTestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of HoldTestSubscriber
1 file declares its use of HoldTestSubscriber
- hold_test.module in core/
modules/ system/ tests/ modules/ hold_test/ hold_test.module - Contains functions for testing hold request/response.
1 string reference to 'HoldTestSubscriber'
- hold_test.services.yml in core/
modules/ system/ tests/ modules/ hold_test/ hold_test.services.yml - core/modules/system/tests/modules/hold_test/hold_test.services.yml
1 service uses HoldTestSubscriber
- hold_test.response in core/
modules/ system/ tests/ modules/ hold_test/ hold_test.services.yml - Drupal\hold_test\EventSubscriber\HoldTestSubscriber
File
-
core/
modules/ system/ tests/ modules/ hold_test/ src/ EventSubscriber/ HoldTestSubscriber.php, line 11
Namespace
Drupal\hold_test\EventSubscriberView source
class HoldTestSubscriber implements EventSubscriberInterface {
const HOLD_REQUEST = 'request';
const HOLD_RESPONSE = 'response';
/**
* Time in microseconds to wait for before checking if the file is updated.
*
* @var int
*/
const WAIT = 100000;
/**
* The site path.
*
* @var string
*/
protected $sitePath;
/**
* HoldTestSubscriber constructor.
*
* @param string $site_path
* The site path.
*/
public function __construct(string $site_path) {
$this->sitePath = $site_path;
}
/**
* Request hold.
*/
public function onRequest() {
$this->hold(static::HOLD_REQUEST);
}
/**
* Response hold.
*/
public function onRespond() {
$this->hold(static::HOLD_RESPONSE);
}
/**
* Hold process by type.
*
* @param string $type
* Type of hold.
*/
protected function hold($type) {
$path = "{$this->sitePath}/hold_test_{$type}.txt";
while ((bool) file_get_contents($path)) {
usleep(static::WAIT);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
$events[KernelEvents::REQUEST][] = [
'onRequest',
];
$events[KernelEvents::RESPONSE][] = [
'onRespond',
];
return $events;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
HoldTestSubscriber::$sitePath | protected | property | The site path. |
HoldTestSubscriber::getSubscribedEvents | public static | function | |
HoldTestSubscriber::hold | protected | function | Hold process by type. |
HoldTestSubscriber::HOLD_REQUEST | constant | ||
HoldTestSubscriber::HOLD_RESPONSE | constant | ||
HoldTestSubscriber::onRequest | public | function | Request hold. |
HoldTestSubscriber::onRespond | public | function | Response hold. |
HoldTestSubscriber::WAIT | constant | Time in microseconds to wait for before checking if the file is updated. | |
HoldTestSubscriber::__construct | public | function | HoldTestSubscriber constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.