Skip to content

Commit f006e43

Browse files
Autogenerated stubs
1 parent cf1e45b commit f006e43

19 files changed

+878
-0
lines changed

stubs/action.stub

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Application\Actions\{{PluralDomainName}};
4+
5+
use App\Application\Actions\BaseAction;
6+
use App\Domain\{{PluralDomainName}}\{{DomainName}};
7+
use App\Infrastructure\API\Requests\{{RequestName}};
8+
use Illuminate\Support\Facades\DB;
9+
10+
class {{ActionName}} extends BaseAction
11+
{
12+
public function execute({{RequestName}} $request): {{DomainName}}
13+
{
14+
return DB::transaction(function () use ($request) {
15+
${{domainVariable}} = {{DomainName}}::create($request->validated());
16+
17+
// Additional business logic here
18+
19+
return ${{domainVariable}};
20+
});
21+
}
22+
}

stubs/base-action.stub

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Application\Actions;
4+
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Log;
7+
8+
abstract class BaseAction
9+
{
10+
/**
11+
* Execute the action with transaction support.
12+
*/
13+
protected function executeInTransaction(callable $callback)
14+
{
15+
return DB::transaction($callback);
16+
}
17+
18+
/**
19+
* Log action execution.
20+
*/
21+
protected function log(string $message, array $context = []): void
22+
{
23+
Log::info($message, array_merge([
24+
'action' => static::class,
25+
], $context));
26+
}
27+
28+
/**
29+
* Log error during action execution.
30+
*/
31+
protected function logError(string $message, \Throwable $exception, array $context = []): void
32+
{
33+
Log::error($message, array_merge([
34+
'action' => static::class,
35+
'exception' => $exception->getMessage(),
36+
'file' => $exception->getFile(),
37+
'line' => $exception->getLine(),
38+
], $context));
39+
}
40+
}

stubs/base-controller.stub

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace App\Infrastructure\API\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Validation\ValidatesRequests;
7+
use Illuminate\Http\JsonResponse;
8+
use Illuminate\Routing\Controller as BaseController;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, ValidatesRequests;
13+
14+
/**
15+
* Return a success JSON response.
16+
*/
17+
protected function successResponse(mixed $data = null, string $message = 'Success', int $status = 200): JsonResponse
18+
{
19+
return response()->json([
20+
'success' => true,
21+
'data' => $data,
22+
'message' => $message
23+
], $status);
24+
}
25+
26+
/**
27+
* Return an error JSON response.
28+
*/
29+
protected function errorResponse(string $message = 'Error', int $status = 400, mixed $errors = null): JsonResponse
30+
{
31+
return response()->json([
32+
'success' => false,
33+
'message' => $message,
34+
'errors' => $errors
35+
], $status);
36+
}
37+
38+
/**
39+
* Return a paginated JSON response.
40+
*/
41+
protected function paginatedResponse($data, string $message = 'Success'): JsonResponse
42+
{
43+
return response()->json([
44+
'success' => true,
45+
'data' => $data->items(),
46+
'pagination' => [
47+
'current_page' => $data->currentPage(),
48+
'last_page' => $data->lastPage(),
49+
'per_page' => $data->perPage(),
50+
'total' => $data->total(),
51+
'from' => $data->firstItem(),
52+
'to' => $data->lastItem(),
53+
],
54+
'message' => $message
55+
]);
56+
}
57+
}

stubs/base-model.stub

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Domain\Shared;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
9+
abstract class BaseModel extends Model
10+
{
11+
use HasFactory, SoftDeletes;
12+
13+
/**
14+
* Indicates if the model should be timestamped.
15+
*/
16+
public $timestamps = true;
17+
18+
/**
19+
* The attributes that should be cast.
20+
*/
21+
protected $casts = [
22+
'created_at' => 'datetime',
23+
'updated_at' => 'datetime',
24+
'deleted_at' => 'datetime',
25+
];
26+
27+
/**
28+
* The attributes that aren't mass assignable.
29+
*/
30+
protected $guarded = ['id'];
31+
32+
/**
33+
* Get the route key for the model.
34+
*/
35+
public function getRouteKeyName(): string
36+
{
37+
return 'id';
38+
}
39+
40+
/**
41+
* Boot the model.
42+
*/
43+
protected static function boot(): void
44+
{
45+
parent::boot();
46+
47+
// Add global scopes or model events here
48+
}
49+
}

stubs/base-request.stub

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Infrastructure\API\Requests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
use Illuminate\Contracts\Validation\Validator;
7+
use Illuminate\Http\Exceptions\HttpResponseException;
8+
9+
abstract class BaseRequest extends FormRequest
10+
{
11+
/**
12+
* Handle a failed validation attempt.
13+
*/
14+
protected function failedValidation(Validator $validator): void
15+
{
16+
throw new HttpResponseException(
17+
response()->json([
18+
'success' => false,
19+
'message' => 'Validation errors occurred',
20+
'errors' => $validator->errors()
21+
], 422)
22+
);
23+
}
24+
25+
/**
26+
* Get the validation rules that apply to the request.
27+
*/
28+
abstract public function rules(): array;
29+
30+
/**
31+
* Prepare the data for validation.
32+
*/
33+
protected function prepareForValidation(): void
34+
{
35+
// Override this method to modify data before validation
36+
}
37+
}

stubs/base-service.stub

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Application\Services;
4+
5+
use Illuminate\Support\Facades\Cache;
6+
use Illuminate\Support\Facades\Log;
7+
8+
abstract class BaseService
9+
{
10+
/**
11+
* Default cache TTL in seconds (1 hour).
12+
*/
13+
protected int $cacheTtl = 3600;
14+
15+
/**
16+
* Cache a result with the given key.
17+
*/
18+
protected function cache(string $key, callable $callback, ?int $ttl = null)
19+
{
20+
return Cache::remember($key, $ttl ?? $this->cacheTtl, $callback);
21+
}
22+
23+
/**
24+
* Forget cached result by key.
25+
*/
26+
protected function forgetCache(string $key): bool
27+
{
28+
return Cache::forget($key);
29+
}
30+
31+
/**
32+
* Log service operation.
33+
*/
34+
protected function log(string $message, array $context = []): void
35+
{
36+
Log::info($message, array_merge([
37+
'service' => static::class,
38+
], $context));
39+
}
40+
41+
/**
42+
* Log error during service operation.
43+
*/
44+
protected function logError(string $message, \Throwable $exception, array $context = []): void
45+
{
46+
Log::error($message, array_merge([
47+
'service' => static::class,
48+
'exception' => $exception->getMessage(),
49+
'file' => $exception->getFile(),
50+
'line' => $exception->getLine(),
51+
], $context));
52+
}
53+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Infrastructure\Exceptions;
4+
5+
use Exception;
6+
7+
class BusinessLogicException extends Exception
8+
{
9+
public function __construct(string $message = "Business logic violation", int $code = 409, ?\Throwable $previous = null)
10+
{
11+
parent::__construct($message, $code, $previous);
12+
}
13+
14+
/**
15+
* Render the exception into an HTTP response.
16+
*/
17+
public function render($request)
18+
{
19+
return response()->json([
20+
'success' => false,
21+
'message' => $this->getMessage(),
22+
'error_type' => 'business_logic_exception'
23+
], $this->getCode());
24+
}
25+
}

stubs/config.stub

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Clean Architecture Configuration
7+
|--------------------------------------------------------------------------
8+
|
9+
| This file contains configuration options for the Laravel Clean
10+
| Architecture package.
11+
|
12+
*/
13+
14+
'default_namespace' => 'App',
15+
16+
'directories' => [
17+
'domain' => 'app/Domain',
18+
'application' => 'app/Application',
19+
'infrastructure' => 'app/Infrastructure',
20+
],
21+
22+
'stubs' => [
23+
'path' => base_path('stubs/clean-architecture'),
24+
],
25+
26+
'auto_discovery' => [
27+
'enabled' => true,
28+
'paths' => [
29+
'app/Application/Actions',
30+
'app/Application/Services',
31+
'app/Domain',
32+
],
33+
],
34+
35+
'validation' => [
36+
'strict_mode' => false,
37+
'custom_messages' => true,
38+
],
39+
40+
'logging' => [
41+
'enabled' => true,
42+
'channel' => 'daily',
43+
],
44+
];

0 commit comments

Comments
 (0)