mirror of
https://github.com/flarum/framework.git
synced 2025-03-02 12:33:10 +08:00
Re-introduce Compat extender
Turns out Container::call() does not work with invokable classes. Thus, we need to wrap callables in a custom extender class to support injecting any resolvable type-hint automatically. Refs #851.
This commit is contained in:
parent
cc1239fe9f
commit
73662598ef
@ -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
|
class Assets implements Extender
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
38
framework/core/src/Extend/Compat.php
Normal file
38
framework/core/src/Extend/Compat.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to wrap old bootstrap.php closures (as used in versions up
|
||||||
|
* to 0.1.0-beta7) in the new Extender format.
|
||||||
|
*
|
||||||
|
* This gives extensions the chance to work with the new API without making any
|
||||||
|
* changes, and have some time to convert to the pure usage of extenders.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
class Compat implements Extender
|
||||||
|
{
|
||||||
|
protected $callback;
|
||||||
|
|
||||||
|
public function __construct($callback)
|
||||||
|
{
|
||||||
|
$this->callback = $callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(Container $container)
|
||||||
|
{
|
||||||
|
$container->call($this->callback);
|
||||||
|
}
|
||||||
|
}
|
19
framework/core/src/Extend/Extender.php
Normal file
19
framework/core/src/Extend/Extender.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?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 __invoke(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
|
class FormatterConfiguration implements Extender
|
||||||
{
|
{
|
||||||
protected $callback;
|
protected $callback;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ use Flarum\Locale\LocaleManager;
|
|||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
class Locale
|
class Locale implements Extender
|
||||||
{
|
{
|
||||||
protected $directory;
|
protected $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
|
class Routes implements Extender
|
||||||
{
|
{
|
||||||
protected $appName;
|
protected $appName;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Flarum\Extension;
|
namespace Flarum\Extension;
|
||||||
|
|
||||||
use Flarum\Database\Migrator;
|
use Flarum\Database\Migrator;
|
||||||
|
use Flarum\Extend\Compat;
|
||||||
use Flarum\Extension\Event\Disabled;
|
use Flarum\Extension\Event\Disabled;
|
||||||
use Flarum\Extension\Event\Disabling;
|
use Flarum\Extension\Event\Disabling;
|
||||||
use Flarum\Extension\Event\Enabled;
|
use Flarum\Extension\Event\Enabled;
|
||||||
@ -285,7 +286,14 @@ class ExtensionManager
|
|||||||
if ($this->filesystem->exists($bootstrapper)) {
|
if ($this->filesystem->exists($bootstrapper)) {
|
||||||
$extenders = require $bootstrapper;
|
$extenders = require $bootstrapper;
|
||||||
|
|
||||||
return (array) $extenders;
|
if (is_array($extenders)) {
|
||||||
|
return $extenders;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assume that the extension has not yet switched to the new
|
||||||
|
// bootstrap.php format, and wrap the callback in a Compat
|
||||||
|
// extender.
|
||||||
|
return [new Compat($extenders)];
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user