Skip to content

Commit 1ece8c1

Browse files
authored
Merge pull request #297 from phpeek/fix-yaml-expression-attributes
Expressions in attributes are not supported when using YAML.
2 parents e9777dd + a8212a0 commit 1ece8c1

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

src/Configuration/Metadata/Driver/YamlDriver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function loadMetadataFromFile(\ReflectionClass $class, string $file):
6767
$relation['rel'],
6868
$this->createHref($relation),
6969
$this->createEmbedded($relation),
70-
$relation['attributes'] ?? [],
70+
isset($relation['attributes']) ? $this->checkExpressionArray($relation['attributes']): [],
7171
$this->createExclusion($relation)
7272
));
7373
}

tests/Hateoas/Tests/Configuration/Metadata/Driver/AbstractDriverTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ public function testUser()
134134
$this->assertSame(43, $relation->getEmbedded()->getExclusion()->getMaxDepth());
135135
$this->assertSame('bar', $relation->getEmbedded()->getExclusion()->getExcludeIf());
136136

137+
$relation = $relations[$i++];
138+
$this->assertSame('attribute_with_expression', $relation->getName());
139+
$this->assertEquals(['baz' => $exp->parse('object.getId()', ['object'])], $relation->getAttributes());
140+
137141
/** @var RelationProvider[] $relations */
138142
$relations = $classMetadata->getRelations();
139143
$this->assertInternalType('array', $relations);
140-
$this->assertCount(7, $relations);
144+
$this->assertCount(8, $relations);
141145

142146
// $relation = current($relations);
143147
// $this->assertSame('getRelations', $relation->getName());

tests/Hateoas/Tests/Fixtures/User.php

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* )
3737
* )
3838
* )
39+
* @Hateoas\Relation("attribute_with_expression", href = "baz", attributes = {"baz" = "expr(object.getId())"})
3940
* @Hateoas\RelationProvider("Hateoas\Tests\Fixtures\User::getRelations")
4041
*/
4142
class User

tests/Hateoas/Tests/Fixtures/config/User.xml

+5
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@
4848
</h:embedded>
4949
<h:exclusion groups="group1, group2" since-version="1" until-version="2.2" max-depth="42" exclude-if="foo"/>
5050
</h:relation>
51+
52+
<h:relation rel="attribute_with_expression">
53+
<h:href uri="baz"/>
54+
<h:attribute name="baz" value="expr(object.getId())"/>
55+
</h:relation>
5156
</class>
5257
</serializer>

tests/Hateoas/Tests/Fixtures/config/User.yml

+6
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,10 @@ Hateoas\Tests\Fixtures\User:
5050
until_version: 2.3
5151
max_depth: 43
5252
exclude_if: bar
53+
-
54+
rel: attribute_with_expression
55+
href: baz
56+
attributes:
57+
baz: expr(object.getId())
58+
5359
relation_providers: [ Hateoas\Tests\Fixtures\User::getRelations ]

0 commit comments

Comments
 (0)