Skip to content

Commit b940d36

Browse files
committed
Move the $types argument to TypeGenerator
1 parent d85b1ef commit b940d36

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

UPGRADE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ overrode the service definition, please take into account the new constructor si
4848

4949
```php
5050
public function __construct(
51+
array $typeConfigs,
5152
TypeBuilder $typeBuilder,
5253
EventDispatcherInterface $eventDispatcher,
5354
TypeGeneratorOptions $options
@@ -61,7 +62,6 @@ with the following constructor signature:
6162
public function __construct(
6263
string $namespace,
6364
?string $cacheDir,
64-
array $types,
6565
bool $useClassMap = true,
6666
?string $cacheBaseDir = null,
6767
?int $cacheDirMask = null

src/Generator/TypeGenerator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ class TypeGenerator
2727
public const GRAPHQL_SERVICES = 'services';
2828

2929
private static bool $classMapLoaded = false;
30+
private array $typeConfigs;
3031
private TypeGeneratorOptions $options;
3132
private TypeBuilder $typeBuilder;
3233
private EventDispatcherInterface $dispatcher;
3334

34-
public function __construct(TypeBuilder $typeBuilder, EventDispatcherInterface $dispatcher, TypeGeneratorOptions $options)
35-
{
35+
public function __construct(
36+
array $typeConfigs,
37+
TypeBuilder $typeBuilder,
38+
EventDispatcherInterface $dispatcher,
39+
TypeGeneratorOptions $options
40+
) {
41+
$this->typeConfigs = $typeConfigs;
3642
$this->typeBuilder = $typeBuilder;
3743
$this->dispatcher = $dispatcher;
3844
$this->options = $options;
@@ -49,12 +55,9 @@ public function compile(int $mode): array
4955
$fs->remove($cacheDir);
5056
}
5157

52-
// Process configs
53-
$types = Processor::process($this->options->types);
54-
5558
// Generate classes
5659
$classes = [];
57-
foreach ($types as $name => $config) {
60+
foreach (Processor::process($this->typeConfigs) as $name => $config) {
5861
$config['config']['name'] ??= $name;
5962
$config['config']['class_name'] = $config['class_name'];
6063
$classMap = $this->generateClass($config, $cacheDir, $mode);

src/Generator/TypeGeneratorOptions.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,38 @@
66

77
class TypeGeneratorOptions
88
{
9+
/**
10+
* PSR-4 namespace for generated GraphQL classes.
11+
*/
912
public string $namespace;
13+
14+
/**
15+
* Relative path to a directory for generated GraphQL classes.
16+
* Equals `null` unless explicitly set by user.
17+
*/
1018
public ?string $cacheDir;
11-
public array $types;
19+
20+
/**
21+
* Permission bitmask for the directory of generated classes.
22+
*/
1223
public int $cacheDirMask;
24+
1325
public bool $useClassMap = true;
26+
27+
/**
28+
* Base directory for generated classes.
29+
*/
1430
public ?string $cacheBaseDir;
1531

1632
public function __construct(
1733
string $namespace,
1834
?string $cacheDir,
19-
array $types,
2035
bool $useClassMap = true,
2136
?string $cacheBaseDir = null,
2237
?int $cacheDirMask = null
2338
) {
2439
$this->namespace = $namespace;
2540
$this->cacheDir = $cacheDir;
26-
$this->types = $types;
2741
$this->useClassMap = $useClassMap;
2842
$this->cacheBaseDir = $cacheBaseDir;
2943

src/Resources/config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ services:
6262

6363
Overblog\GraphQLBundle\Generator\TypeGenerator:
6464
arguments:
65+
- '%overblog_graphql_types.config%'
6566
- '@Overblog\GraphQLBundle\Generator\TypeBuilder'
6667
- '@Symfony\Contracts\EventDispatcher\EventDispatcherInterface'
6768
- !service
6869
class: Overblog\GraphQLBundle\Generator\TypeGeneratorOptions
6970
arguments:
7071
- '%overblog_graphql.class_namespace%'
7172
- '%overblog_graphql.cache_dir%'
72-
- '%overblog_graphql_types.config%'
7373
- '%overblog_graphql.use_classloader_listener%'
7474
- '%kernel.cache_dir%'
7575
- '%overblog_graphql.cache_dir_permissions%'

tests/Generator/TypeGeneratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function testCacheDirPermissions(int $expectedMask, ?string $cacheDir, ?i
2222
$typeBuilder = $this->createMock(TypeBuilder::class);
2323
$eventDispatcher = $this->createMock(EventDispatcherInterface::class);
2424

25-
$options = new TypeGeneratorOptions('App', $cacheDir, [], true, null, $cacheDirMask);
25+
$options = new TypeGeneratorOptions('App', $cacheDir, true, null, $cacheDirMask);
2626

27-
$mask = (new TypeGenerator($typeBuilder, $eventDispatcher, $options))->getCacheDirMask();
27+
$mask = (new TypeGenerator([], $typeBuilder, $eventDispatcher, $options))->getCacheDirMask();
2828

2929
$this->assertSame($expectedMask, $mask);
3030
}
@@ -38,9 +38,9 @@ public function testCompiledEvent(): void
3838
->method('dispatch')
3939
->with($this->equalTo(new SchemaCompiledEvent()));
4040

41-
$options = new TypeGeneratorOptions('App', null, []);
41+
$options = new TypeGeneratorOptions('App', null);
4242

43-
(new TypeGenerator($typeBuilder, $eventDispatcher, $options))->compile(TypeGenerator::MODE_DRY_RUN);
43+
(new TypeGenerator([], $typeBuilder, $eventDispatcher, $options))->compile(TypeGenerator::MODE_DRY_RUN);
4444
}
4545

4646
public function getPermissionsProvider(): Generator

0 commit comments

Comments
 (0)