PHP code example of yangweijie / thinkphp-package-tools

1. Go to this page and download the library: Download yangweijie/thinkphp-package-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yangweijie / thinkphp-package-tools example snippets


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();
            });
    }
}