-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(graphql)!: Builder Context (#116)
- Loading branch information
Showing
98 changed files
with
774 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\Builder; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\Context as ContextContract; | ||
use Override; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class Context implements ContextContract { | ||
/** | ||
* @var array<class-string, object|null> | ||
*/ | ||
private array $context = []; | ||
|
||
public function __construct() { | ||
// empty | ||
} | ||
|
||
#[Override] | ||
public function has(string $key): bool { | ||
return isset($this->context[$key]) && $this->context[$key] instanceof $key; | ||
} | ||
|
||
#[Override] | ||
public function get(string $key): mixed { | ||
return isset($this->context[$key]) && $this->context[$key] instanceof $key | ||
? $this->context[$key] | ||
: null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
#[Override] | ||
public function override(array $context): static { | ||
$overridden = clone $this; | ||
|
||
foreach ($context as $key => $value) { | ||
$overridden->context[$key] = $value; | ||
} | ||
|
||
return $overridden; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\Builder\Contexts; | ||
|
||
use LastDragon_ru\LaraASP\GraphQL\Builder\BuilderInfo; | ||
|
||
class AstManipulation { | ||
public function __construct( | ||
public readonly BuilderInfo $builderInfo, | ||
) { | ||
// empty | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace LastDragon_ru\LaraASP\GraphQL\Builder\Contracts; | ||
|
||
interface Context { | ||
/** | ||
* @param class-string $key | ||
*/ | ||
public function has(string $key): bool; | ||
|
||
/** | ||
* @template T of object | ||
* | ||
* @param class-string<T> $key | ||
* | ||
* @return T|null | ||
*/ | ||
public function get(string $key): mixed; | ||
|
||
/** | ||
* @template T of object | ||
* | ||
* @param array<class-string<T>, T|null> $context | ||
*/ | ||
public function override(array $context): static; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.