Skip to content

Commit

Permalink
Merge pull request #4 from tienvx/check-for-handler
Browse files Browse the repository at this point in the history
Check for handler
  • Loading branch information
tienvx authored Mar 8, 2023
2 parents f341ae4 + 33496a9 commit 1d0cb4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/EventListener/StateChangeRequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Tienvx\Bundle\PactProviderBundle\Exception\BadMethodCallException;
use Tienvx\Bundle\PactProviderBundle\Exception\BadRequestException;
use Tienvx\Bundle\PactProviderBundle\Exception\NoHandlerForStateException;

class StateChangeRequestListener
{
Expand Down Expand Up @@ -35,6 +36,9 @@ public function __invoke(RequestEvent $event): void
if (!in_array($action, [self::SETUP_ACTION, self::TEARDOWN_ACTION])) {
throw new BadRequestException(sprintf("Action '%s' is not supported in state change request.", $action));
}
if (!$this->locator->has($state)) {
throw new NoHandlerForStateException(sprintf("No handler for state '%s'.", $state));
}
$handler = $this->locator->get($state);
$method = [$handler, self::METHODS[$action]];
if (!is_callable($method)) {
Expand Down
7 changes: 7 additions & 0 deletions src/Exception/NoHandlerForStateException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Tienvx\Bundle\PactProviderBundle\Exception;

class NoHandlerForStateException extends \LogicException
{
}

0 comments on commit 1d0cb4d

Please sign in to comment.