8000 Improve `GeneratorAware` trait and interface (#1755) · zircote/swagger-php@c7e8d1f · GitHub
[go: up one dir, main page]

Skip to content

Commit c7e8d1f

Browse files
authored
Improve GeneratorAware trait and interface (#1755)
1 parent 79eeca7 commit c7e8d1f

8 files changed

+27
-13
lines changed

bin/openapi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ foreach ($options["processor"] as $processor) {
218218
}
219219

220220
$analyser = new ReflectionAnalyser([new DocBlockAnnotationFactory(), new AttributeAnnotationFactory()]);
221+
$analyser->setGenerator($generator);
221222

222223
$openapi = $generator
223224
->setVersion($options['version'])

src/Analysers/AnalyserInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
use OpenApi\Analysis;
1010
use OpenApi\Context;
11-
use OpenApi\Generator;
11+
use OpenApi\GeneratorAwareInterface;
1212

13-
interface AnalyserInterface
13+
interface AnalyserInterface extends GeneratorAwareInterface
1414
{
15-
public function setGenerator(Generator $generator): void;
16-
1715
public function fromFile(string $filename, Context $context): Analysis;
1816
}

src/Analysers/AnnotationFactoryInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88

99
use OpenApi\Annotations as OA;
1010
use OpenApi\Context;
11-
use OpenApi\Generator;
11+
use OpenApi\GeneratorAwareInterface;
1212

13-
interface AnnotationFactoryInterface
13+
interface AnnotationFactoryInterface extends GeneratorAwareInterface
1414
{
1515
/**
1616
* Checks if this factory is supported by the current runtime.
1717
*/
1818
public function isSupported(): bool;
1919

20-
public function setGenerator(Generator $generator): void;
21-
2220
/**
2321
* @return array<OA\AbstractAnnotation> top level annotations
2422
*/

src/Analysers/AttributeAnnotationFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use OpenApi\Annotations as OA;
1010
use OpenApi\Context;
1111
use OpenApi\Generator;
12+
use OpenApi\GeneratorAwareTrait;
1213

1314
class AttributeAnnotationFactory implements AnnotationFactoryInterface
1415
{

src/Analysers/DocBlockAnnotationFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use OpenApi\Annotations as OA;
1010
use OpenApi\Context;
1111
use OpenApi\Generator;
12+
use OpenApi\GeneratorAwareTrait;
1213

1314
class DocBlockAnnotationFactory implements AnnotationFactoryInterface
1415
{
@@ -26,11 +27,13 @@ public function isSupported(): bool
2627
return DocBlockParser::isEnabled();
2728
}
2829

29-
public function setGenerator(Generator $generator): void
30+
public function setGenerator(Generator $generator)
3031
{
3132
$this->generator = $generator;
3233

3334
$this->docBlockParser->setAliases($generator->getAliases());
35+
36+
return $this;
3437
}
3538

3639
public function build(\Reflector $reflector, Context $context): array

src/Analysers/ReflectionAnalyser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OpenApi\Annotations as OA;
1111
use OpenApi\Context;
1212
use OpenApi\Generator;
13+
use OpenApi\GeneratorAwareTrait;
1314
use OpenApi\OpenApiException;
1415

1516
/**

src/GeneratorAwareInterface.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* @license Apache 2.0
5+
*/
6+
7+
namespace OpenApi;
8+
9+
interface GeneratorAwareInterface
10+
{
11+
public function setGenerator(Generator $generator);
12+
}

src/Analysers/GeneratorAwareTrait.php renamed to src/GeneratorAwareTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* @license Apache 2.0
55
*/
66

7-
namespace OpenApi\Analysers;
8-
9-
use OpenApi\Generator;
7+
namespace OpenApi;
108

119
trait GeneratorAwareTrait
1210
{
1311
protected ?Generator $generator = null;
1412

15-
public function setGenerator(Generator $generator): void
13+
public function setGenerator(Generator $generator)
1614
{
1715
$this->generator = $generator;
16+
17+
return $this;
1818
}
1919
}

0 commit comments

Comments
 (0)
0