0

I am sorry if this question was asked and answered elsewhere --- I do not know how to phrase my question in a proper way. Any hint will help.

I have "a bunch" of PHP-classes organised by PSR-4 principles (folders = class names, subfolder = sub-namespace-paths). There are sub-namespaces like accounting, printing, production, etc. Each of these subnamespaces might have an unknown amount of classes.

There is an interface in mynamespace\core\interfaces\types. And there are classes that implement this interface in for example mynamespace\core\something.php and mynamespace\core\subnamespace\somethingelse.php and mynamespace\accounting\othertypes.php, etc... and so on...

Is there a "proper" way to "know" all classes in this mynamespace implementing mynamespace\core\interfaces\types and running automatically a sub-method of these classes?

The specific user case here might be a group of "options" that are encapsulated in classes or "menu-items" in classes that can be "collected" and then initialise themselves somehow.

Update: Is there a way to use Reflection-classes on a namespace to evaluate this information maybe?

Patrick
  • 691
  • 8
  • 30
  • Sounds like something you could do with annotations and a DIC compiler pass, which would be better than scraping your classes. – Jared Farrish Nov 28 '22 at 15:42

1 Answers1

1

you are probably looking for this haydenpierce/class-finder

check if this answer will be helpful for you because from what I understood the thread both problems look identical and only differ in the implementation How to get all class names inside a particular namespace?

  • 1
    I actually landed yesterday on [NastuzziSamy/reflection-namespace](https://github.com/NastuzziSamy/reflection-namespace), which does the same as haydenpierce/class-finder. I will be testing both of them. – Patrick Nov 29 '22 at 12:04