๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆBatch Registrar

Introduction

It streamlines the process of binding interfaces to classes in batch. It leverages a binding process to the service container, ensuring clean and maintainable code within the service provider.

How it works?

The package scans all .php files in the specified registrar paths, identifies valid bindable paths, and binds them to the service container. It specifically looks for the BatchRegistrar attribute. Learn more about PHP attributes here.

Service Provider

To use the batch binding feature, extend your service provider from CoreFoundationServiceProvider and utilize the batchRegistrar method.

class YourServiceProvider extends CoreFoundationServiceProvider
{
    public function register(): void
    {
        $this->batchRegistrar([
            __DIR__ . "/../Repositories"
        ]);
    }
}

Repository Interface

Define your repository interface with the BatchRegistrar attribute, indicating which class it should bind to.

<?php

namespace App\Repositories\Interfaces;

use App\Repositories\UserRepository;
use CoreFoundation\Attributes\BatchRegistrar;
use CoreFoundation\Repositories\BaseRepository;

#[BatchRegistrar(UserRepository::class)]
interface UserRepositoryInterface extends BaseRepositoryInterface
{
}

Repository

Implement the repository interface to ensure it adheres to the specified structure.

class UserRepository extends BaseRepository implements UserRepositoryInterface
{}

Last updated

Was this helpful?