ifo/laravel-make-packager
Composer 安装命令:
composer require ifo/laravel-make-packager
包简介
README 文档
README
This package is a CLI tool that helps you build a fully structured package for a Laravel application without spending a lot of time. You no longer need to struggle with initializing the skeleton for your package. Instead, focus on writing the source code while Laravel Packager organizes the package structure for you.
Step 0: Pre-Installation Setup
Before installing, please add the necessary file to your root project. You can find the file and instructions at the following link:
Step 1: Install the Package
Run the following command to install the package:
composer require ifo/laravel-make-packager
Step 2: Dump Autoload
After installing the package, run the following command to autoload the package:
composer dump-autoload
The package has been successfully installed.
How to Create a Custom Package
Step 1: Create a New Package
Run the following command to create a new package:
php artisan package:make YourPackageName
This command will create the folder structure and necessary files for your package, including routes, ServiceProvider, and an AbstractController for enforcing rules and validations.
You can refer to the screenshot below:
Folder Structure
Here’s what the folder structure will look like:
--> packageName
--> composer.json
--> module.json
--> src
--> Config
--> Console
--> Database
--> Events
--> Http
--> Controllers
--> AbstractController // For rules and validations, extends in controllers
--> PackageNameController
--> Middleware
--> Requests
--> Jobs
--> Listeners
--> Models
--> Providers
--> ModuleServiceProvider
--> RouteServiceProvider
--> Resources
--> routes
--> V1.php
--> web.php
--> Test
-->Unit
-->Feature
Step 2: Register the Package
To register the package, follow the setup steps below:
Step 1: Create Package Directory
Create a packages folder and move the MakePackager directory inside it.
Step 2: Update Composer Autoload
Add the package namespace to the composer.json file under the psr-4 key:
"autoload": { "psr-4": { "Packages\\MakePackager\\": "packages/MakePackager/src" } }
Step 3: Register the Service Provider
-
For Laravel version below 10: Register the
ServiceProviderin theconfig/app.phpfile inside theprovidersarray:
'providers' => [ Packages\MakePackager\Providers\MakePackagerServiceProvider::class, ]
-
For Laravel version 10 and above: Register the
ServiceProviderin theapp/Providers/AppServiceProvider.phpfile in theregistermethod:
public function register(): void { $this->app->register(CustomPackageServiceProvider::class); }
Step 4: Initial Setup Completion
Run the following commands to complete the setup:
composer dump-autoload php artisan config:cache php artisan config:clear
Adding Middleware
If you want to automatically apply middleware authentication, add the CustomRouteServiceProvider. This will ensure that the middleware is added by default.
If you prefer not to use the custom middleware setup, you can remove the extension of CustomRouteServiceProvider and instead extend ServiceProvider directly.
MakePackager Artisan Commands
Here are a few custom artisan commands to create specific packages:
php artisan package:make-job YourFileName YourPackageName
to create jobs for a specific package
php artisan package:make-migration YourFileName YourPackageName
to create migration files for a specific package
php artisan package:make-listener YourFileName YourPackageName
to create listeners for a specific package
php artisan package:make-event YourFileName YourPackageName
to create events for a specific package
sudo php artisan package:make-test SamleTest Myo --feature
This command creates a test file in a specific package.
-
First Argument (
FileName): The name of the test file you want to create. -
Second Argument (
PackageName): The name of the package where the test file will be placed. -
Third Argument (
--feature): An optional flag. If provided, the test file will be created under theFeaturefolder. If omitted, the test file will be created under theUnitfolder by default.
This package has an additional feature: it will automatically register the test and unit scripts in the root project’s phpunit.xml file, allowing them to be executed smoothly.
More artisan commands will be added in future updates.
ifo/laravel-make-packager 适用场景与选型建议
ifo/laravel-make-packager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.32k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ifo/laravel-make-packager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ifo/laravel-make-packager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-26