Skip to content

Get updates #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/laravel-modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return [

"modulesPath" => base_path('modules'),

/*
* If this option is true, Artisan commands for Nova will be enabled and modules will support Nova files.
*/
"supportLaravelNova" => false,

];
4 changes: 2 additions & 2 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function modules(string $location = null) {
*/
function module_path($slug = null, $file = '', $location = null , $inSrc = false , $typeSeeder = false) {
$location = $location ?: "modules";
$modulesPath = base_path('modules');
$modulesPath = config('laravel-modules.modulesPath');

$filePath = $file ? '/' . ltrim($file, '/') : '';

Expand Down Expand Up @@ -71,7 +71,7 @@ function module_path($slug = null, $file = '', $location = null , $inSrc = false
* @throws \Idel\Modular\Exceptions\ModuleNotFoundException
*/
function module_class($slug, $class, $location = null) {
$location = $location ?: base_path('modules');
$location = $location ?: config('laravel-modules.modulesPath');
$module = modules($location)->where('slug', $slug);

if (is_null($module)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ abstract class GeneratorCommand extends LaravelGeneratorCommand
protected function qualifyClass($name)
{
try {
$location = $this->option('location') ?: base_path('modules');
$location = $this->option('location') ?: config('laravel-modules.modulesPath');
}
catch (\Exception $e) {
$location = base_path('modules');
$location = config('laravel-modules.modulesPath');
}
$name = str_replace('/', '\\', $name);
return $this->getDefaultNamespace($this->rootNamespace()).'\\'.$name;
Expand All @@ -34,10 +34,10 @@ protected function qualifyClass($name)
protected function getPath($name)
{
try {
$location = $this->option('location') ?: base_path('modules');
$location = $this->option('location') ?: config('laravel-modules.modulesPath');
}
catch (\Exception $e) {
$location = base_path('modules');
$location = config('laravel-modules.modulesPath');
}
$slug = $this->argument('slug');
$module = Module::location($location)->where('slug', $slug);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Generators/MakeConfigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle()
{
$name = $this->argument('name');
$module = $this->argument('slug');
$directionModule = base_path('modules') .'/' . $module;
$directionModule = config('laravel-modules.modulesPath') .'/' . $module;

if (!$this->files->isDirectory("{$directionModule}/config")) {
$this->files->makeDirectory("{$directionModule}/config",0755, true);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Generators/MakeLanguageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle()
{
$name = $this->argument('name');
$module = $this->argument('slug');
$directionModule = base_path('modules') .'/' . $module;
$directionModule = config('laravel-modules.modulesPath') .'/' . $module;

if (!$this->files->isDirectory("{$directionModule}/languages")) {
$this->files->makeDirectory("{$directionModule}/languages",0755, true);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Generators/MakeListenerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle()
$event = $this->option('event');
$eventShortName = Str::studly($event);
$studlyName = Str::studly($name);
$directionModule = base_path('modules') .'/' . $module . '/src';
$directionModule = config('laravel-modules.modulesPath') .'/' . $module . '/src';
$studlyModule = Str::studly($module);
$namespace = "App\\{$studlyModule}\\Listeners";
$eventNamespace = "App\\{$studlyModule}\\Events\\{$eventShortName}";
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Generators/MakeMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle()
$name = $this->argument('name');
$module = $this->argument('slug');
$studlyName = Str::studly($name);
$directionModule = base_path('modules') .'/' . $module . '/src';
$directionModule = config('laravel-modules.modulesPath') .'/' . $module . '/src';
$studlyModule = Str::studly($module);
$namespace = "App\\{$studlyModule}\\Mails";
$template = str_replace([
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Generators/MakeModuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function handle()
$name = $this->container['name'];
$this->container['description'] = "This is the description for the {$name} module.";

$this->container['location'] = base_path('modules');
$this->container['location'] = config('laravel-modules.modulesPath');
$this->container['provider'] = "{$name}ServiceProvider";


Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getManifest(string $slug)
*/
public function getPath(): string
{
return $this->path ?: base_path('modules');
return $this->path ?: config('laravel-modules.modulesPath');
}

/**
Expand Down
20 changes: 8 additions & 12 deletions src/RepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class RepositoryManager
protected $classLoader;

/**
* @var Path
* @var Modules Path
*/
protected $path;
protected $modulePath;

/**
* Repository Manager instance.
Expand All @@ -36,7 +36,7 @@ class RepositoryManager
public function __construct(Application $app)
{
$this->app = $app;
$this->path = base_path('modules');
$this->modulePath = config('laravel-modules.modulesPath');
$this->classLoader = new ClassLoader;
}

Expand All @@ -47,9 +47,7 @@ public function __construct(Application $app)
*/
public function register()
{
$moduleLocations = base_path('modules');

$repository = $this->repository($moduleLocations);
$repository = $this->repository($this->modulePath);
$modules = $repository->enabled()->sortBy(['order']);

$modules->each(function ($module){
Expand All @@ -67,8 +65,7 @@ public function register()
private function registerServiceProvider($module)
{
$moduleName = $module['name'];
$provider = $moduleName . "ServiceProvider";
$providerLoader = "App\\{$moduleName}\\Providers\\{$provider}";
$providerLoader = "App\\{$moduleName}\\Providers\\{$moduleName}ServiceProvider";
if (class_exists($providerLoader)) {
$this->app->register($providerLoader);
}
Expand All @@ -82,10 +79,9 @@ private function registerServiceProvider($module)
*/
public function addPsr4($module)
{
$modulrDir = $this->path;
$moduleName = $module['name'];
$moduleSlug = $module['slug'];
$this->classLoader->addPsr4('App\\' . $moduleName . '\\', $modulrDir . '/' .$moduleSlug . "/src");
$this->classLoader->addPsr4("App\\{$moduleName}\\", "{$this->modulePath}/{$moduleSlug}/src");
$this->classLoader->register();
}

Expand All @@ -103,8 +99,8 @@ public function repositories()
*/
protected function repository()
{
return $this->repositories[$this->path]
?? $this->repositories[$this->path] = new LocalRepository($this->path);
return $this->repositories[$this->modulePath]
?? $this->repositories[$this->modulePath] = new LocalRepository($this->modulePath);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ServiceProvider extends LaravelServiceProvider
*/
public function boot()
{
$this->publishes();
$this->app['modules']->register();
}

Expand All @@ -32,6 +33,18 @@ public function register()
});
}

/**
* Publishes files.
*/
public function publishes()
{
$configPath = __DIR__ . '/../config/laravel-modules.php'

$this->publishes([
$configPath => config_path('laravel-modules.php'),
], 'config');
}

/**
* Get the services provided by the package.
*
Expand Down