From 15cf181f112c296d90a9f6fc885a285f10d42037 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 23 Jun 2016 17:00:00 +0200 Subject: [module] Add getDependencies() to recursively get all deps of a module --- inc/module.inc.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'inc/module.inc.php') diff --git a/inc/module.inc.php b/inc/module.inc.php index 336d0a5b..a7a767ef 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -182,6 +182,28 @@ class Module } } } + + public function getDependencies() + { + $deps = array(); + $this->getDepsInternal($deps); + return array_keys($deps); + } + + private function getDepsInternal(&$deps) + { + if (!is_array($this->dependencies)) + return array(); + foreach ($this->dependencies as $dep) { + if (isset($deps[$dep])) // Handle cyclic dependencies + continue; + $deps[$dep] = true; + $mod = self::get($dep); + if ($mod === false) + continue; + $mod->getDepsInternal($deps); + } + } public function getIdentifier() { -- cgit v1.2.3-55-g7522