-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To inject services in #[Type] methods.
- Loading branch information
Showing
31 changed files
with
577 additions
and
115 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
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jerowork\GraphqlAttributeSchema\Attribute; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_PARAMETER)] | ||
final readonly class Autowire | ||
{ | ||
/** | ||
* @param string|class-string $service | ||
*/ | ||
public function __construct( | ||
public ?string $service = null, | ||
) {} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jerowork\GraphqlAttributeSchema\Parser\Node\Child; | ||
|
||
use Jerowork\GraphqlAttributeSchema\Parser\Node\ArraySerializable; | ||
|
||
/** | ||
* @phpstan-type AutowireNodePayload array{ | ||
* service: string|class-string, | ||
* propertyName: string, | ||
* } | ||
* | ||
* @implements ArraySerializable<AutowireNodePayload> | ||
*/ | ||
final readonly class AutowireNode implements ArraySerializable | ||
{ | ||
public function __construct( | ||
public string $service, | ||
public string $propertyName, | ||
) {} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'service' => $this->service, | ||
'propertyName' => $this->propertyName, | ||
]; | ||
} | ||
|
||
public static function fromArray(array $payload): AutowireNode | ||
{ | ||
return new self( | ||
$payload['service'], | ||
$payload['propertyName'], | ||
); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jerowork\GraphqlAttributeSchema\Parser\NodeParser\Child; | ||
|
||
use Jerowork\GraphqlAttributeSchema\Attribute\Arg; | ||
use Jerowork\GraphqlAttributeSchema\Parser\Node\Child\ArgNode; | ||
use Jerowork\GraphqlAttributeSchema\Parser\NodeParser\GetTypeTrait; | ||
use Jerowork\GraphqlAttributeSchema\Parser\NodeParser\ParseException; | ||
use ReflectionParameter; | ||
|
||
final readonly class ArgNodeParser | ||
{ | ||
use GetTypeTrait; | ||
|
||
/** | ||
* @throws ParseException | ||
*/ | ||
public function parse(ReflectionParameter $parameter, ?Arg $attribute): ArgNode | ||
{ | ||
$type = $this->getType($parameter->getType(), $attribute); | ||
|
||
if ($type === null) { | ||
throw ParseException::invalidParameterType($parameter->getName()); | ||
} | ||
|
||
return new ArgNode( | ||
$type, | ||
$attribute->name ?? $parameter->getName(), | ||
$attribute?->description, | ||
$parameter->getName(), | ||
); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jerowork\GraphqlAttributeSchema\Parser\NodeParser\Child; | ||
|
||
use Jerowork\GraphqlAttributeSchema\Attribute\Autowire; | ||
use Jerowork\GraphqlAttributeSchema\Parser\Node\Child\AutowireNode; | ||
use Jerowork\GraphqlAttributeSchema\Parser\NodeParser\ParseException; | ||
use ReflectionParameter; | ||
use ReflectionNamedType; | ||
|
||
final readonly class AutowireNodeParser | ||
{ | ||
/** | ||
* @throws ParseException | ||
*/ | ||
public function parse(ReflectionParameter $parameter, Autowire $attribute): AutowireNode | ||
{ | ||
if ($attribute->service !== null) { | ||
return new AutowireNode( | ||
$attribute->service, | ||
$parameter->getName(), | ||
); | ||
} | ||
|
||
if (!$parameter->getType() instanceof ReflectionNamedType) { | ||
throw ParseException::invalidAutowiredParameterType($parameter->getName()); | ||
} | ||
|
||
return new AutowireNode( | ||
$parameter->getType()->getName(), | ||
$parameter->getName(), | ||
); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.