-
-
Notifications
You must be signed in to change notification settings - Fork 920
Fallback attributes in the @ApiResource annotation #1788
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
dunglas
merged 2 commits into
api-platform:master
from
meyerbaptiste:fallback_attributes_api_resource_annotation
Mar 29, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,44 @@ | |
|
||
namespace ApiPlatform\Core\Annotation; | ||
|
||
use ApiPlatform\Core\Exception\InvalidArgumentException; | ||
use Doctrine\Common\Util\Inflector; | ||
|
||
/** | ||
* ApiResource annotation. | ||
* | ||
* @author Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* @Annotation | ||
* @Target({"CLASS"}) | ||
* @Attributes( | ||
* @Attribute("accessControl", type="string"), | ||
* @Attribute("accessControlMessage", type="string"), | ||
* @Attribute("attributes", type="array"), | ||
* @Attribute("collectionOperations", type="array"), | ||
* @Attribute("denormalizationContext", type="array"), | ||
* @Attribute("description", type="string"), | ||
* @Attribute("fetchPartial", type="bool"), | ||
* @Attribute("forceEager", type="bool"), | ||
* @Attribute("filters", type="string[]"), | ||
* @Attribute("graphql", type="array"), | ||
* @Attribute("iri", type="string"), | ||
* @Attribute("itemOperations", type="array"), | ||
* @Attribute("maximumItemsPerPage", type="int"), | ||
* @Attribute("normalizationContext", type="array"), | ||
* @Attribute("order", type="array"), | ||
* @Attribute("paginationClientEnabled", type="bool"), | ||
* @Attribute("paginationClientItemsPerPage", type="bool"), | ||
* @Attribute("paginationClientPartial", type="bool"), | ||
* @Attribute("paginationEnabled", type="bool"), | ||
* @Attribute("paginationFetchJoinCollection", type="bool"), | ||
* @Attribute("paginationItemsPerPage", type="int"), | ||
* @Attribute("paginationPartial", type="bool"), | ||
* @Attribute("routePrefix", type="string"), | ||
* @Attribute("shortName", type="string"), | ||
* @Attribute("subresourceOperations", type="array"), | ||
* @Attribute("validationGroups", type="mixed") | ||
* ) | ||
*/ | ||
final class ApiResource | ||
{ | ||
|
@@ -62,4 +93,155 @@ final class ApiResource | |
* @var array | ||
*/ | ||
public $attributes = []; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var string | ||
*/ | ||
private $accessControl; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var string | ||
*/ | ||
private $accessControlMessage; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var array | ||
*/ | ||
private $denormalizationContext; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $fetchPartial; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $forceEager; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var string[] | ||
*/ | ||
private $filters; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var int | ||
*/ | ||
private $maximumItemsPerPage; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var array | ||
*/ | ||
private $normalizationContext; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var array | ||
*/ | ||
private $order; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $paginationClientEnabled; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $paginationClientItemsPerPage; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $paginationClientPartial; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $paginationEnabled; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var bool | ||
*/ | ||
private $paginationFetchJoinCollection; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var int | ||
*/ | ||
private $paginationItemsPerPage; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var int | ||
*/ | ||
private $paginationPartial; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
* | ||
* @var string | ||
*/ | ||
private $routePrefix; | ||
|
||
/** | ||
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not having it on the class level since it's on every property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we may introduce other properties for valid reasons later. |
||
* | ||
* @var mixed | ||
*/ | ||
private $validationGroups; | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct(array $values = []) | ||
{ | ||
if (isset($values['attributes'])) { | ||
$this->attributes = $values['attributes']; | ||
unset($values['attributes']); | ||
} | ||
|
||
foreach ($values as $key => $value) { | ||
if (!property_exists($this, $key)) { | ||
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class)); | ||
} | ||
|
||
$property = new \ReflectionProperty($this, $key); | ||
|
||
if ($property->isPublic()) { | ||
$this->$key = $value; | ||
} else { | ||
$this->attributes += [Inflector::tableize($key) => $value]; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR I'm using vim and all I see is noise 😈
(it's friday I'm allowed to rage coz I'm a hater)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear @soyuka,
I encourage you to download a real IDE. Here is the link to PHPStorm: https://www.jetbrains.com/phpstorm/download/.
I hope this could help you to find the truth!
Yours sincerely.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More seriously,
@Attribute
annotations are needed when using a constructor in your annotation class. The noise here are the private properties.