/** * 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; }
/** * Determines if any variants exist for the provided view file * * @param unknown $view * @param string $site * @return multitype: */ public function variants($view, $site = 'site') { $return = array(); $view = str_replace(".php", "", $view); $view = str_replace("::", "/", $view); $view = str_replace("\\", "/", $view); $pieces = explode('/', $view); $themes = (array) \Base::instance()->get('dsc.themes.' . $site); foreach ($themes as $theme => $theme_path) { // an overrides folder exists in this theme, let's check for the presence of an override for the requested view file $dir = \Dsc\Filesystem\Path::clean($theme_path . "Overrides/"); if ($dir = \Dsc\Filesystem\Path::real($dir)) { $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view); if ($path = \Dsc\Filesystem\Path::real($path)) { $files = \Dsc\Filesystem\Folder::files($path); if ($files) { $return = \Dsc\ArrayHelper::set($return, $theme, $files); } } } } // now find the requested file's original app, and its corresponding view files $app = $pieces[0]; $apps = (array) \Base::instance()->get('dsc.apps'); if (array_key_exists($app, $apps)) { $dir = $apps[$app]; unset($pieces[0]); $view = implode('/', $pieces); if ($dir = \Dsc\Filesystem\Path::real($dir)) { $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view); if ($path = \Dsc\Filesystem\Path::real($path)) { $files = \Dsc\Filesystem\Folder::files($path); if ($files) { $return = \Dsc\ArrayHelper::set($return, $app, $files); } } } } return $return; }
/** * 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; }