yangweijie / thinkphp-package-tools
thinkphp 扩展包开发工具
v1.0.8
2025-05-05 07:58 UTC
Requires
- php: ^8.1
- illuminate/broadcasting: ^10.0|^11.0|^12.0
- illuminate/contracts: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/events: ^10.0|^11.0|^12.0
- illuminate/process: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- phpoption/phpoption: ^1.9
- topthink/framework: ^v6.1 | ^v8.0
- vlucas/phpdotenv: ^5.6
README
参考laravel-package-tools 实现的开发ThinkPHP扩展的包
This package contains a PackageService
that you can use in your packages to easily register config files,
migrations, and more.
Here's an example of how it can be used.
use Spatie\LaravelPackageTools\PackageServiceProvider; use Spatie\LaravelPackageTools\Package; use MyPackage\ViewComponents\Alert; use Spatie\LaravelPackageTools\Commands\Concerns; class YourPackageServiceProvider extends PackageServiceProvider { public function configurePackage(Package $package): void { $package ->name('your-package-name') ->hasConfigFile() ->hasViews() ->hasViewComponent('spatie', Alert::class) // 仅laravel 迁移过来的扩展 ->hasViewComposer('*', MyViewComposer::class) // 仅laravel 迁移过来的扩展 ->sharesDataWithAllViews('downloads', 3) // 仅laravel 迁移过来的扩展 ->hasTranslations() // 仅laravel 迁移过来的扩展 ->hasAssets() ->publishesServiceProvider('MyProviderName') ->hasRoute('web') ->hasMigration('create_package_tables') ->hasCommand(YourCoolPackageCommand::class) // 无需在 composer.json 中注册命令 ->hasInstallCommand(function(InstallCommand $command) { // 添加独立的安装命令 $command ->publishConfigFile() ->publishAssets() ->publishMigrations() ->copyAndRegisterServiceProviderInApp() ->askToStarRepoOnGitHub(); }); } }
Under the hood it will do the necessary work to register the necessary things and make all sorts of files publishable.