Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (42 sloc)
1.56 KB
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
<?php | |
declare(strict_types=1); | |
namespace Mezzio\Hal; | |
use Psr\Container\ContainerInterface; | |
use Zend\Expressive\Hal\Renderer\JsonRenderer; | |
use Zend\Expressive\Hal\Renderer\XmlRenderer; | |
/** | |
* Create and return a HalResponseFactory instance. | |
* | |
* Utilizes the following services: | |
* | |
* - `Psr\Http\Message\ResponseInterface`; must resolve to a PHP callable capable | |
* of producing an instance of that type. | |
* - `Hal\Renderer\JsonRenderer`, if present; otherwise, creates an instance. | |
* - `Hal\Renderer\XmlRenderer`, if present; otherwise, creates an instance. | |
*/ | |
class HalResponseFactoryFactory | |
{ | |
use Psr17ResponseFactoryTrait; | |
/** | |
* @throws RuntimeException If neither a ResponseInterface service is | |
* present nor laminas-diactoros is installed. | |
*/ | |
public function __invoke(ContainerInterface $container): HalResponseFactory | |
{ | |
$jsonRenderer = $container->has(Renderer\JsonRenderer::class) | |
? $container->get(Renderer\JsonRenderer::class) | |
: ($container->has(JsonRenderer::class) | |
? $container->get(JsonRenderer::class) | |
: new Renderer\JsonRenderer()); | |
$xmlRenderer = $container->has(Renderer\XmlRenderer::class) | |
? $container->get(Renderer\XmlRenderer::class) | |
: ($container->has(XmlRenderer::class) | |
? $container->get(XmlRenderer::class) | |
: new Renderer\XmlRenderer()); | |
return new HalResponseFactory( | |
$this->detectResponseFactory($container), | |
$jsonRenderer, | |
$xmlRenderer | |
); | |
} | |
} |