/** * * @param string $moduleName * @param array $defaults * @return Ac_Module */ public static function factory($moduleName, $defaults = array()) { $path = $moduleName == "app" ? AC_PATH_APP : AC_PATH_MODULES . $moduleName . _DS; if (!is_dir($path)) { Ac::log()->fatal($path, "Module not found at given path", __FILE__, __LINE__); } $moduleClass = 'Module_' . ucfirst($moduleName); $classFound = false; //Try to load the moduleClass using the HMVC power if (Ac::loader()->autoload($moduleClass)) { $classFound = true; } else { //Lookup under the module /classes dir $moduleFile = $path . 'classes' . _DS . 'module' . _DS . strtolower($moduleName) . '.php'; if (is_readable($moduleFile)) { include_once $moduleFile; if (class_exists($moduleClass, false)) { $classFound = true; } } } if ($classFound) { return new $moduleClass($defaults); } else { return new Ac_Module($moduleName, $defaults); } }
</table> </div> <div class="span6"> <h2>Environment</h2> <table class="table table-striped table-condensed"> <tr> <th>current module</th> <td><?php echo App::module()->name(); ?> </td> </tr> <tr> <th>loaded modules</th> <td><?php echo implode(", ", array_keys(Ac::loader()->getModules())); ?> </td> </tr> <?php $vars = Ac::router()->toArray(); foreach ($vars as $i => $v) { if ($i == "controllerInstance") { continue; } if ($i == "resource") { $v = '[' . implode(",", $v) . ']'; } if ($i == "params") { $v = '[' . implode(",", $v) . ']'; }
/** * Get / Set the router * @param Ac_Loader $loader The new loader * @return Ac_Loader */ public static function &loader(Ac_Loader &$loader = null) { if (!empty($loader)) { self::$loader = $loader; } return self::$loader; }
/** * Autoloads a class and changes the current module * if the class belongs to a module * * @param string $class_name * @return boolean */ protected function loadClass($class_name) { $result = Ac::loader()->autoload($class_name); // class loaded from /system if ($result === true) { return true; } elseif ($result instanceof Ac_Module) { // class loaded from /app or /modules/* Ac::loader()->setActiveModule($result->name(), false); return true; } // class not found return false; }