unostentatious/repository

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

v1.3.1 2023-09-12 14:52 UTC

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
];

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.