Skip to content

Commit

Permalink
Merge branch 'master' into enable-module-has-method-to-accept-both-lo…
Browse files Browse the repository at this point in the history
…wercase-and-uppercase
  • Loading branch information
dcblogdev authored Aug 17, 2024
2 parents 11845e0 + ecea05a commit a1ddb8b
Show file tree
Hide file tree
Showing 422 changed files with 1,291 additions and 15,920 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"require": {
"php": ">=8.2",
"ext-json": "*",
"wikimedia/composer-merge-plugin": "^2.1",
"laravel/pint": "^1.16"
"wikimedia/composer-merge-plugin": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^v9.0",
"friendsofphp/php-cs-fixer": "^v3.52",
"laravel/framework": "^v11.0",
"laravel/pint": "^1.16",
"spatie/phpunit-snapshot-assertions": "^5.0",
"phpstan/phpstan": "^1.4"
},
Expand Down
32 changes: 32 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@
],
],

/*
|--------------------------------------------------------------------------
| Auto Discover of Modules
|--------------------------------------------------------------------------
|
| Here you configure auto discover of module
| This is useful for simplify module providers.
|
*/
'auto-discover' => [
/*
|--------------------------------------------------------------------------
| Migrations
|--------------------------------------------------------------------------
|
| This option for register migration automatically.
|
*/
'migrations' => true,

/*
|--------------------------------------------------------------------------
| Translations
|--------------------------------------------------------------------------
|
| This option for register lang file automatically.
|
*/
'translations' => false,

],

/*
|--------------------------------------------------------------------------
| Package commands
Expand Down
61 changes: 36 additions & 25 deletions src/Commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Console\Prohibitable;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Support\Collection;
use Nwidart\Modules\Contracts\ConfirmableCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function Laravel\Prompts\multiselect;
use function Laravel\Prompts\multisearch;

abstract class BaseCommand extends Command implements PromptsForMissingInput
{
Expand All @@ -29,18 +30,22 @@ abstract class BaseCommand extends Command implements PromptsForMissingInput
public function __construct()
{
parent::__construct();
$this->getDefinition()->addOption(new InputOption(
strtolower(self::ALL),
'a',
InputOption::VALUE_NONE,
'Check all Modules',
));

$this->getDefinition()->addArgument(new InputArgument(
'module',
InputArgument::IS_ARRAY,
'The name of module will be used.',
));
$this->getDefinition()->addOption(
option: new InputOption(
name: strtolower(self::ALL),
shortcut: 'a',
mode: InputOption::VALUE_NONE,
description: 'Check all Modules',
)
);

$this->getDefinition()->addArgument(
argument: new InputArgument(
name: 'module',
mode: InputArgument::IS_ARRAY,
description: 'The name of module will be used.',
)
);

if ($this instanceof ConfirmableCommand) {
$this->configureConfirmable();
Expand Down Expand Up @@ -98,12 +103,16 @@ protected function promptForMissingArguments(InputInterface $input, OutputInterf
return;
}

$selected_item = multiselect(
label : 'Select Modules',
options : [
self::ALL,
...$modules,
],
$selected_item = multisearch(
label: 'Select Modules',
options: function (string $search_value) use ($modules) {
return collect([
self::ALL,
...$modules,
])->when(strlen($search_value) > 0, function (Collection &$modules) use ($search_value) {
return $modules->filter(fn ($item) => str_contains(strtolower($item), strtolower($search_value)));
})->values()->toArray();
},
required: 'You must select at least one module',
);

Expand All @@ -125,11 +134,13 @@ protected function getModuleModel($name)
private function configureConfirmable(): void
{
$this->getDefinition()
->addOption(new InputOption(
'force',
null,
InputOption::VALUE_NONE,
'Force the operation to run without confirmation.',
));
->addOption(
option: new InputOption(
name: 'force',
shortcut: null,
mode: InputOption::VALUE_NONE,
description: 'Force the operation to run without confirmation.',
)
);
}
}
1 change: 1 addition & 0 deletions src/Commands/Database/MigrateFreshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function handle(): void

// run migration of root
$root_paths = $this->migration_paths
->push($this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations')
->reject(fn (string $path) => str_starts_with($path, config('modules.paths.modules')));

if ($root_paths->count() > 0) {
Expand Down
32 changes: 32 additions & 0 deletions src/Commands/ModuleClearCompiledCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Nwidart\Modules\Commands;

use Illuminate\Console\Command;
use Nwidart\Modules\ModuleManifest;

class ModuleClearCompiledCommand extends Command
{
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'module:clear-compiled';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove the module compiled class file';

public function handle(ModuleManifest $manifest): void
{
if (is_file($manifest->manifestPath)) {
@unlink($manifest->manifestPath);
}

$this->components->info('Compiled module files removed successfully.');
}
}
36 changes: 36 additions & 0 deletions src/Commands/ModuleDiscoverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Nwidart\Modules\Commands;

use Illuminate\Console\Command;
use Nwidart\Modules\ModuleManifest;

class ModuleDiscoverCommand extends Command
{
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'module:discover';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create module compiled class file';

public function handle(ModuleManifest $manifest): void
{
$this->components->info('Discovering modules');

$manifest->build();

collect($manifest->providersArray())
->map(fn ($provider) => preg_match('/Modules\\\\(.*?)\\\\/', $provider, $matches) ? $matches[1] : null)
->unique()
->each(fn ($description) => $this->components->task($description))
->whenNotEmpty(fn () => $this->newLine());
}
}
6 changes: 2 additions & 4 deletions src/Commands/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace $CLASS_NAMESPACE$;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class $CLASS$ extends Controller
{
Expand All @@ -28,7 +26,7 @@ class $CLASS$ extends Controller
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
public function store(Request $request)
{
//
}
Expand All @@ -52,7 +50,7 @@ class $CLASS$ extends Controller
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
public function update(Request $request, $id)
{
//
}
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/stubs/event-provider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ class $CLASS$ extends ServiceProvider

/**
* Configure the proper event listeners for email verification.
*
* @return void
*/
protected function configureEmailVerification(): void
{

//
}
}
10 changes: 5 additions & 5 deletions src/Commands/stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace $NAMESPACE$;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use $MODULE_NAMESPACE$\$MODULE$\Database\Factories\$NAME$Factory;
// use $MODULE_NAMESPACE$\$MODULE$\Database\Factories\$NAME$Factory;

class $CLASS$ extends Model
{
Expand All @@ -15,8 +15,8 @@ class $CLASS$ extends Model
*/
protected $fillable = $FILLABLE$;

protected static function newFactory(): $NAME$Factory
{
//return $NAME$Factory::new();
}
// protected static function newFactory(): $NAME$Factory
// {
// // return $NAME$Factory::new();
// }
}
30 changes: 30 additions & 0 deletions src/Constants/ModuleEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Nwidart\Modules\Constants;

class ModuleEvent
{
const BOOT = 'boot';

const REGISTER = 'register';

const DISABLING = 'disabling';

const DISABLED = 'disabled';

const ENABLING = 'enabling';

const ENABLED = 'enabled';

const CREATING = 'creating';

const CREATED = 'created';

const DELETING = 'deleting';

const DELETED = 'deleted';

const USED = 'used';

const UNUSED = 'unused';
}
Loading

0 comments on commit a1ddb8b

Please sign in to comment.