1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 02:31:17 +02:00

Move logic to Extension class

The gathering and execution of extenders can actually be done here
in the `Extension` class. This way, the `ExtensionManager` only
deals with the question of which extensions are enabled, the
`Extension` class actually extends the core application, and the
service provider simply calls a method, without having to know
about internals.
This commit is contained in:
Franz Liedke
2018-03-04 01:16:50 +01:00
parent 2967b5d106
commit db7cd71f19
3 changed files with 32 additions and 29 deletions

View File

@@ -20,6 +20,7 @@ use Flarum\Extension\Event\Enabling;
use Flarum\Extension\Event\Uninstalled;
use Flarum\Foundation\Application;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
@@ -275,33 +276,15 @@ class ExtensionManager
}
/**
* Retrieve all extender instances of all enabled extensions.
* Call on all enabled extensions to extend the Flarum application.
*
* @return Collection
* @param Container $app
*/
public function getActiveExtenders()
public function extend(Container $app)
{
return $this->getEnabledExtensions()
->flatMap(function (Extension $extension) {
$bootstrapper = $extension->getBootstrapperPath();
if ($this->filesystem->exists($bootstrapper)) {
return array_map(function ($extender) use ($extension) {
// If an extension has not yet switched to the new bootstrap.php
// format, it might return a function (or more of them). We wrap
// these in a Compat extender to enjoy an unique interface.
if ($extender instanceof \Closure || is_string($extender)) {
$extender = new Compat($extender);
}
return function ($app) use ($extension, $extender) {
return $extender($app, $extension);
};
}, array_flatten((array) require $bootstrapper));
}
return [];
});
foreach ($this->getEnabledExtensions() as $extension) {
$extension->extend($app);
}
}
/**