Php – Order include file depending on inherit


Hi there people and greetings from Sweden!

I have a really tricky problem here. I'll try to show exactly what I mean.

I'm building a modulebased CMS, and some modules inherit from a parent module. My problem is that the parent modules need to be included before the "children".

I fetch moduleinfo from a XML file and store it in an array like this:

    [bloggy] => Array
            [module_id] => blog
            [module_name] => Blog
            [module_desc] => Description
            [module_url] =>
            [author] => Dev Name
            [author_url] =>
            [version] => 1.0
            [inherit] => core|twitter
            [path] => /path/to/file
            [dependon] => Array
                    [0] => core
                    [1] => twitter

I've done a explode on inherit and saved it into "dependon" as you see above. The problem now is, how can I sort which order to include the files. Every module inherits from core but if there is another module in the depenon array then the "child" module must be included after.

I hope you understand what I mean?

// Tobias

Best Solution

Look up "topological sort".