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

Refactor doctrine/annotation from dynamic to own static-reflection parser #5974

Merged
merged 9 commits into from
Apr 4, 2021

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Mar 24, 2021

Follow up to making use of static reflection feature #5665

Now the Doctrine annotations need classes to be autoloaded, because they use https://github.com/doctrine/annotations

use Symfony\Component\Routing\Annotation\Route;

final class SomeController
{
    /**
     * @Route(path="/some_path", name="some_name")
     */
    public function some()
    {
    }
}

So now the real static reflection can be used only somewhere. That's source for these bugs #5517, #5628, #5725


This PR replaces doctrine/annotations package with custom parser that mimics its behavior, but uses phpstan/phpdoc-parser with static reflection 👍


That means, the doctrine annotation classes don't have to be autoloaded anymore. It also simplified the doc node printing with much less code.

image

@TomasVotruba TomasVotruba force-pushed the annotation-static branch 2 times, most recently from 10158de to 3bd7d5c Compare March 28, 2021 20:09
@TomasVotruba TomasVotruba changed the title annotation static Refactor doctrine/annotation from dynamic to own static-reflection parser Mar 28, 2021
@TomasVotruba TomasVotruba force-pushed the annotation-static branch 8 times, most recently from c689ffa to e210efc Compare March 29, 2021 22:33
@TomasVotruba TomasVotruba force-pushed the annotation-static branch 8 times, most recently from 9028ddf to 2886800 Compare March 30, 2021 15:33
@TomasVotruba TomasVotruba force-pushed the annotation-static branch 7 times, most recently from 0d427a9 to a830ec2 Compare April 1, 2021 08:16
@TomasVotruba TomasVotruba force-pushed the annotation-static branch 7 times, most recently from 7034cb6 to 2ee8894 Compare April 3, 2021 22:47
@TomasVotruba TomasVotruba force-pushed the annotation-static branch 2 times, most recently from b748d51 to faa82d0 Compare April 3, 2021 23:13
@TomasVotruba
Copy link
Member Author

This is big jump for annotation format preserving #4334

Before, to parse class-based annotations the https://github.com/doctrine/annotations was needed:

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Product
{
}

That required the Doctrine\ORM\Mapping\Entity class to be present and autoloaded. That kind-of kills the advantage of static reflection added in Rector 0.10 for annotations.

Further more, this approach required every such annotation to have own php doc node class and factory to make it. In total, Rector contained ~50 such classes + factories.


The #5974 PR solves this using https://github.com/phpstan/phpdoc-parser and copying the doctrine/annotation behavior 1:1 without autoloading used classes and constants.

Now, Rector is now using static for annotations making it more accessible to wide PHP comunity 🤗 👍

@TomasVotruba
Copy link
Member Author

Closes #5454

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.

1 participant