evotic/make-extended
Composer 安装命令:
composer require evotic/make-extended
包简介
An extension to Laravel artisan make commands
README 文档
README
The Laravel Make Extended package provides additional make: commands that simplify common development tasks in Laravel, such as creating actions, DTOs (Data Transfer Objects), repositories, services, and more. This package aims to fill gaps in Laravel's built-in Artisan commands, offering enhanced tools to streamline development.
Developed to boost productivity and maintain code organization, these commands provide structure and separation of concerns for complex Laravel applications.
Key Features
- Enhanced
make:commands: Adds useful Artisan commands likemake:action,make:dto,make:repository, andmake:service. - Separation of concerns: Promotes clean architecture patterns like CQRS and DDD (Domain-Driven Design) by offering DTOs, actions, and repositories.
- Extendable: Easily customizable stubs for generated files. See the Customizing Stubs section for more information.
- Seamless integration: Works seamlessly with existing Laravel projects from version 9.x onwards.
Installation
To install the Laravel Make Extended package, follow these steps:
-
Install via Composer:
Run the following command to install the package via Composer:
composer require evotic/make-extended
-
Publish Configuration (Optional):
If you want to customize any aspect of the package, you can publish the configuration files:
php artisan vendor:publish --tag=make-extended-config
Usage
Once the package is installed, you can start using the new make: commands in your Laravel project.
For example, to create a new action class, simply run:
php artisan make:action YourAction
Each generated file will be placed in the appropriate folder, following Laravel’s naming conventions.
Available Commands
This package provides the following make: commands:
make:action
Creates a single-action class, which can be used to organize your business logic and simplify controllers. Typically used in a CQRS pattern.
Example:
php artisan make:action ProcessOrderAction
This generates the following file:
// app/Actions/ProcessOrderAction.php namespace App\Actions; class ProcessOrderAction { public function __invoke() { // } }
Use Case:
Single-action classes can be useful for organizing logic that```s reused across different parts of your application (such as processing an order, user registration, etc.).
make:dto
Generates a Data Transfer Object (DTO) class. DTOs are used to encapsulate data that is passed between layers of the application.
Example:
php artisan make:dto UserDto
This generates the following file:
// app/DTOs/UserDto.php namespace App\DTOs; class UserDto { public function __construct( // ) {} // Add your methods here }
Use Case:
DTOs are used to carry data between different layers of the application (e.g., from a controller to a service) while ensuring that the data structure is consistent and immutable.
make:repository
Creates a Repository class, useful for abstracting data access logic. Repositories are often used in service layers to handle database operations, ensuring that the domain logic is decoupled from the data source.
Example:
php artisan make:repository UserRepository
This generates the following file:
// app/Repositories/UserRepository.php namespace App\Repositories; class UserRepository { public function all() { // Fetch all users } public function find($id) { // Find a user by ID } public function create(array $data) { // Create a new user } public function update($id, array $data) { // Update an existing user } public function delete($id) { // Delete a user } }
Use Case:
Repositories provide an abstraction layer between the business logic and the database, allowing developers to swap out the data source without affecting the rest of the application.
make:service
Creates a Service class. Services contain the business logic of the application and typically call repositories or other services to perform their operations.
Example:
php artisan make:service PaymentService
This generates the following file:
// app/Services/PaymentService.php namespace App\Services; class PaymentService { public function __construct() { // } // Add your methods here }
Use Case:
Service classes are useful for isolating business logic, making it easier to maintain, test, and reuse across different parts of the application.
Customizing Stubs
If you need to customize the stubs generated by the make: commands, you can publish the stubs to your Laravel project by running:
php artisan vendor:publish --tag=make-extended-stubs
This will publish the stubs to the resources/stubs/make-extended directory in your Laravel application. You can then modify these stubs as needed, and the package will use the customized stubs instead of the default ones.
Example
To customize the Service.stub, you would find the file at: resources/stubs/make-extended/Service.stub.
Contributing
If you'd like to contribute to this project, feel free to submit pull requests or open issues on GitHub. Contributions, suggestions, and improvements are always welcome!
Important Links
- evotic Website: evotic.io
- Laravel Documentation: Laravel Docs
- CQRS Pattern: CQRS Documentation
- Data Transfer Objects (DTOs): DTO Pattern
License
This package is licensed under the MIT License. See the LICENSE file for more information.
evotic/make-extended 适用场景与选型建议
evotic/make-extended 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 263 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 evotic/make-extended 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evotic/make-extended 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 263
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-06