moeen/photon-lumen
Lumen Extension for SRP (Single Responsibility Principle)
10
| Install | |
|---|---|
composer require moeen/photon-lumen |
|
| Latest Version: | v0.1 |
| PHP: | ^8.0 |
| License: | MIT |
| Last Updated: | Sep 20, 2021 |
| Links: | GitHub · Packagist |
Maintainer: moeen-basra
Photon
An Extension for the Lumen for SRP (Single Responsibility Principle).
How to use
- install the package using the following command
composer require moeen-basra/photon-lumen
- Open the file
bootstrap/app.phpand registerPhoton\Foundation\Providers\HttpServiceProvider
$app->register(Photon\Foundation\Providers\HttpServiceProvider::class);
- Open the file
app/Http/Controllers/Controller.phpand replace the following code
use Laravel\Lumen\Routing\Controller as BaseController;
with this
use Photon\Foundation\Controller as BaseController;
-
Open the file
app\Exceptions\Handlerextend it from\Photon\Foundation\Exceptions\Handler\Handler -
Now you have to can create the following directories in the
appfolder.
|-- app
| |-- Domains
| |-- Features
| |-- Operations
Great now you are good to go.
Here is a sample code for a controller serving the feature.
namespace App\Http\Controllers\Api\Auth;
use Illuminate\Http\JsonResponse;
use Photon\Foundation\Controller;
use App\Features\Api\Auth\RegisterFeature;
class AuthController extends Controller
{
public function __construct()
{
$this->middleware('auth:api', ['only' => 'me', 'logout', 'refresh']);
}
/**
* Register user
*
* @return JsonResponse
*/
public function register(): JsonResponse
{
return $this->serve(RegisterFeature::class);
}
}
Here is sample code for Feature running the jobs and operations
namespace App\Features\Api\Auth;
use Photon\Foundation\Feature;
use App\Operations\Auth\RegisterOperation;
use Photon\Domains\Http\Jobs\JsonResponseJob;
use App\Domains\Auth\Jobs\Register\ValidateRegisterRequestJob;
class RegisterFeature extends Feature
{
public function handle()
{
$input = $this->run(ValidateRegisterRequestJob::class);
$data = $this->run(RegisterOperation::class, compact('input'));
return $this->run(new JsonResponseJob($data));
}
}