0

Lets say I have file myplugin.php

How can I get a list of all the classes that implement a certain interface?

Real simple

y2k
  • 65,388
  • 27
  • 61
  • 86

1 Answers1

2
  1. Load all files (you could have a plugins directory for example)
  2. Iterate through the get_declared_classes() result
  3. Check for the implementation: class_implements()
Peter Kiss
  • 9,309
  • 2
  • 23
  • 38
  • 1
    or grep -r "implements $classname" * :) – Orangepill Jun 10 '13 at 05:59
  • Nice solution! :) But it has a hard dependency on grep and sometimes a concrate implementation derives from an abstract one so we would have to maintain class hierarchy. – Peter Kiss Jun 10 '13 at 06:00
  • Just abstract out a file system searcher which has grep as it's sole concrete implementation then inject it into your dependency figure outer. That should appease the IoC gods – Orangepill Jun 10 '13 at 06:02