Skip to content

Commit

Permalink
More context.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Jun 14, 2021
1 parent 641b16c commit 2f06c98
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/Event/StompHeaderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ class StompHeaderEvent implements StompHeaderEventInterface {
*/
protected $user;

/**
* An array of data to be sent with the STOMP request, for context.
*
* @var array
*/
protected $data;

/**
* An array of configuration used to generate $data, for context.
*
* @var array
*/
protected $configuration;

/**
* The set of headers.
*
Expand All @@ -37,9 +51,11 @@ class StompHeaderEvent implements StompHeaderEventInterface {
/**
* Constructor.
*/
public function __construct(EntityInterface $entity, AccountInterface $user) {
public function __construct(EntityInterface $entity, AccountInterface $user, array $data, array $configuration) {
$this->entity = $entity;
$this->user = $user;
$this->data = $data;
$this->configuration = $configuration;
$this->headers = new ParameterBag();
}

Expand All @@ -57,11 +73,25 @@ public function getUser() {
return $this->user;
}

/**
* {@inheritdoc}
*/
public function getData() {
return $this->data;
}

/**
* {@inheritdoc}
*/
public function getHeaders() {
return $this->headers;
}

/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}

}
16 changes: 16 additions & 0 deletions src/Event/StompHeaderEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ public function getEntity();
*/
public function getUser();

/**
* Fetch the data to be sent in the body of the request.
*
* @return array
* The array of data.
*/
public function getData();

/**
* Fetch the configuration of the action, for context.
*
* @return array
* The array of configuration for the upstream action.
*/
public function getConfiguration();

}
2 changes: 1 addition & 1 deletion src/EventGenerator/EmitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function execute($entity = NULL) {

$event = $this->eventDispatcher->dispatch(
StompHeaderEvent::EVENT_NAME,
new StompHeaderEvent($entity, $user)
new StompHeaderEvent($entity, $user, $data, $this->getConfiguration())
);

$message = new Message(
Expand Down
3 changes: 3 additions & 0 deletions src/EventSubscriber/StompHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\jwt\Authentication\Provider\JwtAuth;

use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -15,6 +16,8 @@
*/
class StompHeaderEventSubscriber implements EventSubscriberInterface {

use StringTranslationTrait;

/**
* The JWT auth service.
*
Expand Down

0 comments on commit 2f06c98

Please sign in to comment.