1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 14:10:37 +02:00

Rework extension bootstrapping

System JS modules don't execute when they're registered, so we need to
import them explicitly. While we're at it, we may as well make the
locale bootstrapper a module too.
This commit is contained in:
Toby Zerner
2015-07-20 18:08:28 +09:30
parent 19fe138770
commit 6b7cf1b6bf
12 changed files with 130 additions and 59 deletions

View File

@@ -4,6 +4,7 @@
// classes in the src directory to be autoloaded.
require __DIR__.'/vendor/autoload.php';
// Register our service provider with the Flarum application. In here we can
// register bindings and execute code when the application boots.
return $this->app->register('{{namespace}}\{{classPrefix}}ServiceProvider');
// Return the name of our Extension class. Flarum will register it as a service
// provider, allowing it to register bindings and execute code when the
// application boots.
return '{{namespace}}\Extension';

View File

@@ -1,8 +0,0 @@
import { extend, override } from 'flarum/extension-utils';
import app from 'flarum/app';
app.initializers.add('{{name}}', function() {
// @todo
});

View File

@@ -0,0 +1,4 @@
import { extend } from 'flarum/extend';
import app from 'flarum/app';
// TODO

View File

@@ -0,0 +1,27 @@
<?php namespace {{namespace}};
use Flarum\Support\Extension;
use Illuminate\Events\Dispatcher;
class Extension extends BaseExtension
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot(Dispatcher $events)
{
$events->subscribe('{{namespace}}\Listeners\AddClientAssets');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}

View File

@@ -0,0 +1,33 @@
<?php namespace {{namespace}}\Listeners;
use Flarum\Events\RegisterLocales;
use Flarum\Events\BuildClientView;
use Illuminate\Contracts\Events\Dispatcher;
class AddClientAssets
{
public function subscribe(Dispatcher $events)
{
$events->listen(RegisterLocales::class, __CLASS__.'@addLocale');
$events->listen(BuildClientView::class, __CLASS__.'@addAssets');
}
public function addLocale(RegisterLocales $event)
{
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
}
public function addAssets(BuildClientView $event)
{
$event->forumAssets([
__DIR__.'/../../js/dist/extension.js',
__DIR__.'/../../less/extension.less'
]);
$event->forumBootstrapper('{{name}}/main');
$event->forumTranslations([
// '{{name}}.hello_world'
]);
}
}

View File

@@ -1,39 +0,0 @@
<?php namespace {{namespace}};
use Flarum\Support\ServiceProvider;
use Flarum\Extend;
class {{classPrefix}}ServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->extend([
(new Extend\Locale('en'))->translations(__DIR__.'/../locale/en.yml'),
(new Extend\ForumClient())
->assets([
__DIR__.'/../js/dist/extension.js',
__DIR__.'/../less/extension.less'
])
->translations([
// Add the keys of translations you would like to be available
// for use by the JS client application.
])
]);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}