added countries support expanded for ISO 3166 standard merged in new support
This commit is contained in:
@@ -10,13 +10,20 @@ use Modules\Countries\Support\ModuleInfo;
|
||||
class CountriesServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Countries';
|
||||
|
||||
protected string $moduleNameLower = 'countries';
|
||||
|
||||
/**
|
||||
* Register module services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap module services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerTranslations();
|
||||
@@ -24,72 +31,127 @@ class CountriesServiceProvider extends ServiceProvider
|
||||
$this->registerViews();
|
||||
$this->registerHelpers();
|
||||
$this->registerCommands();
|
||||
$this->loadMigrationsFrom(module_path(ModuleInfo::name(), 'Database/Migrations'));
|
||||
$this->registerMigrations();
|
||||
}
|
||||
|
||||
public function provides(): array
|
||||
/**
|
||||
* Register module migrations using the real filesystem path.
|
||||
*/
|
||||
protected function registerMigrations(): void
|
||||
{
|
||||
return [];
|
||||
$path = dirname(__DIR__).'/Database/Migrations';
|
||||
|
||||
if (is_dir($path)) {
|
||||
$this->loadMigrationsFrom($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module helper files.
|
||||
*/
|
||||
protected function registerHelpers(): void
|
||||
{
|
||||
foreach (glob(__DIR__.'/../Helpers/*.php') ?: [] as $filename) {
|
||||
foreach (glob(dirname(__DIR__).'/Helpers/*.php') ?: [] as $filename) {
|
||||
require_once $filename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register console commands when present.
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
if (! $this->app->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
$commandPath = __DIR__.'/../Console';
|
||||
|
||||
$commandPath = dirname(__DIR__).'/Console';
|
||||
|
||||
if (! is_dir($commandPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$commands = collect(File::allFiles($commandPath))
|
||||
->map(fn ($file): string => 'Modules\\'.$this->moduleName.'\\Console\\'.$file->getFilenameWithoutExtension())
|
||||
->filter(fn (string $class): bool => class_exists($class))
|
||||
->values()
|
||||
->all();
|
||||
$this->commands($commands);
|
||||
|
||||
if ($commands !== []) {
|
||||
$this->commands($commands);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$sourcePath = dirname(__DIR__).'/Config/config.php';
|
||||
|
||||
if (! is_file($sourcePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->publishes([
|
||||
module_path(ModuleInfo::name(), 'Config/config.php') => config_path(ModuleInfo::nameLower().'.php'),
|
||||
$sourcePath => config_path(ModuleInfo::nameLower().'.php'),
|
||||
], 'config');
|
||||
$this->mergeConfigFrom(module_path(ModuleInfo::name(), 'Config/config.php'), ModuleInfo::nameLower());
|
||||
|
||||
$this->mergeConfigFrom($sourcePath, ModuleInfo::nameLower());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module views.
|
||||
*/
|
||||
protected function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.ModuleInfo::nameLower());
|
||||
$sourcePath = module_path(ModuleInfo::name(), 'Resources/views');
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', ModuleInfo::nameLower().'-module-views']);
|
||||
$sourcePath = dirname(__DIR__).'/Resources/views';
|
||||
|
||||
if (! is_dir($sourcePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->publishes([
|
||||
$sourcePath => $viewPath,
|
||||
], ['views', ModuleInfo::nameLower().'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module translations.
|
||||
*/
|
||||
protected function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.ModuleInfo::nameLower());
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
|
||||
$publishedPath = resource_path('lang/modules/'.ModuleInfo::nameLower());
|
||||
$sourcePath = dirname(__DIR__).'/Resources/lang';
|
||||
|
||||
if (is_dir($publishedPath)) {
|
||||
$this->loadTranslationsFrom($publishedPath, ModuleInfo::nameLower());
|
||||
return;
|
||||
}
|
||||
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), 'Resources/lang'), ModuleInfo::nameLower());
|
||||
|
||||
if (is_dir($sourcePath)) {
|
||||
$this->loadTranslationsFrom($sourcePath, ModuleInfo::nameLower());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get published view paths.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (Config::get('view.paths') as $path) {
|
||||
|
||||
foreach (Config::get('view.paths', []) as $path) {
|
||||
if (is_dir($path.'/modules/'.ModuleInfo::nameLower())) {
|
||||
$paths[] = $path.'/modules/'.ModuleInfo::nameLower();
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user