Skip to content
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

Make ApiResource shorter #5076

Closed
tourze opened this issue Oct 20, 2022 · 3 comments
Closed

Make ApiResource shorter #5076

tourze opened this issue Oct 20, 2022 · 3 comments

Comments

@tourze
Copy link

tourze commented Oct 20, 2022

Sometime we need to write a long code like :

#[ApiResource(
    routePrefix: '/live-chat',
    normalizationContext: ['groups' => ['restful_read']],
    denormalizationContext: ['groups' => ['restful_write']],
    openapiContext: ['tags' => ['LiveChat']],
    order: ['id' => 'DESC'],
    security: 'is_granted("ROLE_OPERATOR")'
)]

It is too long for person to read.
Can we just create a new Attribute class, class RestfulApi extends ApiResource, and move some normal logic into consturctor?
Then we just add code like this:

#[RestfulApi(
    routePrefix: '/live-chat',
)]

Related code:

if ($reflectionClass->getAttributes(ApiResource::class)) {

@dunglas
Copy link
Member

dunglas commented Oct 20, 2022

Indeed, the code should be if ($reflectionClass->getAttributes(ApiResource::class, \ReflectionAttribute::IS_INSTANCEOF)) {.

@yobrx
Copy link
Contributor

yobrx commented Nov 9, 2022

@dunglas #5175

My first PR on Api Platform 🙏

yobrx pushed a commit to yobrx/api-platform-core that referenced this issue Nov 9, 2022
yobrx pushed a commit to yobrx/api-platform-core that referenced this issue Nov 9, 2022
yobrx pushed a commit to yobrx/api-platform-core that referenced this issue Nov 10, 2022
soyuka added a commit that referenced this issue Nov 10, 2022
@yobrx
Copy link
Contributor

yobrx commented Nov 16, 2022

It's fixed on 3.0.4 last upgrade

@dunglas dunglas closed this as completed Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants