Skip to content

Commit 0276c54

Browse files
authored
feat(ast): add path() getter method to ASTCache class (#2694)
1 parent a4d126e commit 0276c54

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co
99

1010
## Unreleased
1111

12+
### Added
13+
14+
- Add `path()` method to `ASTCache` class https://github.com/nuwave/lighthouse/pull/2694
15+
1216
## v6.58.0
1317

1418
### Changed

src/Schema/AST/ASTCache.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function isEnabled(): bool
3434
return $this->enable;
3535
}
3636

37+
public function path(): string
38+
{
39+
return $this->path;
40+
}
41+
3742
public function set(DocumentAST $documentAST): void
3843
{
3944
$variable = var_export(
@@ -42,24 +47,25 @@ public function set(DocumentAST $documentAST): void
4247
);
4348

4449
$this->filesystem()->put(
45-
path: $this->path,
50+
path: $this->path(),
4651
contents: /** @lang PHP */ "<?php return {$variable};",
4752
lock: true,
4853
);
4954
}
5055

5156
public function clear(): void
5257
{
53-
$this->filesystem()->delete($this->path);
58+
$this->filesystem()->delete($this->path());
5459
}
5560

5661
/** @param callable(): DocumentAST $build */
5762
public function fromCacheOrBuild(callable $build): DocumentAST
5863
{
59-
if ($this->filesystem()->exists($this->path)) {
60-
$ast = require $this->path;
64+
$path = $this->path();
65+
if ($this->filesystem()->exists($path)) {
66+
$ast = require $path;
6167
if (! is_array($ast)) {
62-
throw new InvalidSchemaCacheContentsException($this->path, $ast);
68+
throw new InvalidSchemaCacheContentsException($path, $ast);
6369
}
6470

6571
/** @var SerializableDocumentAST $ast */

0 commit comments

Comments
 (0)