Skip to content

Commit d85b1ef

Browse files
committed
Change accessibility of type generator options
1 parent 1381982 commit d85b1ef

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

src/CacheWarmer/CompileCacheWarmer.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,16 @@ public function warmUp($cacheDir)
3535
{
3636
if ($this->compiled) {
3737
// use warm up cache dir if type generator cache dir not already explicitly declared
38-
$options = $this->typeGenerator->options;
39-
$cacheBaseDir = $options->cacheBaseDir;
38+
$cacheBaseDir = $this->typeGenerator->getCacheBaseDir();
4039

41-
if (null === $options->cacheDir) {
42-
$options->cacheBaseDir = $cacheDir;
40+
if (null === $this->typeGenerator->getCacheDir()) {
41+
$this->typeGenerator->setCacheBaseDir($cacheDir);
4342
}
4443

4544
$this->typeGenerator->compile(TypeGenerator::MODE_WRITE | TypeGenerator::MODE_OVERRIDE);
4645

4746
if (null !== $cacheBaseDir) {
48-
$options->cacheBaseDir = $cacheBaseDir;
47+
$this->typeGenerator->setCacheBaseDir($cacheBaseDir);
4948
}
5049
}
5150

src/Generator/TypeGenerator.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TypeGenerator
2727
public const GRAPHQL_SERVICES = 'services';
2828

2929
private static bool $classMapLoaded = false;
30-
public TypeGeneratorOptions $options;
30+
private TypeGeneratorOptions $options;
3131
private TypeBuilder $typeBuilder;
3232
private EventDispatcherInterface $dispatcher;
3333

@@ -40,7 +40,7 @@ public function __construct(TypeBuilder $typeBuilder, EventDispatcherInterface $
4040

4141
public function compile(int $mode): array
4242
{
43-
$cacheDir = $this->options->getCacheDirOrDefault();
43+
$cacheDir = $this->getCacheDirOrDefault();
4444
$writeMode = $mode & self::MODE_WRITE;
4545

4646
// Configure write mode
@@ -122,8 +122,33 @@ public function loadClasses(bool $forceReload = false): void
122122
}
123123
}
124124

125+
public function getCacheDir(): ?string
126+
{
127+
return $this->options->cacheDir;
128+
}
129+
130+
public function getCacheDirMask(): int
131+
{
132+
return $this->options->cacheDirMask;
133+
}
134+
135+
public function getCacheBaseDir(): ?string
136+
{
137+
return $this->options->cacheBaseDir;
138+
}
139+
140+
public function setCacheBaseDir(string $dir): void
141+
{
142+
$this->options->cacheBaseDir = $dir;
143+
}
144+
145+
public function getCacheDirOrDefault(): string
146+
{
147+
return $this->options->cacheDir ?? $this->options->cacheBaseDir.'/overblog/graphql-bundle/__definitions__';
148+
}
149+
125150
private function getClassesMap(): string
126151
{
127-
return $this->options->getCacheDirOrDefault().'/__classes.map';
152+
return $this->getCacheDirOrDefault().'/__classes.map';
128153
}
129154
}

src/Generator/TypeGeneratorOptions.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ public function __construct(
3434

3535
$this->cacheDirMask = $cacheDirMask;
3636
}
37-
38-
public function getCacheDirOrDefault(): string
39-
{
40-
return $this->cacheDir ?? $this->cacheBaseDir.'/overblog/graphql-bundle/__definitions__';
41-
}
4237
}

tests/Functional/Command/CompileCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setUp(): void
3333

3434
/** @var TypeGenerator $generator */
3535
$generator = static::$kernel->getContainer()->get('overblog_graphql.cache_compiler');
36-
$this->cacheDir = $generator->options->getCacheDirOrDefault();
36+
$this->cacheDir = $generator->getCacheDirOrDefault();
3737
$this->commandTester = new CommandTester($command);
3838
}
3939

tests/Generator/TypeGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testCacheDirPermissions(int $expectedMask, ?string $cacheDir, ?i
2424

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

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

2929
$this->assertSame($expectedMask, $mask);
3030
}

0 commit comments

Comments
 (0)