-
Notifications
You must be signed in to change notification settings - Fork 9
Weawing doesn't support annotated targets with use statements #6
Comments
The "was never imported" exception often occurs, when you don't have an autoloader for annotations. Try requiring the annotation class manually in |
You're missing the point. The AnnotationReader can't get the annotation from the compiled PHP file (in which the adviced method with this annotation is) because there is no use statement for the annotation which is present in the original file. If you open the compiled PHP file, there should be a use statement for this annotation as it was in the original file. That's causing the problem. PS: requiring the annotation in bootstrap didn't help. There is no problem in loading the annotation class, but reading the annotation since the use statement is missing in the compiled file. |
Why is the annotation in the compiled file? The phpGenerator did copied it from the original method, did it? Oh fuck :) |
To clear things out: original file:
the compiled file
AnnotationReader can't read the annotation because it is in a namespace which is not imported in the compiled file. |
Yes. I don't know if Doctrine annotations get inherited from super classes, if yes, that would solve the problem. If not, the compiled file needs the same use statement as in original file. By the way, it would be convenient to have a getter in the joinpoint object returning the object of the annotation defined in the pointcut's *AnnotatedWith. |
The problem is here... https://github.com/nette/nette/blob/master/Nette/PhpGenerator/Method.php#L91 What do you think would be better solution? expand the annotations to FQN? copying the use statements might be more problematic... |
I agree #7 :) |
Awesome! 👍 As for a solution of this problem, it's up to you what suits you best. Expading to FQN is clean and non-problematic way to go I think. I can see some problems in copying the use statements too :) |
Hi. I solved the alias to FQN expanding and I'm using it without problems. https://github.com/milo/alias-expander Feel free to get what you want, if you want. |
@milo Good to know, but I'm probably gonna stick to Doctrine tools, because I'm already using annotations. |
@hosiplan I see, didn't know that. And as I see, the implementation is the same across different libraries. |
I want to access the annotation in the aspect when using methodAnnotatedWith with the annotation in a namespace. The adviced method file uses a use statement importing the annotation, but the use statement is not generated in the PHP file when compiling.
Accessing the annotation on the target results in an exception:
The usecase is to get the information stored in the annotation and process it in the aspect using the AnnotationReader (since Nette annotation doesn't support use statements imports of annotation classes), like this:
Or is there a way to get the annotation object defined by the pointcut?
The text was updated successfully, but these errors were encountered: