定制 unostentatious/repository 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

unostentatious/repository

Composer 安装命令:

composer require unostentatious/repository

包简介

An abstraction layer that let's you implement repository pattern for your models.

README 文档

README

Unostentatious Repository

Latest Stable Version Total Downloads License


Unostentatious Repository

An abstraction layer that let's you implement repository pattern for your models.


Requirements

  • PHP 7.4^
  • Laravel 8.x / Lumen 8.x

Installation

Step 1: Install through Composer

composer require unostentatious/repository

Step 2: Publish the service provider

In Laravel:
  1. In Laravel, edit config\app.php and add the provider under package service provider section:
 /*
  * Package Service Providers...
  */
 \Unostentatious\Repository\Integration\Laravel\UnostentatiousRepositoryProvider::class,       
  1. Then open your terminal, while in the Laravel app's root directory, publish the vendor:
php artisan vendor:publish --provider="Unostentatious\Repository\Integration\Laravel\UnostentatiousRepositoryProvider"
In Lumen:
  1. Copy the unostent-repository.php config file from vendor/unostentatious/repository/Integration/config/ directory
  2. If the {root}/config/ directory is not existing in your Lumen app, make sure to create it first, paste the config file you just copied
  3. Edit bootstrap/app.php then register the service provider and add the package's config explicitly like so:
// Other actions...

$app->register(\Unostentatious\Repository\Integration\Laravel\UnostentatiousRepositoryProvider::class);
$app->configure('unostent-repository');

Step 3: Custom Configurations

Right now the package's configuration is already residing to your app's config directory /config, there are 3 values in the package's config that you can customize to fit your needs:

<?php
declare(strict_types=1);

return [
    'root' => null,
    'destination' => null,
    'placeholder' => null
];
Key Value
root The base directory in which the application is assigned the folder,
and the structure of the repositories where will be based on.
sample value:
- Laravel: \app_path()
- Lumen: \base_path() . '/app'
destination Define the repositories destination within the {root} directory.
sample value:
- 'Database'
When a value is given ie Database the default path will be:
`{root}/Database/{placeholder}
placeholder Define the repositories placeholder within the {root}/{destination},
sample value:
- Repo
when a value is given ie Repo the default path will be:
{root}/{destination}/Repo.
The default value is null, which makes the folder structure into:
{root}/{destination}/Repositories

Installation Done:

Viola! Just like that your ready to use Unostentatious Repository in your Laravel or Lumen application, happy coding!

Usage:

When creating the repository classes it MUST reside on the specified path {root}/{destination}/{placeholder}, where in this case the default path will be app/Database/Repositories:

Step 1: Create the Repositories

It must be composed of a concrete class, and it's corresponding interface.

Step 2: Follow the convention

Then the concrete class MUST extend the AbstractEloquentRepository from the package.

See the example:

<?php

namespace App\Database\Repositories;

use App\Database\Repositories\Interfaces\UserRepositoryInterface;
use Unostentatious\Repository\AbstractEloquentRepository;

class UserRepository extends AbstractEloquentRepository implements UserRepositoryInterface
{
    // Business logic goes here. 
}

Step 3: Load them to the IoC

Then after these classes has been written, just execute composer dump-autoload to invoke the IoC and these classes will now be injectable to consuming classes ie: Controllers.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固