I have several classes with a certain attribute, how can I get all the classes that have it?
#[Attribute]
class MyAttribute {}
#[MyAttribute]
class Foo
{
}
#[MyAttribute]
class Bar
{
}
Have some ideas?
I have several classes with a certain attribute, how can I get all the classes that have it?
#[Attribute]
class MyAttribute {}
#[MyAttribute]
class Foo
{
}
#[MyAttribute]
class Bar
{
}
Have some ideas?
Copyright © 2021 Jogjafile Inc.
You can make with php Reflection, or just by a bash command
grep '\#\[YourAttributeName\]' -A1 -r projectfolder | grep Class | awk '{print $2}'Here is the php way.
First use the
get_declared_classes()to get all declared class. Then you can make theReflectionClasson each class. Then check if theReflectionClasshas the attribute.