private static function runModule($name) { $name = RequirePHP::parseAlias($name); if (!isset(RequirePHP::$modules[$name])) { return false; } if (key_exists('return', RequirePHP::$modules[$name])) { // If we've already loaded this module, we're golden. return true; } RequirePHP::$depth++; // Keep track of how deep we're going. if (RequirePHP::$depth > REQUIREPHP_MAX_DEPTH) { RequirePHP::$depth = 0; throw new RequireTooDeepException("Proceeded too deeply down the rabbit hole. Max require depth is " . REQUIREPHP_MAX_DEPTH . "."); } // Load the required modules. $arguments = array(); if (!empty(RequirePHP::$modules[$name]['requires'])) { foreach (RequirePHP::$modules[$name]['requires'] as $require) { $require = RequirePHP::parseAlias($require); if (!RequirePHP::runModule($require)) { RequirePHP::$depth--; return false; } $arguments[] = RequirePHP::$modules[$require]['return']; // Add this return value to the arguments. We'll pass it to the callback. } } if (is_callable(RequirePHP::$modules[$name]['function'])) { RequirePHP::$modules[$name]['return'] = call_user_func_array(RequirePHP::$modules[$name]['function'], $arguments); } else { RequirePHP::$depth--; return false; } RequirePHP::$depth--; return true; }