Skip to content

Commit 0a31079

Browse files
committed
Add a dispatch proxy method in the ControllerTrait
1 parent 0a6c562 commit 0a31079

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\HttpFoundation\StreamedResponse;
2222
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2323
use Symfony\Component\HttpKernel\HttpKernelInterface;
24+
use Symfony\Component\Message\MessageBusInterface;
2425
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2526
use Symfony\Component\Security\Csrf\CsrfToken;
2627
use Symfony\Component\Form\Extension\Core\Type\FormType;
@@ -383,4 +384,20 @@ protected function isCsrfTokenValid(string $id, string $token): bool
383384

384385
return $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($id, $token));
385386
}
387+
388+
/**
389+
* Dispatches a message to the bus.
390+
*
391+
* @param object $message The message to dispatch
392+
*
393+
* @return mixed The result from the bus
394+
*/
395+
final protected function dispatch($message)
396+
{
397+
if (!$this->container->has('message_bus')) {
398+
throw new \LogicException('The message bus is not enabled in your application. Enable it with the "message" key in "config/packages/framework.yaml".');
399+
}
400+
401+
return $this->container->get('message_bus')->dispatch($message);
402+
}
386403
}

0 commit comments

Comments
 (0)