From 407515f5a75266efc2e32b966a9223a0d8de8715 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 4 Mar 2018 10:13:12 +1030 Subject: [PATCH] Give Extenders information about which Extension they belong to --- framework/core/src/Extend/Assets.php | 3 ++- framework/core/src/Extend/Compat.php | 3 ++- framework/core/src/Extend/Extender.php | 3 ++- .../src/Extend/FormatterConfiguration.php | 3 ++- framework/core/src/Extend/Locale.php | 3 ++- framework/core/src/Extend/Routes.php | 3 ++- .../core/src/Extension/ExtensionManager.php | 27 ++++++++++--------- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/framework/core/src/Extend/Assets.php b/framework/core/src/Extend/Assets.php index 0738e2529..6236f4a51 100644 --- a/framework/core/src/Extend/Assets.php +++ b/framework/core/src/Extend/Assets.php @@ -11,6 +11,7 @@ namespace Flarum\Extend; +use Flarum\Extension\Extension; use Flarum\Frontend\Event\Rendering; use Illuminate\Contracts\Container\Container; use Illuminate\Events\Dispatcher; @@ -41,7 +42,7 @@ class Assets implements Extender return $this; } - public function __invoke(Container $container) + public function __invoke(Container $container, Extension $extension = null) { $container->make(Dispatcher::class)->listen( Rendering::class, diff --git a/framework/core/src/Extend/Compat.php b/framework/core/src/Extend/Compat.php index 62e059cc4..662f37536 100644 --- a/framework/core/src/Extend/Compat.php +++ b/framework/core/src/Extend/Compat.php @@ -11,6 +11,7 @@ namespace Flarum\Extend; +use Flarum\Extension\Extension; use Illuminate\Contracts\Container\Container; /** @@ -31,7 +32,7 @@ class Compat implements Extender $this->callback = $callback; } - public function __invoke(Container $container) + public function __invoke(Container $container, Extension $extension = null) { $container->call($this->callback); } diff --git a/framework/core/src/Extend/Extender.php b/framework/core/src/Extend/Extender.php index 2ee9d7e13..138b4bbda 100644 --- a/framework/core/src/Extend/Extender.php +++ b/framework/core/src/Extend/Extender.php @@ -11,9 +11,10 @@ namespace Flarum\Extend; +use Flarum\Extension\Extension; use Illuminate\Contracts\Container\Container; interface Extender { - public function __invoke(Container $container); + public function __invoke(Container $container, Extension $extension = null); } diff --git a/framework/core/src/Extend/FormatterConfiguration.php b/framework/core/src/Extend/FormatterConfiguration.php index a5532ad0b..b82adf0b1 100644 --- a/framework/core/src/Extend/FormatterConfiguration.php +++ b/framework/core/src/Extend/FormatterConfiguration.php @@ -11,6 +11,7 @@ namespace Flarum\Extend; +use Flarum\Extension\Extension; use Flarum\Formatter\Event\Configuring; use Illuminate\Contracts\Container\Container; use Illuminate\Events\Dispatcher; @@ -24,7 +25,7 @@ class FormatterConfiguration implements Extender $this->callback = $callback; } - public function __invoke(Container $container) + public function __invoke(Container $container, Extension $extension = null) { $container->make(Dispatcher::class)->listen( Configuring::class, diff --git a/framework/core/src/Extend/Locale.php b/framework/core/src/Extend/Locale.php index cff7dfab2..f127bd6fb 100644 --- a/framework/core/src/Extend/Locale.php +++ b/framework/core/src/Extend/Locale.php @@ -12,6 +12,7 @@ namespace Flarum\Extend; use DirectoryIterator; +use Flarum\Extension\Extension; use Flarum\Locale\LocaleManager; use Illuminate\Contracts\Container\Container; use RuntimeException; @@ -25,7 +26,7 @@ class Locale implements Extender $this->directory = $directory; } - public function __invoke(Container $container) + public function __invoke(Container $container, Extension $extension = null) { $this->loadLanguagePackFrom( $this->directory, diff --git a/framework/core/src/Extend/Routes.php b/framework/core/src/Extend/Routes.php index c867634ec..0a99895c6 100644 --- a/framework/core/src/Extend/Routes.php +++ b/framework/core/src/Extend/Routes.php @@ -11,6 +11,7 @@ namespace Flarum\Extend; +use Flarum\Extension\Extension; use Flarum\Http\RouteHandlerFactory; use Illuminate\Contracts\Container\Container; @@ -62,7 +63,7 @@ class Routes implements Extender return $this; } - public function __invoke(Container $container) + public function __invoke(Container $container, Extension $extension = null) { if (empty($this->routes)) { return; diff --git a/framework/core/src/Extension/ExtensionManager.php b/framework/core/src/Extension/ExtensionManager.php index dc773b364..99786e2ea 100644 --- a/framework/core/src/Extension/ExtensionManager.php +++ b/framework/core/src/Extension/ExtensionManager.php @@ -284,20 +284,23 @@ class ExtensionManager return $this->getEnabledExtensions() ->flatMap(function (Extension $extension) { $bootstrapper = $extension->getBootstrapperPath(); + if ($this->filesystem->exists($bootstrapper)) { - return (array) require $bootstrapper; - } else { - return []; - } - })->map(function ($extender) { - // 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)) { - return new Compat($extender); - } else { - return $extender; + 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 []; }); }