public function boot() { $this->manager = PluginManager::instance(); // Get paths we need $theme = Theme::getActiveTheme(); $themePath = $theme->getPath(); $pluginPath = dirname(__FILE__); $providerPath = $themePath . '/Plugin.php'; // Load your theme's Theme.php file as a service provider if (File::exists($providerPath)) { // Use reflection to find out info about Plugin.php $info = new Classes\ClassInfo($providerPath); if (ltrim($info->extends, '\\') == "NSRosenqvist\\ThemesPlus\\Classes\\ThemesPlusBase") { // Activate the theme plugin $plugin = $this->manager->loadPlugin($info->namespace, $themePath); $identifier = $this->manager->getIdentifier($plugin); $definitionsFile = $pluginPath . '/composer/definitions.php'; $this->manager->registerPlugin($plugin); $this->manager->bootPlugin($plugin); // See if we need to generate a new composer psr-4 definitions file if (Settings::get('definitions_generated_for') != $identifier || !File::exists($definitionsFile)) { File::put($definitionsFile, $this->makeDefinitionFile($info->namespace, $themePath)); Settings::set('definitions_generated_for', $identifier); } // Add theme to autoload through our definitions file ComposerManager::instance()->autoload($pluginPath); } } // dd(\Composer\Autoload\ClassLoader::findFile('MyCompany\\MyTheme\\Classes\\Radical')); // dd(ComposerManager::instance()); }
/** * Registers a single plugin object. * @param PluginBase $plugin * @param string $pluginId * @return void */ public function registerPlugin($plugin, $pluginId = null) { if (!$pluginId) { $pluginId = $this->getIdentifier($plugin); } if (!$plugin || $plugin->disabled) { return; } $pluginPath = $this->getPluginPath($plugin); $pluginNamespace = strtolower($pluginId); /* * Register plugin class autoloaders */ $autoloadPath = $pluginPath . '/vendor/autoload.php'; if (File::isFile($autoloadPath)) { ComposerManager::instance()->autoload($pluginPath . '/vendor'); } if (!self::$noInit || $plugin->elevated) { $plugin->register(); } /* * Register language namespaces */ $langPath = $pluginPath . '/lang'; if (File::isDirectory($langPath)) { Lang::addNamespace($pluginNamespace, $langPath); } /* * Register configuration path */ $configPath = $pluginPath . '/config'; if (File::isDirectory($configPath)) { Config::package($pluginNamespace, $configPath, $pluginNamespace); } /* * Register views path */ $viewsPath = $pluginPath . '/views'; if (File::isDirectory($viewsPath)) { View::addNamespace($pluginNamespace, $viewsPath); } /* * Add init, if available */ $initFile = $pluginPath . '/init.php'; if (!self::$noInit && File::exists($initFile)) { require $initFile; } /* * Add routes, if available */ $routesFile = $pluginPath . '/routes.php'; if (File::exists($routesFile)) { require $routesFile; } }