/** * Bootstraps all registered modules * */ public function bootstrap() { $paths = \Base::instance()->get('dsc.module.paths'); if (!empty($paths)) { foreach ($paths as $path) { if ($folders = \Dsc\Filesystem\Folder::folders($path)) { foreach ($folders as $folder) { if (file_exists($path . $folder . '/bootstrap.php')) { require_once $path . $folder . '/bootstrap.php'; } } } } } return $this; }
/** * Gets an array of all the registered module types * * @param string $group_items * @return multitype:multitype: NULL |unknown */ public function types($group_items = true) { // Search the registered module folders for the list of modules $paths = \Base::instance()->get('dsc.module.paths'); // TODO cache the results $types = array(); $grouped = array(); foreach ($paths as $path) { if ($folders = \Dsc\Filesystem\Folder::folders($path)) { foreach ($folders as $folder) { if (file_exists($path . $folder . '/module.json')) { // echo $path . $folder . '/module.json'; // die(); $file = $path . $folder . '/module.json'; if ($contents = file_get_contents($file)) { $object = json_decode($contents); if (empty($object->title)) { continue; } if (empty($object->group)) { $object->group = 'Misc'; } if (empty($object->class) || !class_exists($object->class)) { if (!file_exists($path . $folder . '/Module.php')) { continue; } if (!($sniffed = $this->getClass($path . $folder . '/Module.php'))) { continue; } $class = "\\" . $sniffed['class']; if (!empty($sniffed['namespace'])) { $class = $sniffed['namespace'] . $class; } $object->class = $class; } // only one instance of :: can be in the final type string $object->group = str_replace('::', '-', $object->group); $object->title = str_replace('::', '-', $object->title); // set the type $object->type = strtolower($object->group . "." . $object->title) . "::" . $object->class; if (empty($grouped[$object->group])) { $grouped[$object->group] = array(); } $grouped[$object->group][] = $object; $types[] = $object; } } } } } // sort the results, first by group, then by title if ($group_items) { ksort($grouped); foreach ($grouped as $key => $type) { $grouped[$key] = \Dsc\ArrayHelper::sortObjects($grouped[$key], 'title'); } return $grouped; } $types = \Dsc\ArrayHelper::sortObjects($types, 'type'); return $types; }