NelmioApiDocBundle/Describer/ExternalDocDescriber.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2016-07-28 10:20:59 +02:00
<?php
/*
2016-12-29 12:09:26 +01:00
* This file is part of the NelmioApiDocBundle package.
2016-07-28 10:20:59 +02:00
*
2016-12-29 12:09:26 +01:00
* (c) Nelmio
2016-07-28 10:20:59 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2016-12-29 12:09:26 +01:00
namespace Nelmio\ApiDocBundle\Describer;
2016-07-28 10:20:59 +02:00
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OA;
2016-07-28 10:20:59 +02:00
class ExternalDocDescriber implements DescriberInterface
{
private $externalDoc;
2017-12-22 17:42:18 +00:00
2016-07-29 10:22:40 +02:00
private $overwrite;
2016-07-28 10:20:59 +02:00
/**
* @param array|callable $externalDoc
*/
2016-07-29 10:22:40 +02:00
public function __construct($externalDoc, bool $overwrite = false)
2016-07-28 10:20:59 +02:00
{
$this->externalDoc = $externalDoc;
2016-07-29 10:22:40 +02:00
$this->overwrite = $overwrite;
2016-07-28 10:20:59 +02:00
}
public function describe(OA\OpenApi $api)
2016-07-28 10:20:59 +02:00
{
$externalDoc = $this->getExternalDoc();
if (!empty($externalDoc)) {
Util::merge($api, $externalDoc, $this->overwrite);
}
2016-07-28 10:20:59 +02:00
}
2016-07-29 10:22:40 +02:00
private function getExternalDoc()
2016-07-28 10:20:59 +02:00
{
if (is_callable($this->externalDoc)) {
return call_user_func($this->externalDoc);
}
return $this->externalDoc;
}
}