Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Revise class loader #481

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ServiceProvider extends ModuleServiceProvider
*/
public function register()
{
parent::register();

$this->registerConsole();
$this->registerMailer();
$this->registerAssetBundles();
Expand Down
2 changes: 2 additions & 0 deletions modules/cms/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ServiceProvider extends ModuleServiceProvider
*/
public function register()
{
parent::register();

$this->registerConsole();
$this->registerTwigParser();
$this->registerAssetBundles();
Expand Down
11 changes: 10 additions & 1 deletion modules/system/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ServiceProvider extends ModuleServiceProvider
*/
public function register()
{
parent::register();

$this->registerSingletons();
$this->registerPrivilegedActions();

Expand All @@ -60,7 +62,14 @@ public function register()
* Register other module providers
*/
foreach (Config::get('cms.loadModules', []) as $module) {
if (strtolower(trim($module)) != 'system') {
$moduleLower = strtolower(trim($module));
$serviceProviderPath = base_path("modules/$moduleLower/ServiceProvider.php");
if (
strtolower(trim($module)) !== 'system'
&& file_exists($serviceProviderPath)
) {
// Load and register the module's ServiceProvider
require_once $serviceProviderPath;
App::register('\\' . $module . '\ServiceProvider');
}
}
Expand Down
6 changes: 5 additions & 1 deletion modules/system/classes/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public function loadPlugin($namespace, $path)
$classObj->disabled = true;
}

// Register the plugin with the autoloader
$pluginNamespace = Str::before(get_class($classObj), '\\Plugin') . '\\';
$this->app->make(ClassLoader::class)->autoloadPackage($pluginNamespace, $path . '/');

$this->plugins[$classId] = $classObj;
$this->pathMap[$classId] = $path;
$this->normalizedMap[strtolower($classId)] = $classId;
Expand Down Expand Up @@ -292,7 +296,7 @@ public function registerPlugin($plugin, $pluginId = null)
foreach ($replaces as $replace) {
$replaceNamespace = $this->getNamespace($replace);

App::make(ClassLoader::class)->addNamespaceAliases([
$this->app->make(ClassLoader::class)->addNamespaceAliases([
// class_alias() expects order to be $real, $alias
$this->getNamespace($pluginId) => $replaceNamespace,
]);
Expand Down
3 changes: 3 additions & 0 deletions modules/system/providers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

// Ensure the System ServiceProvider class is available
require_once __DIR__ . DIRECTORY_SEPARATOR . 'ServiceProvider.php';

return [

/*
Expand Down
4 changes: 0 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@
);

$loader->register();
$loader->addDirectories([
'modules',
'plugins'
]);