DDC-1247: Implement AnnotationDriver::addExcludePath #1573

Closed
opened 2026-01-22 13:18:34 +01:00 by admin · 8 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 4, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user hosiplan:

Hi,
I've been having issues with AnnotationDriver crawling in my directories and loading files.
I have a few classes that require specific libraries loaded, and I don't want the AnnotationDriver to load them.

For example, I have my descendant of PHPUnit_Framework_TestCase in libs and the driver just dies, because PHPUnit is not loaded, and I don't want to load it, to be able to finish the process.

Solution would be add method AnnotationDriver::addExcludePath, whose name speaks for itself :)

Temporarily, I had to extend the AnnotationDriver and overload the crawling process, which is realy annoing, because I had to copy the whole method with all its exceptions and I would have to maintain it, till this will be in Doctrine. Can be viewed here https://github.com/Kdyby/Framework/blob/master/libs/Kdyby/Doctrine/Mapping/Driver/AnnotationDriver.php

Thanks
Filip

Originally created by @doctrinebot on GitHub (Jul 4, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user hosiplan: Hi, I've been having issues with AnnotationDriver crawling in my directories and loading files. I have a few classes that require specific libraries loaded, and I don't want the AnnotationDriver to load them. For example, I have my descendant of PHPUnit_Framework_TestCase in libs and the driver just dies, because PHPUnit is not loaded, and I don't want to load it, to be able to finish the process. Solution would be add method `AnnotationDriver::addExcludePath`, whose name speaks for itself :) Temporarily, I had to extend the AnnotationDriver and overload the crawling process, which is realy annoing, because I had to copy the whole method with all its exceptions and I would have to maintain it, till this will be in Doctrine. Can be viewed here https://github.com/Kdyby/Framework/blob/master/libs/Kdyby/Doctrine/Mapping/Driver/AnnotationDriver.php Thanks Filip
admin added the New Feature label 2026-01-22 13:18:34 +01:00
admin closed this issue 2026-01-22 13:18:35 +01:00
Author
Owner

@doctrinebot commented on GitHub (Apr 20, 2012):

Comment created by juzna:

This behavior really messes with my projects, as it automatically loads all php files. Not just those with classes, but also simple scripts, which can do horrible stuff (e.g. I've got scripts to make changes in the source code!)

Annotations should be read without executing the scripts, e.g. by TokenReflection library: https://github.com/Andrewsville/PHP-Token-Reflection

@doctrinebot commented on GitHub (Apr 20, 2012): Comment created by juzna: This behavior really messes with my projects, as it automatically loads all php files. Not just those with classes, but also simple scripts, which can do horrible stuff (e.g. I've got scripts to make changes in the source code!) Annotations should be read without executing the scripts, e.g. by TokenReflection library: https://github.com/Andrewsville/PHP-Token-Reflection
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2012):

Comment created by vrtak-cz:

pull https://github.com/doctrine/common/pull/176

@doctrinebot commented on GitHub (Aug 27, 2012): Comment created by vrtak-cz: pull https://github.com/doctrine/common/pull/176
Author
Owner

@doctrinebot commented on GitHub (Sep 19, 2012):

Comment created by stof:

@Jan Tokenizing the file was the way annotations were handled in 2.0. Doctrine 2.1 switched to using Reflection to read annotation because it is faster.

@Filip I'm wondering why you would have PHPUnit testcases in a path storing entities.

@doctrinebot commented on GitHub (Sep 19, 2012): Comment created by stof: @Jan Tokenizing the file was the way annotations were handled in 2.0. Doctrine 2.1 switched to using Reflection to read annotation because it is faster. @Filip I'm wondering why you would have PHPUnit testcases in a path storing entities.
Author
Owner

@doctrinebot commented on GitHub (Sep 19, 2012):

Comment created by hosiplan:

@stof

Tokenizing the file was the way annotations were handled in 2.0. Doctrine 2.1 switched to using Reflection to read annotation because it is faster.

And it is obviousely the wrong one. There is no argument, that could beat the fact, that the result can and should be cached, as it does already. Correct behaviour is much more valuable than few miliseconds on first run.

I'm wondering why you would have PHPUnit testcases in a path storing entities.

I don't. They are base classes for the actual tests. I agree they might (or should) be somewhere else, but the fact, that they should not be executed, when readed, stays.

@doctrinebot commented on GitHub (Sep 19, 2012): Comment created by hosiplan: @stof > Tokenizing the file was the way annotations were handled in 2.0. Doctrine 2.1 switched to using Reflection to read annotation because it is faster. And it is obviousely the wrong one. There is no argument, that could beat the fact, that the result can and should be cached, as it does already. Correct behaviour is much more valuable than few miliseconds on first run. > I'm wondering why you would have PHPUnit testcases in a path storing entities. I don't. They are base classes for the actual tests. I agree they might (or should) be somewhere else, but the fact, that they should not be executed, when readed, stays.
Author
Owner

@doctrinebot commented on GitHub (Sep 19, 2012):

Comment created by stof:

@Filip The AnnotationReader is not loading any file. It simply expects a ReflectionClass.
And for the performances, we are talking about running several times faster here (I don't have the benchmark results anymore but you could search in the merged PRs on Doctrine Common)

The ORM AnnotationDriver expects a path in which it should look for annotated classes, to be able to implement getAllClasses() (as it cannot expect all classes to be already loaded). And btw, the behavior was the same in 2.0 when the reader was using tokenization.

@doctrinebot commented on GitHub (Sep 19, 2012): Comment created by stof: @Filip The AnnotationReader is not loading any file. It simply expects a ReflectionClass. And for the performances, we are talking about running several times faster here (I don't have the benchmark results anymore but you could search in the merged PRs on Doctrine Common) The ORM AnnotationDriver expects a path in which it should look for annotated classes, to be able to implement getAllClasses() (as it cannot expect all classes to be already loaded). And btw, the behavior was the same in 2.0 when the reader was using tokenization.
Author
Owner

@doctrinebot commented on GitHub (Feb 3, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-176] was closed:
https://github.com/doctrine/common/pull/176

@doctrinebot commented on GitHub (Feb 3, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-176] was closed: https://github.com/doctrine/common/pull/176
Author
Owner

@doctrinebot commented on GitHub (Feb 4, 2014):

Comment created by @ocramius:

Merged: d0c1a60854

@doctrinebot commented on GitHub (Feb 4, 2014): Comment created by @ocramius: Merged: https://github.com/doctrine/common/commit/d0c1a60854c69089278e0db13235563748f2fa26
Author
Owner

@doctrinebot commented on GitHub (Feb 4, 2014):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 4, 2014): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1573