phpvms/resources/stubs/modules/provider.stub

94 lines
2.2 KiB
Plaintext
Raw Normal View History

2017-12-14 12:24:41 +08:00
<?php
namespace $MODULE_NAMESPACE$\$STUDLY_NAME$\Providers;
2017-12-14 12:24:41 +08:00
use App\Contracts\Modules\ServiceProvider;
2017-12-14 12:24:41 +08:00
/**
* @package $NAMESPACE$
*/
class AppServiceProvider extends ServiceProvider
2017-12-14 12:24:41 +08:00
{
private $moduleSvc;
protected $defer = false;
2017-12-14 12:24:41 +08:00
/**
* Boot the application events.
2017-12-14 12:24:41 +08:00
*/
public function boot(): void
{
$this->moduleSvc = app('App\Services\ModuleService');
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->registerLinks();
// Uncomment this if you have migrations
// $this->loadMigrationsFrom(__DIR__ . '/../$MIGRATIONS_PATH$');
}
2017-12-14 12:24:41 +08:00
/**
* Register the service provider.
*/
public function register()
{
//
}
/**
* Add module links here
*/
public function registerLinks(): void
{
// Show this link if logged in
// $this->moduleSvc->addFrontendLink('$STUDLY_NAME$', '/$LOWER_NAME$', '', $logged_in=true);
// Admin links:
$this->moduleSvc->addAdminLink('$STUDLY_NAME$', '/admin/$LOWER_NAME$');
}
/**
* Register config.
2017-12-14 12:24:41 +08:00
*/
protected function registerConfig()
2017-12-14 12:24:41 +08:00
{
$this->publishes([
__DIR__.'/../Config/config.php' => config_path('$LOWER_NAME$.php'),
], '$LOWER_NAME$');
$this->mergeConfigFrom(__DIR__.'/../Config/config.php', '$LOWER_NAME$');
}
/**
* Register views.
*/
public function registerViews()
{
$viewPath = resource_path('views/modules/$LOWER_NAME$');
$sourcePath = __DIR__.'/../Resources/views';
$this->publishes([$sourcePath => $viewPath],'views');
$this->loadViewsFrom(array_merge(array_map(function ($path) {
return $path . '/modules/$LOWER_NAME$';
}, \Config::get('view.paths')), [$sourcePath]), '$LOWER_NAME$');
}
/**
* Register translations.
*/
public function registerTranslations()
{
$langPath = resource_path('lang/modules/$LOWER_NAME$');
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, '$LOWER_NAME$');
} else {
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', '$LOWER_NAME$');
}
2017-12-14 12:24:41 +08:00
}
}