| 1 | <?php |
||
| 2 | namespace Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\Provider; |
||
| 3 | |||
| 4 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
| 5 | use Yoanm\JsonRpcHttpServerSwaggerDoc\Infra\Normalizer\DocNormalizer; |
||
| 6 | use Yoanm\SymfonyJsonRpcHttpServerDoc\Creator\HttpServerDocCreator; |
||
| 7 | use Yoanm\SymfonyJsonRpcHttpServerDoc\Provider\DocProviderInterface; |
||
| 8 | use Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\Event\SwaggerDocCreatedEvent; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class DocProvider |
||
| 12 | */ |
||
| 13 | class DocProvider implements DocProviderInterface |
||
| 14 | { |
||
| 15 | /** @var EventDispatcherInterface */ |
||
| 16 | private $dispatcher; |
||
| 17 | /** @var HttpServerDocCreator */ |
||
| 18 | private $serverDocCreator; |
||
| 19 | /** @var DocNormalizer */ |
||
| 20 | private $docNormalizer; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param EventDispatcherInterface $dispatcher |
||
| 24 | * @param HttpServerDocCreator $serverDocCreator |
||
| 25 | * @param DocNormalizer $docNormalizer |
||
| 26 | */ |
||
| 27 | public function __construct( |
||
| 28 | EventDispatcherInterface $dispatcher, |
||
| 29 | HttpServerDocCreator $serverDocCreator, |
||
| 30 | DocNormalizer $docNormalizer |
||
| 31 | ) { |
||
| 32 | $this->dispatcher = $dispatcher; |
||
| 33 | $this->serverDocCreator = $serverDocCreator; |
||
| 34 | $this->docNormalizer = $docNormalizer; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param string|null $host |
||
| 39 | * |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | public function getDoc($host = null) : array |
||
| 43 | { |
||
| 44 | $rawDoc = $this->serverDocCreator->create($host); |
||
| 45 | $swaggerDoc = $this->docNormalizer->normalize($rawDoc); |
||
| 46 | |||
| 47 | $event = new SwaggerDocCreatedEvent($swaggerDoc, $rawDoc); |
||
| 48 | $this->dispatcher->dispatch($event::EVENT_NAME, $event); |
||
| 49 | |||
| 50 | return $event->getSwaggerDoc(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function supports($filename, $host = null) : bool |
||
| 57 | { |
||
| 58 | return 'swagger.json' === $filename; |
||
| 59 | } |
||
| 60 | } |
||
| 61 |