New listen API

Event subscriptions now take place before *any* boot method is called.
This ensures that all event listeners are registered before things
happen – e.g. locales are registered before the translator is
instantiated in the Tags extension's boot method.
This commit is contained in:
Toby Zerner 2015-08-13 12:55:48 +09:30
parent 6db682217a
commit 0a19ca5e19
3 changed files with 12 additions and 16 deletions

View File

@ -1,6 +1,7 @@
<?php namespace Flarum\Support; <?php namespace Flarum\Support;
use Flarum\Support\ServiceProvider; use Flarum\Support\ServiceProvider;
use Illuminate\Events\Dispatcher;
class Extension extends ServiceProvider class Extension extends ServiceProvider
{ {
@ -11,4 +12,8 @@ class Extension extends ServiceProvider
public function uninstall() public function uninstall()
{ {
} }
public function listen(Dispatcher $events)
{
}
} }

View File

@ -21,5 +21,11 @@ class ExtensionsServiceProvider extends ServiceProvider
$providers[$extension] = $this->app->register($providerName); $providers[$extension] = $this->app->register($providerName);
} }
} }
$events = $this->app->make('events');
foreach ($providers as $provider) {
$provider->listen($events);
}
} }
} }

View File

@ -5,23 +5,8 @@ use Illuminate\Events\Dispatcher;
class Extension extends BaseExtension class Extension extends BaseExtension
{ {
/** public function listen(Dispatcher $events)
* Bootstrap the application events.
*
* @return void
*/
public function boot(Dispatcher $events)
{ {
$events->subscribe('{{namespace}}\Listeners\AddClientAssets'); $events->subscribe('{{namespace}}\Listeners\AddClientAssets');
} }
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
} }