Skip to content

Commit

Permalink
feat: add middleware command
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed Jul 21, 2022
1 parent a52f06d commit f968f02
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Commands/MakeMiddlewareCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Regnerisch\LaravelBeyond\Commands;

use Illuminate\Console\Command;
use Regnerisch\LaravelBeyond\Resolvers\AppNameSchemaResolver;

class MakeMiddlewareCommand extends Command
{
protected $signature = 'beyond:make:middleware {name?} {--support} {--overwrite}';

protected $description = 'Make a new middleware';

public function handle(): void
{
try {
$name = $this->argument('name');
$support = $this->option('support');
$overwrite = $this->option('overwrite');

$stub = $support ? 'middleware.support.stub' : 'middleware.stub';
$directory = $support ? 'Packages/Laravel/Middleware' : 'Middleware';

$schema = (new AppNameSchemaResolver($this, $name, support: $support))->handle();

beyond_copy_stub(
$stub,
$schema->path($directory),
[
'{{ namespace }}' => $schema->namespace(),
'{{ className }}' => $schema->className(),
],
$overwrite
);

$this->info('Middleware created.');
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
}
}
2 changes: 2 additions & 0 deletions src/LaravelBeyondServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Regnerisch\LaravelBeyond\Commands\MakeEventCommand;
use Regnerisch\LaravelBeyond\Commands\MakeJobCommand;
use Regnerisch\LaravelBeyond\Commands\MakeListenerCommand;
use Regnerisch\LaravelBeyond\Commands\MakeMiddlewareCommand;
use Regnerisch\LaravelBeyond\Commands\MakeModelCommand;
use Regnerisch\LaravelBeyond\Commands\MakePolicyCommand;
use Regnerisch\LaravelBeyond\Commands\MakeQueryBuilderCommand;
Expand Down Expand Up @@ -40,6 +41,7 @@ public function boot()
MakeEventCommand::class,
MakeJobCommand::class,
MakeListenerCommand::class,
MakeMiddlewareCommand::class,
MakeModelCommand::class,
MakePolicyCommand::class,
MakeQueryBuilderCommand::class,
Expand Down
14 changes: 14 additions & 0 deletions stubs/middleware.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\{{ namespace }}\Middleware;

use Closure;
use Illuminate\Http\Request;

class {{ className }}
{
public function handle(Request $request, Closure $next)
{
return $next($request);
}
}
14 changes: 14 additions & 0 deletions stubs/middleware.support.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Support\Packages\Laravel\Middleware;

use Closure;
use Illuminate\Http\Request;

class {{ className }}
{
public function handle(Request $request, Closure $next)
{
return $next($request);
}
}

0 comments on commit f968f02

Please sign in to comment.