add swiftpayments from old source

This commit is contained in:
2024-09-01 17:06:49 +05:00
parent 9d65fa72b6
commit a5978835d0
27 changed files with 1822 additions and 141 deletions

View File

@@ -0,0 +1,258 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\PromptsForMissingInput;
use Illuminate\Database\Migrations\MigrationCreator;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
class MakeModule extends Command implements PromptsForMissingInput
{
/**
* Filesystem instance
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected Filesystem $files;
/**
* Module name
*/
protected string $moduleName;
/**
* Module directory path
*/
protected string $moduleDirectory;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:module {module}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create new module';
/**
* Prompt for missing input arguments using the returned questions.
*
* @return array<string, array<int, string>>
*/
protected function promptForMissingArgumentsUsing(): array
{
return [
'module' => ['Module name', 'News, Product, Order...'],
];
}
/**
* Create a new command instance.
*
* @param \Illuminate\Filesystem\Filesystem $files
* @return void
*/
public function __construct(Filesystem $files)
{
parent::__construct();
$this->files = $files;
}
/**
* Execute the console command.
*/
public function handle(): void
{
/* @var string */
$module = $this->argument('module');
$this->moduleName = $module;
$this->moduleDirectory = modules_path($module.'/');
// Create module directory if not exists...
$this->makeDirectory($this->moduleDirectory);
// Models...
$this->makeDirectory($this->moduleDirectory.'Models');
$this->makeModelFile($this->moduleDirectory.'Models');
// Database...
$this->makeDirectory($this->moduleDirectory.'Database');
$this->makeDirectory($this->moduleDirectory.'Database/Migrations');
$this->makeMigrationFile($this->moduleDirectory.'Database/Migrations');
// Controller...
$this->makeDirectory($this->moduleDirectory.'Controllers');
$this->makeController($this->moduleDirectory.'Controllers');
// Repository...
$this->makeDirectory($this->moduleDirectory.'Repositories');
$this->makeRepository($this->moduleDirectory.'Repositories');
// Nova...
$this->makeDirectory($this->moduleDirectory.'Nova');
$this->makeDirectory($this->moduleDirectory.'Nova/Resources');
$this->makeNovaResource($this->moduleDirectory.'Nova/Resources');
}
/**
* Make model file
*
* @param string $modelPath
*/
protected function makeModelFile(string $modelPath): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $modelPath, $this->moduleName),
stubFile: __DIR__.'/stubs/make-module/model.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\\Modules\\%s\\Models', $this->moduleName),
'CLASS_NAME' => $this->moduleName,
]
);
$creationStatus
? $this->info("Model created: {$this->moduleName} created")
: $this->info("Model: {$this->moduleName} already exits");
}
/**
* Make migration file
*
* @param string $migrationsPath
*/
protected function makeMigrationFile(string $migrationsPath): void
{
$migrationCreator = new MigrationCreator(
files: new Filesystem,
customStubPath: app_path('Console/Commands/stubs/make-module/migration.stub')
);
$migrationPath = $migrationCreator->create(Str::lower('create_'.Str::plural($this->moduleName).'_table'), $migrationsPath);
$migrationName = Str::afterLast($migrationPath, '/');
$this->info("Migration created: {$migrationName} created");
}
/**
* Make controller file
*
* @param string $controllersPath
*/
protected function makeController(string $controllersPath): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%sController', $controllersPath, $this->moduleName),
stubFile: app_path('Console/Commands/stubs/make-module/controller.stub'),
stubVariables: [
'NAMESPACE' => sprintf('App\\Modules\\%s\\Controllers', $this->moduleName),
'CONTROLLER_NAME' => $this->moduleName.'Controller',
]
);
$creationStatus
? $this->info("Controller created: {$this->moduleName} created")
: $this->info("Controller: {$this->moduleName} already exits");
}
/**
* Make repository file
*
* @param string $path
*/
protected function makeRepository(string $path): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $path, $this->moduleName.'Repository'),
stubFile: __DIR__.'/stubs/make-module/repository.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\Modules\%s\Repositories', $this->moduleName),
'MODULE_NAME' => ucfirst($this->moduleName),
'MODEL_NAMESPACE' => sprintf('App\Modules\%s\Models\%s', $this->moduleName, $this->moduleName),
],
);
$creationStatus
? $this->info("Repository created: {$this->moduleName} created")
: $this->info("Repository: {$this->moduleName} already exits");
}
/**
* Make nova resource file
*
* @param string $path
*/
public function makeNovaResource(string $path): void
{
$creationStatus = $this->createFileFromStub(
createFilePath: sprintf('%s/%s', $path, 'Nova'.$this->moduleName),
stubFile: __DIR__.'/stubs/make-module/nova-resource.stub',
stubVariables: [
'NAMESPACE' => sprintf('App\Modules\%s\Nova\Resources', $this->moduleName),
'MODEL_NAMESPACE' => sprintf('App\Modules\%s\Models\%s', $this->moduleName, $this->moduleName),
'MODEL_NAME_PLURAL' => Str::of($this->moduleName)->plural(),
'MODEL_NAME_SINGULAR' => Str::of($this->moduleName)->singular(),
'RESOURCE_NAME_SINGULAR' => 'Nova'.Str::of($this->moduleName)->singular(),
],
);
$creationStatus
? $this->info("Nova resource created: {$this->moduleName} created")
: $this->info("Nova resource: {$this->moduleName} already exits");
}
/**
* Build the directory for the class if necessary.
*
* @param string $path
* @return string
*/
protected function makeDirectory(string $path): string
{
if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true, true);
}
return $path;
}
/**
* Create a file from stub
*
* @param string $createFilePath
* @param string $stubFile
* @param array<string, string> $stubVariables
*/
protected function createFileFromStub(string $createFilePath, string $stubFile, array $stubVariables): int|bool
{
$contents = $this->getStubContents($stubFile, $stubVariables);
return $this->files->missing($createFilePath)
? $this->files->put($createFilePath.'.php', $contents)
: false;
}
/**
* Replace the stub variables(key) with the desire value
*
* @param string $stub
* @param array<string, string> $stubVariables
*/
protected function getStubContents(string $stub, array $stubVariables = []): string
{
$contents = (string) file_get_contents($stub);
foreach ($stubVariables as $search => $replace) {
$contents = str_replace('$'.$search.'$', $replace, $contents);
}
return $contents;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace $NAMESPACE$;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class $CONTROLLER_NAME$ extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request): void
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): void
{
//
}
/**
* Display the specified resource.
*/
public function show(Request $request): void
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request): void
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request): void
{
//
}
}

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('{{ table }}', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('{{ table }}');
}
};

View File

@@ -0,0 +1,11 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
class $CLASS_NAME$ extends Model
{
use HasUuids;
}

View File

@@ -0,0 +1,74 @@
<?php
namespace $NAMESPACE$;
use App\Nova\Resource;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
/**
* @template TModel of \$MODEL_NAMESPACE$
*
* @extends Resource<TModel>
*/
class $RESOURCE_NAME_SINGULAR$ extends Resource
{
/**
* The model the resource corresponds to.
*
* @var class-string<\$MODEL_NAMESPACE$>
*/
public static $model = \$MODEL_NAMESPACE$::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array<int, string>
*/
public static $search = [
'id',
];
/**
* The relationships that should be eager loaded on index queries.
*
* @var array<int, string>
*/
// public static $with = [];
/**
* Get the displayable label of the resource.
*/
public static function label(): string
{
return __('$MODEL_NAME_PLURAL$');
}
/**
* Get the displayable singular label of the resource.
*/
public static function singularLabel(): string
{
return __('$MODEL_NAME_SINGULAR$');
}
/**
* Get the fields displayed by the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array<int, \Laravel\Nova\Fields\FieldElement|\Laravel\Nova\Panel>
*/
public function fields(NovaRequest $request): array
{
return [
ID::make('id')->sortable(),
];
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace $NAMESPACE$;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use $MODEL_NAMESPACE$;
class $MODULE_NAME$Repository
{
/**
* $queryBuilder
*
* @var \Illuminate\Database\Eloquent\Builder<\$MODEL_NAMESPACE$>
*/
protected Builder $queryBuilder;
/**
* Model
*/
public static function model(): string
{
return $MODULE_NAME$::class;
}
/**
* Product repository
*/
public function __construct()
{
$this->queryBuilder = self::model()::query();
}
}