Skip to content

Allow use attribute instead of annotation #117

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 16 commits into from
Nov 4, 2021

Conversation

ggg-mzkr
Copy link

@ggg-mzkr ggg-mzkr commented Sep 9, 2021

Allow use attribute instead of annotation.

Implementation design

  1. Separate the existingAnnotationScanner into the base scanner and annotation-dependent parts as ScanStrategy. And check pass the existing tests.
  2. Create anAttributeScanStrategy and test that the scan results are the same as the AnnotationScanStrategy.
  3. Make AnnotationsServiceProvider to allow to switch strategies.

ex)

Annotation

 /**
   * @Get("login")
   * @Middleware("guest")
   */
  public function login()
  {
    return view('index');
  }

Attribute

  #[Get(path: 'login')]
  #[Middleware(name: 'guest')]
  public function login()
  {
    return view('index');
  }

If use attribute, set $useAttribute totrue inAnnotationsServiceProvider.php;

<?php namespace App\Providers;

use Collective\Annotations\AnnotationsServiceProvider as ServiceProvider;

class AnnotationsServiceProvider extends ServiceProvider {

.....
.....

    /**
     * Determines whether to use attributes for scanning.
     *
     * @var bool
     */
    protected $useAttribute = false;

.....
.....
}

@ggg-mzkr ggg-mzkr changed the title Feature/attribute Allow use attribute instead of annotation Sep 9, 2021
@ggg-mzkr ggg-mzkr marked this pull request as ready for review September 11, 2021 15:42
@ggg-mzkr
Copy link
Author

I Organized the commit history from the previous PR.

#116

@loonytoons
Copy link
Collaborator

Thanks @ggg-mzkr, lots of tidy up stuff here! And nice one implementing the php 8 specificity for the attributes.

One question, for someone to migrate from annotations to attributes, is it expected that they'll need to add the use statements for the various attribute classes being used? It doesn't seem obvious from the readme that these would also need to be added. It'll only trip up people migrating, and only because they'll be used to not needing to include them due to the autoloading done in the background. Not saying ones right or wrong, just noting the difference.

@szeber would you mind taking a look at this, seeing as you looked at the previous iteration?

@loonytoons
Copy link
Collaborator

@ggg-mzkr thanks for your patience. I was hoping to get a second pair of eyes across this, but it's proving tricky. I'll get this sorted this week though!

@loonytoons
Copy link
Collaborator

Looks like travis ci has finally been disconnected, and I don't have the perms to change how the tests run. So just noting that I've run them all manually for php 7.3, 7.4 and 8.0

@loonytoons loonytoons merged commit 5d7215f into LaravelCollective:8.0 Nov 4, 2021
@loonytoons
Copy link
Collaborator

@ggg-mzkr I finally got there! Thanks for your patience, and thanks so much for your contribution! 🙌

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

Successfully merging this pull request may close these issues.

2 participants