-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiDocGenerator.php
57 lines (47 loc) · 1.37 KB
/
ApiDocGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/*
* This file is part of the ApiDocBundle package.
*
* (c) EXSyst
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace EXSyst\Bundle\ApiDocBundle;
use EXSyst\Bundle\ApiDocBundle\Describer\DescriberInterface;
use EXSyst\Component\Swagger\Swagger;
use Psr\Cache\CacheItemPoolInterface;
final class ApiDocGenerator
{
private $swagger;
private $describers;
private $cacheItemPool;
/**
* @param DescriberInterface[] $describers
*/
public function __construct(array $describers, CacheItemPoolInterface $cacheItemPool = null)
{
$this->describers = $describers;
$this->cacheItemPool = $cacheItemPool;
}
public function generate(): Swagger
{
if (null !== $this->swagger) {
return $this->swagger;
}
if ($this->cacheItemPool) {
$item = $this->cacheItemPool->getItem('swagger_doc');
if ($item->isHit()) {
return $this->swagger = $item->get();
}
}
$this->swagger = new Swagger();
foreach ($this->describers as $describer) {
$describer->describe($this->swagger);
}
if (isset($item)) {
$this->cacheItemPool->save($item->set($this->swagger));
}
return $this->swagger;
}
}