mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 11:34:36 +08:00
Turn extenders into callables
This simplifies the API and gives extension developers more flexibility, for a) maintaining backwards compatibility, and b) doing advanced stuff that extenders do not allow. Note that only extenders are guaranteed to work across different versions of Flarum (once the API surface is stable). See the discussion in https://github.com/flarum/core/pull/1335.
This commit is contained in:
parent
714775cfed
commit
1ce70eeb6e
|
@ -15,7 +15,7 @@ use Flarum\Frontend\Event\Rendering;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Events\Dispatcher;
|
use Illuminate\Events\Dispatcher;
|
||||||
|
|
||||||
class Assets implements Extender
|
class Assets
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class Assets implements Extender
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(Container $container)
|
public function __invoke(Container $container)
|
||||||
{
|
{
|
||||||
$container->make(Dispatcher::class)->listen(
|
$container->make(Dispatcher::class)->listen(
|
||||||
Rendering::class,
|
Rendering::class,
|
||||||
|
|
|
@ -22,7 +22,7 @@ use Illuminate\Contracts\Container\Container;
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
class Compat implements Extender
|
class Compat
|
||||||
{
|
{
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class Compat implements Extender
|
||||||
$this->callback = $callback;
|
$this->callback = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(Container $container)
|
public function __invoke(Container $container)
|
||||||
{
|
{
|
||||||
$container->call($this->callback);
|
$container->call($this->callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Extend;
|
|
||||||
|
|
||||||
use Illuminate\Contracts\Container\Container;
|
|
||||||
|
|
||||||
interface Extender
|
|
||||||
{
|
|
||||||
public function apply(Container $container);
|
|
||||||
}
|
|
|
@ -15,7 +15,7 @@ use Flarum\Formatter\Event\Configuring;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Events\Dispatcher;
|
use Illuminate\Events\Dispatcher;
|
||||||
|
|
||||||
class FormatterConfiguration implements Extender
|
class FormatterConfiguration
|
||||||
{
|
{
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class FormatterConfiguration implements Extender
|
||||||
$this->callback = $callback;
|
$this->callback = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(Container $container)
|
public function __invoke(Container $container)
|
||||||
{
|
{
|
||||||
$container->make(Dispatcher::class)->listen(
|
$container->make(Dispatcher::class)->listen(
|
||||||
Configuring::class,
|
Configuring::class,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use Flarum\Locale\LocaleManager;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class Locale implements Extender
|
class Locale
|
||||||
{
|
{
|
||||||
protected $directory;
|
protected $directory;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class Locale implements Extender
|
||||||
$this->directory = $directory;
|
$this->directory = $directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(Container $container)
|
public function __invoke(Container $container)
|
||||||
{
|
{
|
||||||
$this->loadLanguagePackFrom(
|
$this->loadLanguagePackFrom(
|
||||||
$this->directory,
|
$this->directory,
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Flarum\Extend;
|
||||||
use Flarum\Http\RouteHandlerFactory;
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
|
|
||||||
class Routes implements Extender
|
class Routes
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class Routes implements Extender
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(Container $container)
|
public function __invoke(Container $container)
|
||||||
{
|
{
|
||||||
if (empty($this->routes)) {
|
if (empty($this->routes)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -24,11 +24,11 @@ class ExtensionServiceProvider extends AbstractServiceProvider
|
||||||
$this->app->bind('flarum.extensions', ExtensionManager::class);
|
$this->app->bind('flarum.extensions', ExtensionManager::class);
|
||||||
|
|
||||||
$this->app->booting(function (Container $app) {
|
$this->app->booting(function (Container $app) {
|
||||||
/** @var \Flarum\Extend\Extender[] $extenders */
|
/** @var callable[] $extenders */
|
||||||
$extenders = $app->make('flarum.extensions')->getActiveExtenders();
|
$extenders = $app->make('flarum.extensions')->getActiveExtenders();
|
||||||
|
|
||||||
foreach ($extenders as $extender) {
|
foreach ($extenders as $extender) {
|
||||||
$extender->apply($app);
|
$app->call($extender);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user