propaysystems/laravel-base-repositories 问题修复 & 功能扩展

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

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

propaysystems/laravel-base-repositories

Composer 安装命令:

composer require propaysystems/laravel-base-repositories

包简介

Base elequent repositories with interface for common queries.

README 文档

README

Propay Systems

Base elequent repositories with interfaces for common queries.

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

UNDER DEVELOPMENT AND TESTING - WE WILL ADD PROPER DOCUMENTATION WITH v1 STABLE RELEASE

This is the base classes & helper commands for the repository pattern we use. In your own repository classes you have to extend the BaseRepository and implement your custom interface. In your custom interface you have to extend the BaseRepositoryInterface. This will give you a collection of commonly used queries and function that you don't need to duplicate each time.

class AddressRepository extends BaseRepository implements AddressRepositoryInterface
interface AddressRepositoryInterface extends BaseRepositoryInterface

Requirements

PHP 8.0+
Laravel 8+

Version Compatibility

Laravel BaseRepositories
8.x 0.0.7
9.x 0.0.3
10.x 0.0.8

Installation

You can install the package via composer:

composer require propaysystems/laravel-base-repositories

You can publish the config file with:

php artisan vendor:publish --tag="laravel-base-repositories-config"

Configuration

We create the service and repositories in the app folder of laravel to make use of laravels auto loading functionality.

Service

The default path for createing services will be in the App\Services folder. If the folder does not exist it will be created.

If you want to overwrite default path for the service you can add a ENV variable and specify your custom path.

BASE_SERVICE_PATH="App\MyServiceFolder"

The base name that will be appended to the class that is created by default, it will append Service. So if you create a User -s service the file that gets created will be UserService

APPEND_SERVICE_NAME="Service"

Repository

The default path for createing repositories will be in the App\Repositories folder. If the folder does not exist it will be created.

If you want to overwrite default path for the repository you can add a ENV variable and specify your custom path.

BASE_REPOSITORY_PATH="App\MyRepositoryFolder"

The base name that will be appended to the class that is created by default, it will append Repository. So if you create a User -r service the file that gets created will be UserRepository & UserRepositoryInterface

APPEND_REPOSITORY_NAME="Repository"

Usage

Creating a Service

The service class is where all the domain logic will be created. This makes it easier to reuse business logic in the controllers, API, commands etc

  1. Creating a service class:
php artisan base:create Users/User --service
or
php artisan base:create Users/User -s

Running this command will create a new service class in the App\Services\ folders.

The rule is to split every service into its own related folders so the above command will actually create a file in:

  • App\Services\Users\UserService.php

Injecting a Repository

❕ Remember to dependancy inject your repositories you want to use into the __construct method of your service like the example below.

PHP 8.1 & above using constructor promotion
public function __construct(
    protected UserRepositoryInterface $userRepository,
)
{}

or 

PHP 8.0 & below
protected UserRepositoryInterface $userRepository;

public function __construct(
    UserRepositoryInterface $userRepository,
)
{
    $this->userRepository = $userRepository;
}

Creating a Repository

  1. Creating a repository class:
php artisan base:create Users/User --repository --model=App/Models/Users/User
or
php artisan base:create Users/User -r --model=App/Models/Users/User

Running this command will create a repository class with its related interface in the App\Repositories & App\Repository\UserRepository\Interfaces folder. Specifying the model with auto link the relevant model to the repository. In this case the User model will be added to the construct methof of the repository.

Same as the service class the rule is to split each repository into its own related folders so the above command will create files in:

  • App\Repositories\Users\UserRepositories.php
  • App\Repositories\Users\Interfaces\UserRepositoriesInterface.php

This will also try create and register the class and interface in laravel.

❕ These command flags can be combined -s -r so that the related service and repository classes be created in one command.

First Repository

After creating your first repository a RepositoryServiceProvider.php file will automatically be created in your App\Providers folder. You will need to add the repository provider file to your config/app.php under the providers section. This will tell laravel that you are adding repositories and linking interfaces to them and they be autoloaded.

...

/*
 * Package Service Providers...
 */
App\Providers\RepositoryServiceProvider::class,

...        

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

propaysystems/laravel-base-repositories 适用场景与选型建议

propaysystems/laravel-base-repositories 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 propaysystems/laravel-base-repositories 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-09