Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Iterating through classes with an extension


Go to End


3 Posts   1132 Views

Avatar
g4b0

Community Member, 14 Posts

28 February 2013 at 5:24am

How can I get a list of all classes extended by a DataExtension?

g4b0

Avatar
Willr

Forum Moderator, 5523 Posts

28 February 2013 at 8:54pm

Going that way might be tricky Object::has_extension($class, $extension) would be one piece of API that would help, though you would need to get a list of classes though. ClassInfo::subclassesFor('DataObject') will give you an array of dataobject classes so you could use both

foreach(ClassInfo::subclassesFor('DataObject') as $className) {
if(Object::has_extension($className, 'YourExtension')) {
// class has extension
}
}

Avatar
g4b0

Community Member, 14 Posts

28 February 2013 at 11:23pm

I solved with:

foreach(ClassInfo::subclassesFor('DataObject') as $class ) {
if (singleton($class)->hasExtension("ZkTwitterExtension")) {

Do you think your version is more performat, or they're the same?