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.

General Questions

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

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

Iterating through classes with an extension


Reply

3 Posts   270 Views

Avatar
g4b0

28 February 2013 at 5:24am Community Member, 6 Posts

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

g4b0

Avatar
Willr

28 February 2013 at 8:54pm Forum Moderator, 5511 Posts

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

28 February 2013 at 11:23pm Community Member, 6 Posts

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?