承接 si-dev/laravel-layered 相关项目开发

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

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

si-dev/laravel-layered

Composer 安装命令:

composer require si-dev/laravel-layered

包简介

Package for using layered structure in Laravel.

README 文档

README

StyleCI License: MIT

This is an open source Laravel package which is intended primarily for those developers who uses the layered structure, like:

model - repository - service - controller

or

model - service - controller.

Actually, the package allows to create any classes, interfaces, traits that you want.

Features

  • list of new artisan make commands: class, trait, contract, repository, service, layered-bunch
  • almost every command (except trait) has options
  • you can inherit abstract package classes, but if that doesn't suit you, you can create your base classes and inherit them
  • the same is about interfaces - you can implement or extend the provided interfaces or write your own base interfaces

Installation

composer require si-dev/laravel-layered

Then run command:

php artisan vendor:publish --provider="SiDev\LaravelLayered\LayeredServiceProvider"

Package will use its own base repository and service classes and interfaces, but if you want to use yours, you can redefine them in config/layered.php.

Artisan commands and usage

make:contract

creates a contract (interface) with the given name. It is also possible to specify an extensible interface.

Options

-e, --extends=EXTENDS

creates a contract that extends another specified contract

Note: the contract that extends will not be created

Examples

php artisan make:contract ProductInterface
php artisan make:contract ProductInterface --extends=AdapterInterface

make:class

creates a class with the specified name. Using options you can create class with injected dependency and/or implementing the specified interface.

Options

-c, --contract[=CONTRACT]

If the name of the contract is specified, the command will create an interface with the specified name and a class that implements the created interface. Otherwise, a contract with the default name (classname + Interface) will be created and a class that implements the created interface.

-d, --dependency=DEPENDENCY

creates a class with the specified name and injects the specified dependency into the constructor.

--dependencyName=DEPENDENCYNAME

this option can only be used with the dependency option. Used if you want to name the injection dependency variable with a different name.

Note: dependency and dependencyName will not create a dependency (class or interface). You should create it manually or using command.

Examples

php artisan make:class Adapters/DocumentAdapter
php artisan make:class Adapters/DocumentAdapter -c
php artisan make:class Adapters/DocumentAdapter -c -dDocument
php artisan make:class Adapters/DocumentAdapter  --dependency=DocumentInterface --dependencyName=document

make:repository

creates a repository with the specified name. It also allows to extends base repository class, create and implement contract, inject the specified model.

Options

-e, --extends[=EXTENDS]

extends the specified class. If the name of the class to extend is not defined, it extends the base repository class that defined in package config.

-m, --model=MODEL

inject the model you specify. Note: the model will not be created, you should create it with appropriate command or manually.

-c, --contract

creates and implements the contract for the repository class

All repositories will be placed in the directory App\Repositories. All contracts you can find in the folder App\Contracts\Repositories.

Examples

php artisan make:repository ProductRepository
php artisan make:repository ProductRepository -c
php artisan make:repository ProductRepository -c -e
php artisan make:repository ProductRepository -c -e --model=Product

Base repository interface and class contain the next methods:

  • get($columns = ['*'])
  • find($id, array $columns = ['*'])
  • findWhere(array $where, array $columns = ['*'])
  • firstWhere(array $where, $columns = ['*'])
  • create(array $attributes)
  • update($id, array $attributes)
  • updateWhere(array $where, array $attributes)
  • delete($id)
  • deleteWhere(array $where)

In addtition base repository class has magic __call method. So you can use any Eloquent model method you need.

make:service

creates service class in the App\Services folder. Also you can inject repository or model, extends base service class, implement contract.

Options

-e, --extends[=EXTENDS]

extends the specified class. If the name of the class to extend is not defined, it extends the base service class that defined in package config.

-r, --repository[=REPOSITORY]

injects repository class or interface.

-m, --model[=MODEL]

injects the specified model.

Notice: you can use either the repository or the model, but not both options together.

-c, --contract

creates and implements the contract for the service class

Examples

php artisan make:service ProductService
php artisan make:service ProductService --model=Product
php artisan make:service ProductService -c
php artisan make:service ProductService -c -e
php artisan make:service ProductService -c -e --repository=ProductRepository

make:layered-bunch

creates bunch of classes for layered structure. As the result the next ones will be created:

  • model
  • factory
  • migration
  • repository contract that extends base repository contract
  • repository class that extends base repository class and implements the contract that was created on the previous step. Also model will be injected in this class
  • service contract that extends base service contract
  • service class that extends base service class and implements the contract created on the previous step. Also repository contract will be injected

Notice this command only creates contracts and classes, but does not bind abstract to concrete implementation. You should do it manually in AppServiceProvider or other service provider!

Examples

php artisan make:layered-bunch Product

make:trait

creates a trait with the specified name. There is no custom options for this command.

Examples

php artisan make:trait Taggable

License

laravel-layered is open-source package licensed under the MIT license

si-dev/laravel-layered 适用场景与选型建议

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

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

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

围绕 si-dev/laravel-layered 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-19