Skip to content

Commit ae79ac8

Browse files
committed
Fix BC-break when using short-syntax notation for access_control
1 parent 115cf92 commit ae79ac8

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
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/Fixtures/TestBundle/Document/LegacySecuredDummy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
* @author Vincent Chalamon <[email protected]>
2424
*
2525
* @ApiResource(
26-
* attributes={"access_control"="is_granted('ROLE_USER')"},
26+
* accessControl="is_granted('ROLE_USER')",
27+
* accessControlMessage="Nope!",
2728
* collectionOperations={
2829
* "get",
2930
* "post"={"access_control"="is_granted('ROLE_ADMIN')"}

tests/Fixtures/TestBundle/Entity/LegacySecuredDummy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
* @author Vincent Chalamon <[email protected]>
2424
*
2525
* @ApiResource(
26-
* attributes={"access_control"="is_granted('ROLE_USER')"},
26+
* accessControl="is_granted('ROLE_USER')",
27+
* accessControlMessage="Nope!",
2728
* collectionOperations={
2829
* "get",
2930
* "post"={"access_control"="is_granted('ROLE_ADMIN')"}

0 commit comments

Comments
 (0)