Skip to content

Fix BC-break when using short-syntax notation for access_control #3113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Annotation/AttributesHydratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ private function hydrateAttributes(array $values): void
unset($values['attributes']);
}

if (\array_key_exists('accessControl', $values)) {
$values['security'] = $values['accessControl'];
@trigger_error('Attribute "accessControl" is deprecated in annotation since API Platform 2.5, prefer using "security" attribute instead', E_USER_DEPRECATED);
unset($values['accessControl']);
}
if (\array_key_exists('accessControlMessage', $values)) {
$values['securityMessage'] = $values['accessControlMessage'];
@trigger_error('Attribute "accessControlMessage" is deprecated in annotation since API Platform 2.5, prefer using "securityMessage" attribute instead', E_USER_DEPRECATED);
unset($values['accessControlMessage']);
}

foreach ($values as $key => $value) {
$key = (string) $key;
if (!property_exists($this, $key)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Annotation/ApiResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,17 @@ public function testConstructWithInvalidAttribute()
'invalidAttribute' => 'exception',
]);
}

/**
* @group legacy
* @expectedDeprecation Attribute "accessControl" is deprecated in annotation since API Platform 2.5, prefer using "security" attribute instead
* @expectedDeprecation Attribute "accessControlMessage" is deprecated in annotation since API Platform 2.5, prefer using "securityMessage" attribute instead
*/
public function testWithDeprecatedAttributes()
{
new ApiResource([
'accessControl' => "is_granted('ROLE_USER')",
'accessControlMessage' => 'Nope!',
]);
}
}