moeen/photon 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

moeen/photon

最新稳定版本:1.0.0

Composer 安装命令:

composer require moeen/photon

包简介

Laravel micro framework for SRP (Single Responsibility Principle)

README 文档

README

License

Photon is a lightweight extension framework for Laravel that implements the Single Responsibility Principle (SRP) design pattern. It draws inspiration from the Lucid Framework.

How to Use

To use Photon in your Laravel project, follow these steps:

  1. Open your terminal and execute the following command:
composer require moeen-basra/photon
  1. Open the App\Http\Controllers\Controller class and replace the following code:
use Illuminate\Routing\Controller as BaseController;

with:

use MoeenBasra\Photon\Http\Controller as BaseController;
  1. Extend the app\Exceptions\Handler class with the following class:
MoeenBasra\Photon\Foundation\Exceptions\Handler\Handler

Alternatively, you can use the following traits in your existing exception handler:

use MoeenBasra\Photon\Concerns\Marshal;
use MoeenBasra\Photon\Concerns\ActionRunner;

In the render method, execute the following job if the request accepts application\json:

$message = $exception->getMessage();
$code = $exception->getCode();
$errors = ($exception instanceof \Illuminate\Validation\ValidationException) ? $exception->errors() : [];

if ($request->expectsJson()) {
    return $this->run(JsonErrorResponseJob::class, [
        'message' => $message,
        'errors' => $errors,
        'status' => ($code < 100 || $code >= 600) ? 400 : $code,
    ]);
}
  1. Create the following directories inside the app folder:
|-- app
|  |-- Actions
|  |-- Features
|  |-- Operations
  1. Here's an example code for a controller that serves the feature:
namespace App\Http\Controllers\Api\Auth;

use App\Features\Api\Auth\RegisterFeature;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use MoeenBasra\Photon\Http\Controller;

class AuthController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api', ['only' => ['me', 'logout']]);
    }

    public function register(Request $request): JsonResponse
    {
        return $this->serve(RegisterFeature::class, [
            'data' => $request->validated(),
        ]);
    }
}
  1. Lastly, here's an example code for a feature that runs the job:
namespace App\Features\Api\Auth;

use App\Operations\Auth\RegisterOperation;
use Illuminate\Http\JsonResponse;
use Photon\Actions\JsonResponseAction;
use MoeenBasra\Photon\Features\Feature;

final class RegisterFeature extends Feature
{
    public function __construct(
        readonly private array $input
    ){}
    
    public function handle(): JsonResponse
    {
        $data = $this->run(RegisterOperation::class, [
            'input' => $this->input
        ]);

        return $this->run(new JsonResponseAction($data));
    }
}

License

Photon is released under the MIT License. See the LICENSE file for details.

Contact

You can reach me here moeen.basra@gamil.com

统计信息

  • 总下载量: 1.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固