-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #337: Implemented handle delegators
Signed-off-by: alexmerlin <[email protected]>
- Loading branch information
1 parent
9060c52
commit 6a69ccf
Showing
33 changed files
with
318 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Api\App\Entity; | ||
|
||
interface EntityInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Api\App\Exception; | ||
|
||
class RuntimeException extends \RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Api\App\Factory; | ||
|
||
use Api\App\Exception\RuntimeException; | ||
use Api\App\Handler\AbstractHandler; | ||
use Api\App\Message; | ||
use Mezzio\Hal\HalResponseFactory; | ||
use Mezzio\Hal\ResourceGenerator; | ||
use Mezzio\ProblemDetails\ProblemDetailsResponseFactory; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
use function assert; | ||
use function sprintf; | ||
|
||
class HandlerDelegatorFactory | ||
{ | ||
/** | ||
* @param class-string $name | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
* @throws RuntimeException | ||
*/ | ||
public function __invoke( | ||
ContainerInterface $container, | ||
string $name, | ||
callable $callback | ||
): RequestHandlerInterface { | ||
if (! $container->has(HalResponseFactory::class)) { | ||
throw new RuntimeException(sprintf(Message::SERVICE_NOT_FOUND, HalResponseFactory::class)); | ||
} | ||
|
||
if (! $container->has(ResourceGenerator::class)) { | ||
throw new RuntimeException(sprintf(Message::SERVICE_NOT_FOUND, ResourceGenerator::class)); | ||
} | ||
|
||
if (! $container->has(ProblemDetailsResponseFactory::class)) { | ||
throw new RuntimeException(sprintf(Message::SERVICE_NOT_FOUND, ProblemDetailsResponseFactory::class)); | ||
} | ||
|
||
$handler = $callback(); | ||
assert($handler instanceof AbstractHandler); | ||
|
||
return $handler | ||
->setResponseFactory($container->get(HalResponseFactory::class)) | ||
->setResourceGenerator($container->get(ResourceGenerator::class)); | ||
} | ||
} |
Oops, something went wrong.