# mimmi20/mezzio-generic-authorization-rbac architecture

> Architecture diagram of the GitHub repository mimmi20/mezzio-generic-authorization-rbac, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mimmi20/mezzio-generic-authorization-rbac
- Repository: https://github.com/mimmi20/mezzio-generic-authorization-rbac

## Overview

This project is a PHP library that provides a Laminas-RBAC adapter implementation for the mezzio-generic-authorization system. Its primary purpose is to supply role-based access control (RBAC) functionality within applications built using the Mezzio middleware framework. The design centers on integrating an RBAC system with mezzio’s authentication, using Laminas’ RBAC components and adding the possibility of dynamic assertions.

##### Main Components
- Library Core:
- ConfigProvider (src/ConfigProvider.php): Supplies RBAC configuration to the application.
- LaminasRbac (src/LaminasRbac.php): Likely a wrapper or adapter around the Laminas RBAC implementation.
- LaminasRbacAssertionInterface (src/LaminasRbacAssertionInterface.php): An extension of Laminas’ AssertionInterface to support PSR-7 requests.
- LaminasRbacFactory (src/LaminasRbacFactory.php): A factory class to create instances of the RBAC adapter using dependency injection.
- Testing:
- The tests directory shows unit tests for the key components (e.g., tests/ConfigProviderTest.php, tests/LaminasRbacTest.php).

##### Understand the Integration Points
- Mezzio Integration: The library is intended as an adapter for mezzio-generic-authorization and works with mezzio-authentication (adding the PSR-7 UserInterface attribute).
- Laminas RBAC Library: Underpins the actual RBAC functionality.
- Dynamic Assertions: The project supports dynamic authorization checks (involving HTTP request context) – a central part is extending or customizing the assertion logic (as illustrated by the EditorAuth example in the README).

##### Relationships and Interactions
- Configuration Flow: The ConfigProvider provides the required configuration (like roles and permissions) included in the application’s configuration file (as shown in the README example).
- Factory Instantiation: The factory (LaminasRbacFactory) is used to instantiate the LaminasRbac-based adapter; it pulls in the configuration and dependencies from a service container.
- Authorization Flow: When a request comes into the application, mezzio-authentication supplies user identity attributes; these are then checked against RBAC rules through the LaminasRbac implementation.
- Dynamic Assertion Handling: If a dynamic check is needed, the custom assertion interface (LaminasRbacAssertionInterface) is used to inspect the request and determine if access should be granted.

##### Architectural Patterns and Design Principles
- Dependency Injection: Usage of factories (e.g., LaminasRbacFactory) to create instances with their dependencies.
- Adapter Pattern: The library adapts the standard Laminas RBAC concepts to work within a mezzio authorization context.
- Separation of Concerns: Configuration, authorization checking, and service instantiation are clearly separated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Dependency Injection Layer
    subgraph "Configuration & Dependency Injection"
        CF["authorization.local.php"]:::config
        SC["Service Container"]:::config
    end

    %% Core Library Components
    subgraph "Core Library"
        CP["ConfigProvider"]:::core
        FACT["LaminasRbacFactory"]:::core
        RBAC["LaminasRbac"]:::core
        ASSERT["LaminasRbacAssertionInterface"]:::core
    end

    %% External Dependencies
    subgraph "External Dependencies"
        MA["Mezzio Authentication"]:::external
        HTTP["HTTP Request(with attributes)"]:::external
        LRBAC["Laminas-permissions-RBAC"]:::external
    end

    %% Testing Components
    subgraph "Testing"
        TEST["Tests (Unit Tests)"]:::test
    end

    %% Connections for Configuration & DI to Core Library
    CF -->|"provides config"| CP
    SC -->|"instantiates"| FACT
    CP -->|"config data used by"| FACT
    FACT -->|"creates instance"| RBAC

    %% Dynamic Assertion Flow
    HTTP -->|"triggers dynamic assertion"| ASSERT
    ASSERT -->|"integrates with"| RBAC

    %% External Integration
    RBAC -->|"uses"| LRBAC
    MA -->|"supplies authenticated context to"| HTTP

    %% Styles for nodes
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef external fill:#C1FFC1,stroke:#000,stroke-width:2px;
    classDef config fill:#FFFFCC,stroke:#000,stroke-width:2px;
    classDef test fill:#FFC0CB,stroke:#000,stroke-width:2px;

    %% Click Events
    click CP "https://github.com/mimmi20/mezzio-generic-authorization-rbac/blob/master/src/ConfigProvider.php"
    click RBAC "https://github.com/mimmi20/mezzio-generic-authorization-rbac/blob/master/src/LaminasRbac.php"
    click ASSERT "https://github.com/mimmi20/mezzio-generic-authorization-rbac/blob/master/src/LaminasRbacAssertionInterface.php"
    click FACT "https://github.com/mimmi20/mezzio-generic-authorization-rbac/blob/master/src/LaminasRbacFactory.php"
    click TEST "https://github.com/mimmi20/mezzio-generic-authorization-rbac/tree/master/tests"
```
