Skip to content

Commit 9a6853f

Browse files
authored
Merge pull request #3113 from antograssiot/security-bc-break
Fix BC-break when using short-syntax notation for access_control
2 parents bc2a8f6 + 3485028 commit 9a6853f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Annotation/AttributesHydratorTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ private function hydrateAttributes(array $values): void
4949
unset($values['attributes']);
5050
}
5151

52+
if (\array_key_exists('accessControl', $values)) {
53+
$values['security'] = $values['accessControl'];
54+
@trigger_error('Attribute "accessControl" is deprecated in annotation since API Platform 2.5, prefer using "security" attribute instead', E_USER_DEPRECATED);
55+
unset($values['accessControl']);
56+
}
57+
if (\array_key_exists('accessControlMessage', $values)) {
58+
$values['securityMessage'] = $values['accessControlMessage'];
59+
@trigger_error('Attribute "accessControlMessage" is deprecated in annotation since API Platform 2.5, prefer using "securityMessage" attribute instead', E_USER_DEPRECATED);
60+
unset($values['accessControlMessage']);
61+
}
62+
5263
foreach ($values as $key => $value) {
5364
$key = (string) $key;
5465
if (!property_exists($this, $key)) {

tests/Annotation/ApiResourceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,17 @@ public function testConstructWithInvalidAttribute()
143143
'invalidAttribute' => 'exception',
144144
]);
145145
}
146+
147+
/**
148+
* @group legacy
149+
* @expectedDeprecation Attribute "accessControl" is deprecated in annotation since API Platform 2.5, prefer using "security" attribute instead
150+
* @expectedDeprecation Attribute "accessControlMessage" is deprecated in annotation since API Platform 2.5, prefer using "securityMessage" attribute instead
151+
*/
152+
public function testWithDeprecatedAttributes()
153+
{
154+
new ApiResource([
155+
'accessControl' => "is_granted('ROLE_USER')",
156+
'accessControlMessage' => 'Nope!',
157+
]);
158+
}
146159
}

0 commit comments

Comments
 (0)