承接 pixielity/laravel-service-provider 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pixielity/laravel-service-provider

Composer 安装命令:

composer require pixielity/laravel-service-provider

包简介

Base infrastructure for modular service providers with traits, interfaces, and enums for Laravel applications.

README 文档

README

ServiceProvider

Service Provider Package

A base service provider package for Pixielity modules, providing common functionality and conventions for registering services, configurations, routes, migrations, and more.

Features

  • Base Service Provider - Abstract base class for all module providers
  • Auto-Discovery - Automatic registration of common module components
  • Configuration Publishing - Easy config file publishing
  • Migration Loading - Automatic migration registration
  • Route Registration - Convention-based route loading
  • View Registration - Automatic view namespace registration
  • Translation Loading - i18n support
  • Command Registration - Artisan command auto-discovery
  • Event Listeners - Automatic event listener registration
  • Middleware Registration - Easy middleware registration
  • Policy Registration - Automatic policy discovery

Installation

composer require pixielity/laravel-service-provider

Usage

Creating a Module Service Provider

Extend the base service provider:

<?php

namespace Pixielity\YourModule\Providers;

use Pixielity\Support\Str;
use Pixielity\ServiceProvider\Providers\ServiceProvider;

class YourModuleServiceProvider extends ServiceProvider
{
    /**
     * Module namespace for auto-discovery
     */
    protected string $moduleNamespace = 'Pixielity\\YourModule';

    /**
     * Module name for paths
     */
    protected string $moduleName = 'your-module';

    /**
     * Register services
     */
    public function register(): void
    {
        parent::register();

        // Register your bindings
        $this->registerBindings();
    }

    /**
     * Bootstrap services
     */
    public function boot(): void
    {
        parent::boot();

        // Additional boot logic
    }
}

Auto-Discovery Features

The base service provider automatically discovers and registers:

1. Configuration Files

Place config files in config/ directory:

your-module/
  config/
    your-module.php

They will be automatically published and merged.

2. Migrations

Place migrations in src/Migrations/ directory:

your-module/
  src/
    Migrations/
      2026_01_01_000000_create_table.php

They will be automatically loaded.

3. Routes

Place route files in routes/ directory:

your-module/
  routes/
    api.php      # API routes
    web.php      # Web routes
    console.php  # Console routes

They will be automatically registered with appropriate middleware.

4. Views

Place views in resources/views/ directory:

your-module/
  resources/
    views/
      index.blade.php

Access with namespace: view('your-module::index')

5. Translations

Place translations in resources/lang/ directory:

your-module/
  resources/
    lang/
      en/
        messages.php

Access with namespace: __('your-module::messages.key')

6. Commands

Place commands in src/Console/Commands/ directory:

your-module/
  src/
    Console/
      Commands/
        YourCommand.php

They will be automatically registered.

Configuration

Module Structure

Follow this structure for auto-discovery:

your-module/
├── config/
│   └── your-module.php
├── resources/
│   ├── views/
│   │   └── index.blade.php
│   └── lang/
│       └── en/
│           └── messages.php
├── routes/
│   ├── api.php
│   ├── web.php
│   └── console.php
├── src/
│   ├── Console/
│   │   └── Commands/
│   ├── Controllers/
│   ├── Events/
│   ├── Listeners/
│   ├── Middleware/
│   ├── Migrations/
│   ├── Models/
│   ├── Policies/
│   ├── Providers/
│   │   └── YourModuleServiceProvider.php
│   ├── Repositories/
│   └── Services/
└── composer.json

Advanced Usage

Custom Configuration Publishing

protected function registerConfig(): void
{
    $configPath = $this->getModulePath('config/your-module.php');

    $this->publishes([
        $configPath => config_path('your-module.php'),
    ], 'your-module-config');

    $this->mergeConfigFrom($configPath, 'your-module');
}

Custom Route Registration

protected function registerRoutes(): void
{
    if ($this->app->routesAreCached()) {
        return;
    }

    Route::middleware('api')
        ->prefix('api/v1')
        ->group($this->getModulePath('routes/api.php'));

    Route::middleware('web')
        ->group($this->getModulePath('routes/web.php'));
}

Custom Migration Loading

protected function registerMigrations(): void
{
    $this->loadMigrationsFrom($this->getModulePath('src/Migrations'));
}

Custom View Registration

protected function registerViews(): void
{
    $viewPath = $this->getModulePath('resources/views');

    $this->loadViewsFrom($viewPath, 'your-module');

    $this->publishes([
        $viewPath => resource_path('views/vendor/your-module'),
    ], 'your-module-views');
}

Custom Translation Loading

protected function registerTranslations(): void
{
    $langPath = $this->getModulePath('resources/lang');

    $this->loadTranslationsFrom($langPath, 'your-module');

    $this->publishes([
        $langPath => resource_path('lang/vendor/your-module'),
    ], 'your-module-translations');
}

Command Registration

protected function registerCommands(): void
{
    if ($this->app->runningInConsole()) {
        $this->commands([
            YourCommand::class,
            AnotherCommand::class,
        ]);
    }
}

Event Listener Registration

protected function registerEventListeners(): void
{
    Event::listen(
        YourEvent::class,
        YourListener::class
    );
}

protected function registerMiddleware(): void { $router = $this->app[ContainerToken::ROUTER];

$router->aliasMiddleware('your-middleware', YourMiddleware::class);

$router->pushMiddlewareToGroup('api', YourMiddleware::class);

}


### Policy Registration

```php
protected function registerPolicies(): void
{
    Gate::policy(YourModel::class, YourPolicy::class);
}

Helper Methods

Get Module Path

$path = $this->getModulePath('config/your-module.php');

Get Module Namespace

$namespace = $this->getModuleNamespace('Controllers');
// Returns: Pixielity\YourModule\Controllers

Check if Running in Console

if ($this->app->runningInConsole()) {
    // Console-specific logic
}

Publish Assets

$this->publishes([
    $this->getModulePath('public') => public_path('vendor/your-module'),
], 'your-module-assets');

Publishing

Publish Configuration

bin/laravel vendor:publish --tag=your-module-config

Publish Views

bin/laravel vendor:publish --tag=your-module-views

Publish Translations

bin/laravel vendor:publish --tag=your-module-translations

Publish Assets

bin/laravel vendor:publish --tag=your-module-assets

Publish Everything

bin/laravel vendor:publish --provider="Pixielity\YourModule\Providers\YourModuleServiceProvider"

Testing

use Orchestra\Testbench\TestCase;

class ServiceProviderTest extends TestCase
{
    protected function getPackageProviders($app)
    {
        return [
            YourModuleServiceProvider::class,
        ];
    }

    public function test_config_is_registered()
    {
        $this->assertNotNull(config('your-module'));
    }

    public function test_routes_are_registered()
    {
        $this->assertTrue(Route::has('your-module.index'));
    }

    public function test_views_are_registered()
    {
        $this->assertTrue(View::exists('your-module::index'));
    }

    public function test_commands_are_registered()
    {
        $this->assertTrue(Artisan::has('your-module:command'));
    }
}

Best Practices

1. Follow Naming Conventions

// ✅ Good
protected string $moduleName = 'your-module';
protected string $moduleNamespace = 'Pixielity\\YourModule';

// ❌ Bad
protected string $moduleName = 'YourModule';

2. Use Auto-Discovery

// ✅ Good - Let base provider handle it
public function boot(): void
{
    parent::boot(); // Handles migrations, views, etc.
}

// ❌ Bad - Manual registration
public function boot(): void
{
    $this->loadMigrationsFrom(__DIR__ . '/../Migrations');
    $this->loadViewsFrom(__DIR__ . '/../../resources/views', 'your-module');
}

3. Register Bindings in register()

// ✅ Good
public function register(): void
{
    parent::register();
    $this->registerBindings();
}

// ❌ Bad
public function boot(): void
{
    $this->app->singleton(...); // Should be in register()
}

4. Use Deferred Providers When Possible

class YourModuleServiceProvider extends ServiceProvider implements DeferrableProvider
{
    public function provides()
    {
        return [
            YourServiceInterface::class,
        ];
    }
}

5. Organize by Responsibility

protected function registerBindings(): void { }
protected function registerCommands(): void { }
protected function registerEventListeners(): void { }
protected function registerMiddleware(): void { }
protected function registerPolicies(): void { }

Common Patterns

Module with API Routes

class YourModuleServiceProvider extends ServiceProvider
{
    protected string $moduleName = 'your-module';

    protected function registerRoutes(): void
    {
        Route::prefix('api/v1')
            ->middleware('api')
            ->group($this->getModulePath('routes/api.php'));
    }
}

Module with Commands

class YourModuleServiceProvider extends ServiceProvider
{
    protected function registerCommands(): void
    {
        if ($this->app->runningInConsole()) {
            $this->commands([
                Commands\InstallCommand::class,
                Commands\SyncCommand::class,
            ]);
        }
    }
}

Module with Events

class YourModuleServiceProvider extends ServiceProvider
{
    protected function registerEventListeners(): void
    {
        Event::listen(
            Events\ModelCreated::class,
            Listeners\SendNotification::class
        );
    }
}

Troubleshooting

Routes Not Loading

  1. Check routes file exists in routes/ directory
  2. Verify route file name (api.php, web.php)
  3. Clear route cache: bin/laravel route:clear

Views Not Found

  1. Check views exist in resources/views/
  2. Verify view namespace matches module name
  3. Clear view cache: bin/laravel view:clear

Config Not Loading

  1. Check config file exists in config/
  2. Clear config cache: bin/laravel config:clear
  3. Verify config file name matches module name

License

This package is proprietary software developed by Pixielity.

Support

For support, please contact the development team or open an issue in the project repository.

pixielity/laravel-service-provider 适用场景与选型建议

pixielity/laravel-service-provider 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「module」 「service-provider」 「laravel」 「traits」 「infrastructure」 「modular-architecture」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pixielity/laravel-service-provider 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pixielity/laravel-service-provider 我们能提供哪些服务?
定制开发 / 二次开发

基于 pixielity/laravel-service-provider 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08