Skip to content

Commit 3e743a7

Browse files
committed
Added PHP 8 Attributes for HideParameter, InjectUser and UseInputType annotations
1 parent c617743 commit 3e743a7

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/Annotations/HideParameter.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TheCodingMachine\GraphQLite\Annotations;
66

7+
use Attribute;
78
use BadMethodCallException;
89

910
use function ltrim;
@@ -18,6 +19,7 @@
1819
* @Attribute("for", type = "string")
1920
* })
2021
*/
22+
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
2123
class HideParameter implements ParameterAnnotationInterface
2224
{
2325
/** @var string */
@@ -26,13 +28,13 @@ class HideParameter implements ParameterAnnotationInterface
2628
/**
2729
* @param array<string, mixed> $values
2830
*/
29-
public function __construct(array $values = [])
31+
public function __construct(array $values = [], ?string $for = null)
3032
{
31-
if (! isset($values['for'])) {
33+
if (! isset($for) && ! isset($values['for'])) {
3234
return;
3335
}
3436

35-
$this->for = ltrim($values['for'], '$');
37+
$this->for = ltrim($for ?? $values['for'], '$');
3638
}
3739

3840
public function getTarget(): string

src/Annotations/InjectUser.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TheCodingMachine\GraphQLite\Annotations;
66

7+
use Attribute;
78
use BadMethodCallException;
89

910
use function ltrim;
@@ -18,6 +19,7 @@
1819
* @Attribute("for", type = "string")
1920
* })
2021
*/
22+
#[Attribute(Attribute::TARGET_METHOD)]
2123
class InjectUser implements ParameterAnnotationInterface
2224
{
2325
/** @var string */
@@ -26,13 +28,13 @@ class InjectUser implements ParameterAnnotationInterface
2628
/**
2729
* @param array<string, mixed> $values
2830
*/
29-
public function __construct(array $values = [])
31+
public function __construct(array $values = [], ?string $for = null)
3032
{
31-
if (! isset($values['for'])) {
33+
if (! isset($for) && ! isset($values['for'])) {
3234
return;
3335
}
3436

35-
$this->for = ltrim($values['for'], '$');
37+
$this->for = ltrim($for ?? $values['for'], '$');
3638
}
3739

3840
public function getTarget(): string

src/Annotations/UseInputType.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TheCodingMachine\GraphQLite\Annotations;
66

7+
use Attribute;
78
use BadMethodCallException;
89

910
use function is_string;
@@ -19,6 +20,7 @@
1920
* @Attribute("inputType", type = "string"),
2021
* })
2122
*/
23+
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
2224
class UseInputType implements ParameterAnnotationInterface
2325
{
2426
/** @var string|null */
@@ -31,7 +33,7 @@ class UseInputType implements ParameterAnnotationInterface
3133
*
3234
* @throws BadMethodCallException
3335
*/
34-
public function __construct($inputType = [])
36+
public function __construct($inputType = [], ?string $for = null)
3537
{
3638
$values = $inputType;
3739
if (is_string($values)) {
@@ -41,11 +43,11 @@ public function __construct($inputType = [])
4143
throw new BadMethodCallException('The @UseInputType annotation must be passed an input type. For instance: "@UseInputType(for="$input", inputType="MyInputType")" in PHP 7+ or #[UseInputType("MyInputType")] in PHP 8+');
4244
}
4345
$this->inputType = $values['inputType'];
44-
if (! isset($values['for'])) {
46+
if (! isset($for) &&! isset($values['for'])) {
4547
return;
4648
}
4749

48-
$this->for = ltrim($values['for'], '$');
50+
$this->for = ltrim($for ?? $values['for'], '$');
4951
}
5052

5153
public function getTarget(): string

0 commit comments

Comments
 (0)