mirror of
https://github.com/flarum/framework.git
synced 2024-12-05 09:03:36 +08:00
Allow extensions to return a callback instead of a provider name
This is useful for very simple extensions like language packs, because it means no Composer/namespacing and thus bootstrap.php doesn't have to be changed at all.
This commit is contained in:
parent
575ff76002
commit
7889b15f09
|
@ -53,8 +53,6 @@ class ExtensionManager
|
||||||
|
|
||||||
$enabled[] = $extension;
|
$enabled[] = $extension;
|
||||||
|
|
||||||
$this->load($extension);
|
|
||||||
|
|
||||||
$this->migrate($extension);
|
$this->migrate($extension);
|
||||||
|
|
||||||
$this->setEnabled($enabled);
|
$this->setEnabled($enabled);
|
||||||
|
@ -76,8 +74,6 @@ class ExtensionManager
|
||||||
{
|
{
|
||||||
$this->disable($extension);
|
$this->disable($extension);
|
||||||
|
|
||||||
$this->load($extension);
|
|
||||||
|
|
||||||
$this->migrateDown($extension);
|
$this->migrateDown($extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,15 +121,6 @@ class ExtensionManager
|
||||||
return in_array($extension, $this->getEnabled());
|
return in_array($extension, $this->getEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function load($extension)
|
|
||||||
{
|
|
||||||
if (file_exists($file = $this->getExtensionsDir() . '/' . $extension . '/bootstrap.php')) {
|
|
||||||
$className = require $file;
|
|
||||||
|
|
||||||
$ext = new $className($this->app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getExtensionsDir()
|
protected function getExtensionsDir()
|
||||||
{
|
{
|
||||||
return public_path('extensions');
|
return public_path('extensions');
|
||||||
|
|
|
@ -23,19 +23,19 @@ class ExtensionsServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
$config = $this->app->make('Flarum\Core\Settings\SettingsRepository')->get('extensions_enabled');
|
$config = $this->app->make('Flarum\Core\Settings\SettingsRepository')->get('extensions_enabled');
|
||||||
$extensions = json_decode($config, true);
|
$extensions = json_decode($config, true);
|
||||||
$providers = [];
|
|
||||||
|
|
||||||
foreach ($extensions as $extension) {
|
|
||||||
if (file_exists($file = public_path().'/extensions/'.$extension.'/bootstrap.php')) {
|
|
||||||
$providerName = require $file;
|
|
||||||
$providers[$extension] = $this->app->register($providerName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$events = $this->app->make('events');
|
$events = $this->app->make('events');
|
||||||
|
|
||||||
foreach ($providers as $provider) {
|
foreach ($extensions as $extension) {
|
||||||
$provider->listen($events);
|
if (file_exists($file = public_path().'/extensions/'.$extension.'/bootstrap.php')) {
|
||||||
|
$provider = require $file;
|
||||||
|
|
||||||
|
if (is_string($provider)) {
|
||||||
|
$this->app->register($provider)->listen($events);
|
||||||
|
} elseif (is_callable($provider)) {
|
||||||
|
$provider($events);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user