Skip to content

Commit 88c050e

Browse files
committed
Merge branch '0.13'
2 parents 2d5692c + ff62876 commit 88c050e

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

UPGRADE-0.13.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The new `default_field_resolver` config entry accepts callable service id.
2323
Stop using internally `symfony/property-access` package
2424
since it was a bottleneck to performance for large schema.
2525

26-
Array access and camelize getter are supported but isser, hasser,
26+
Array access and camelize getter/isser are supported but hasser,
2727
jQuery style (e.g. `last()`) and "can" property accessors
2828
are no more supported out-of-the-box,
2929
please implement a custom resolver if these accessors are needed.

src/Config/Parser/AnnotationParser.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ private static function getTypeFieldConfigurationFromReflector(GraphClass $graph
511511
if (!empty($fieldAnnotation->args)) {
512512
foreach ($fieldAnnotation->args as $arg) {
513513
$args[$arg->name] = ['type' => $arg->type]
514-
+ ($arg->description ? ['description' => $arg->description] : [])
515-
+ ($arg->default ? ['defaultValue' => $arg->default] : []);
514+
+ (null !== $arg->description ? ['description' => $arg->description] : [])
515+
+ (null !== $arg->default ? ['defaultValue' => $arg->default] : []);
516516
}
517517
} elseif ($reflector instanceof ReflectionMethod) {
518518
$args = self::guessArgs($reflector);
@@ -741,6 +741,28 @@ private static function getDescriptionConfiguration(array $annotations, bool $wi
741741
return $config;
742742
}
743743

744+
/**
745+
* Get args config from an array of @Arg annotation or by auto-guessing if a method is provided.
746+
*
747+
* @param array $args
748+
* @param ReflectionMethod $method
749+
*/
750+
private static function getArgs(array $args = null, ReflectionMethod $method = null): array
751+
{
752+
$config = [];
753+
if ($args && !empty($args)) {
754+
foreach ($args as $arg) {
755+
$config[$arg->name] = ['type' => $arg->type]
756+
+ ($arg->description ? ['description' => $arg->description] : [])
757+
+ ($arg->default ? ['defaultValue' => $arg->default] : []);
758+
}
759+
} elseif ($method) {
760+
$config = self::guessArgs($method);
761+
}
762+
763+
return $config;
764+
}
765+
744766
/**
745767
* Format an array of args to a list of arguments in an expression.
746768
*/

src/Resolver/FieldResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public static function valueFromObjectOrArray($objectOrArray, string $fieldName)
4242
} elseif (is_object($objectOrArray)) {
4343
if (null !== $getter = self::guessObjectMethod($objectOrArray, $fieldName, 'get')) {
4444
$value = $objectOrArray->$getter();
45+
} elseif (null !== $getter = self::guessObjectMethod($objectOrArray, $fieldName, 'is')) {
46+
$value = $objectOrArray->$getter();
4547
} elseif (null !== $getter = self::guessObjectMethod($objectOrArray, $fieldName, '')) {
4648
$value = $objectOrArray->$getter();
4749
} elseif (isset($objectOrArray->$fieldName)) {

tests/Config/Parser/AnnotationParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testTypes(): void
129129
'currentMaster' => ['type' => 'Sith', 'resolve' => "@=service('master_resolver').getMaster(value)"],
130130
'victims' => [
131131
'type' => '[Character]',
132-
'args' => ['jediOnly' => ['type' => 'Boolean', 'description' => 'Only Jedi victims']],
132+
'args' => ['jediOnly' => ['type' => 'Boolean', 'description' => 'Only Jedi victims', 'defaultValue' => false]],
133133
'resolve' => '@=call(value.getVictims, arguments({jediOnly: "Boolean"}, args))',
134134
],
135135
],

tests/Resolver/ResolverFieldTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class ResolverFieldTest extends TestCase
1313
/**
1414
* @dataProvider resolverProvider
1515
*
16-
* @param mixed $source
16+
* @param mixed $source
17+
* @param bool|string|null $expected
1718
*/
18-
public function testDefaultFieldResolveFn(string $fieldName, $source, ?string $expected): void
19+
public function testDefaultFieldResolveFn(string $fieldName, $source, $expected): void
1920
{
2021
$info = $this->getMockBuilder(ResolveInfo::class)->disableOriginalConstructor()->getMock();
2122
$info->fieldName = $fieldName;
@@ -36,6 +37,8 @@ public function resolverProvider(): array
3637
['private_property_with_getter2', $object, Toto::PRIVATE_PROPERTY_WITH_GETTER2_VALUE],
3738
['not_object_or_array', 'String', null],
3839
['name', $object, $object->name],
40+
['enabled', $object, $object->isEnabled()],
41+
['isDisabled', $object, $object->isDisabled()],
3942
];
4043
}
4144
}

tests/Resolver/Toto.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Toto
1717
private string $privatePropertyWithGetter = self::PRIVATE_PROPERTY_WITH_GETTER_VALUE;
1818
private string $private_property_with_getter2 = self::PRIVATE_PROPERTY_WITH_GETTER2_VALUE;
1919
public string $name = 'public';
20+
private bool $enabled = true;
21+
private bool $isDisabled = false;
2022

2123
public function getPrivatePropertyWithGetter(): string
2224
{
@@ -39,4 +41,14 @@ public function resolve(): array
3941
{
4042
return func_get_args();
4143
}
44+
45+
public function isEnabled(): bool
46+
{
47+
return $this->enabled;
48+
}
49+
50+
public function isDisabled(): bool
51+
{
52+
return $this->isDisabled;
53+
}
4254
}

0 commit comments

Comments
 (0)