lowel/laravel-service-maker 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

lowel/laravel-service-maker

最新稳定版本:1.0.1

Composer 安装命令:

composer require lowel/laravel-service-maker

包简介

A package for Laravel 9+ that helps generate layered services according to the Interface-Service-Factory pattern using laravel's built-in DI.

README 文档

README

This Laravel package provides Artisan commands to quickly generate service and repository classes with their corresponding interfaces and factories following a standardized structure.

Installation

  1. Install the package via Composer:
composer require lowel/laravel-service-maker
  1. The package will automatically register its service provider. If you need to publish the configuration file:
php artisan vendor:publish --provider="Lowel\\LaravelServiceMaker\\LaravelServiceMakerProvider" --tag="config"

Commands

Create a new service

php artisan lowel:make:service {name} {--s|singleton}

Options:

  • name: The name of the service (e.g., Payment will create PaymentService)
  • --s|singleton: Create the service as a singleton

Example:

php artisan lowel:make:service Payment

This will generate:

  • App/Services/Payment/PaymentService.php
  • App/Services/Payment/PaymentServiceInterface.php
  • App/Services/Payment/PaymentServiceFactory.php

Create a new repository

php artisan lowel:make:repository {name} {--s|singleton}

Options:

  • name: The name of the repository (e.g., User will create UserRepository)
  • --s|singleton: Create the repository as a singleton

Example:

php artisan lowel:make:repository User --singleton

This will generate:

  • App/Repositories/User/UserRepository.php
  • App/Repositories/User/UserRepositoryInterface.php
  • App/Repositories/User/UserRepositoryFactory.php

File Structure

The package follows this directory structure:

app/
├── Repositories/
│   ├── {RepositoryName}/
│   │   ├── {RepositoryName}Repository.php
│   │   ├── {RepositoryName}RepositoryInterface.php
│   │   └── {RepositoryName}RepositoryFactory.php
└── Services/
    ├── {ServiceName}/
    │   ├── {ServiceName}Service.php
    │   ├── {ServiceName}ServiceInterface.php
    │   └── {ServiceName}ServiceFactory.php

Usage

After generating the classes, you can use them through Laravel's dependency injection:

use App\Services\Payment\PaymentServiceInterface;
use App\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Facades\App;

// Using app() helper
$service = app(PaymentServiceInterface::class);
$repository = app(UserRepositoryInterface::class);

// Using App facade
$service = App::make(PaymentServiceInterface::class);

// Using constructor injection
public function __construct(
    PaymentServiceInterface $paymentService,
    UserRepositoryInterface $userRepository
) {
    // ...
}

The package automatically registers the interfaces in Laravel's container, binding them to their concrete implementations.

Configuration

You can customize the generation behavior by publishing and modifying the package configuration file:

php artisan vendor:publish --provider="Lowel\\LaravelServiceMaker\\LaravelServiceMakerProvider" --tag="config"

This will create config/service-maker.php where you can configure:

  • Base paths
  • Class mapping
  • Formatting

Requirements

  • PHP 8.3+
  • Laravel 9+

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-06