PHPackages                             bamise/framework - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bamise/framework

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bamise/framework
================

Secure enterprise CRUD library for PHP 8.4+ — hexagonal architecture, DDD, PSR standards, JWT/CSRF/XSS protection, event system.

v1.0.0(1mo ago)14MITPHPPHP ^8.4CI failing

Since May 26Pushed 1mo agoCompare

[ Source](https://github.com/segunmayor/bamise)[ Packagist](https://packagist.org/packages/bamise/framework)[ Docs](https://github.com/segunmayor/bamise.git)[ GitHub Sponsors](https://github.com/segunmayor)[ Patreon](https://www.patreon.com/SegunMayor)[ RSS](/packages/bamise-framework/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

Bamise
======

[](#bamise)

 [![](.github/assets/bamise_logo.png)](.github/assets/bamise_logo.png)

Bamise
=======

[](#bamise-1)

Enterprise Secure CRUD Automation Framework

[![CI](https://github.com/bamise/bamise/actions/workflows/ci.yml/badge.svg)](https://github.com/bamise/bamise/actions/workflows/ci.yml)[![Mutation Testing](https://camo.githubusercontent.com/fe6eb1a346aa04ee16b551fa9da02bd3e9e066faa30a1c75aae43a368af0823b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324662616d69736525324662616d6973652532466d61696e)](https://dashboard.stryker-mutator.io/reports/github.com/bamise/bamise/main)[![PHP 8.4+](https://camo.githubusercontent.com/29410bb6bcb6a3fb064bad25ef3ce0793978e60c3876a15c4c80f62d6660e553/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342532422d626c7565)](https://www.php.net/)[![License: GPL-3.0-or-later](https://camo.githubusercontent.com/884747af79c314c5be03b673d810583f77915795ab5682bc3319f9a34ccc8984/68747470733a2f2f736869656c64732e696f)](https://www.gnu.org/licenses/gpl-3.0)(LICENSE)

Secure enterprise CRUD library for PHP 8.4+ built on hexagonal (ports-and-adapters) architecture. Domain-driven, PSR-compliant, zero hardcoded dependencies.

---

Features
--------

[](#features)

- **Hexagonal architecture** — contracts, domain, application, infrastructure layers fully separated
- **Repository pattern** — PDO-backed with MySQL, MariaDB, PostgreSQL, and SQLite dialects
- **Security-first** — CSRF protection, HTML sanitisation, cache-backed rate limiting, HMAC request signing, bearer/session/JWT auth stubs, PSR audit logging
- **Event system** — synchronous dispatcher, async queue bridge, before/after CRUD lifecycle hooks, subscriber autoloading
- **Policy engine** — callable and class-based access policies with a chainable evaluator
- **Middleware pipeline** — pluggable before/after handlers with a `PipelineState` value object
- **PHPUnit 11** — full unit test suite; PHPStan level 6; PHP CS Fixer; Infection mutation testing

---

Requirements
------------

[](#requirements)

RequirementVersionPHP8.4+psr/container^2.0psr/log^3.0Optional: `firebase/php-jwt ^6.10` for `JwtAuthAdapter` (HS256 bearer validation).

---

Installation
------------

[](#installation)

```
composer require bamise/framework
```

---

Quick Start
-----------

[](#quick-start)

### 1. Define a resource

[](#1-define-a-resource)

```
use Bamise\Contract\Domain\ResourceDefinitionInterface;
use Bamise\Contract\Enum\OperationType;

final class PostDefinition implements ResourceDefinitionInterface
{
    public function resourceName(): string  { return 'posts'; }
    public function primaryKey(): string    { return 'id'; }
    public function fillable(): array       { return ['title', 'body', 'author_id']; }
    public function guarded(): array        { return ['id', 'created_at']; }

    public function allowedOperations(): array
    {
        return [
            OperationType::Create,
            OperationType::Read,
            OperationType::Update,
            OperationType::Delete,
        ];
    }
}
```

### 2. Wire up the repository

[](#2-wire-up-the-repository)

```
use Bamise\Infrastructure\Persistence\PDO\PdoConnection;
use Bamise\Infrastructure\Persistence\PDO\ConnectionConfig;
use Bamise\Infrastructure\Persistence\PDO\PdoRepository;
use Bamise\Contract\Enum\DatabaseDriver;

$config = new ConnectionConfig(
    driver: DatabaseDriver::Mysql,
    dsn: 'mysql:host=127.0.0.1;dbname=myapp',
    user: 'root',
    password: 'secret',
);

$connection  = PdoConnection::fromConfig($config);
$definition  = new PostDefinition();
$repository  = new PdoRepository($connection, $definition);
```

### 3. Register resources and build the application

[](#3-register-resources-and-build-the-application)

```
use Bamise\Application\Registry\ResourceRegistry;
use Bamise\Application\Registry\RepositoryResolver;
use Bamise\Application\CrudApplication;

$resources  = new ResourceRegistry();
$resolver   = new RepositoryResolver();

$resources->register($definition);
$resolver->register('posts', $repository);

$app = new CrudApplication($resources, $resolver, /* ...middlewares, strategies... */);
```

### 4. Dispatch an operation

[](#4-dispatch-an-operation)

```
use Bamise\Contract\Http\CrudRequestInterface;

// $request is any object implementing CrudRequestInterface
$response = $app->handle($request);

echo $response->status();  // 200, 422, 403 …
echo json_encode($response->data());
```

---

Security
--------

[](#security)

### CSRF Protection

[](#csrf-protection)

```
use Bamise\Infrastructure\Security\Csrf\CsrfGuard;
use Bamise\Infrastructure\Cache\InMemoryCache;

$cache = new InMemoryCache();
$guard = new CsrfGuard($cache, ttl: 3600);

$token = $guard->generate('session-id');
$guard->validate('session-id', $token); // throws on mismatch
```

### Rate Limiting

[](#rate-limiting)

```
use Bamise\Infrastructure\Security\RateLimit\CacheRateLimiter;

$limiter = new CacheRateLimiter($cache, maxAttempts: 60, windowSeconds: 60);
// Used automatically by RateLimitMiddleware when registered in the pipeline
```

### Request Signing (HMAC)

[](#request-signing-hmac)

```
use Bamise\Infrastructure\Security\Signing\HmacRequestSigner;

$signer    = new HmacRequestSigner(secret: getenv('HMAC_SECRET'));
$signature = $signer->sign(['resource' => 'posts', 'action' => 'create']);
// Attach as X-Signature header; verify incoming requests with $signer->verify($request)
```

### Access Policies

[](#access-policies)

```
use Bamise\Infrastructure\Security\Policy\CallablePolicy;
use Bamise\Domain\Policy\PolicyEvaluator;

$policy = new CallablePolicy(
    static fn (OperationType $op, ?object $subject, string $resource): bool =>
        $subject !== null && in_array('admin', $subject->roles ?? [], true),
);

$evaluator = new PolicyEvaluator([$policy]);
$allowed   = $evaluator->evaluate(OperationType::Delete, $subject, 'posts');
```

---

Event System
------------

[](#event-system)

### Listening to CRUD lifecycle events

[](#listening-to-crud-lifecycle-events)

```
use Bamise\Contract\Event\DomainEventInterface;
use Bamise\Infrastructure\Event\EventDispatcher;
use Bamise\Infrastructure\Event\ListenerRegistry;

$registry   = new ListenerRegistry();
$dispatcher = new EventDispatcher($registry);

// Register a listener for all BeforeCrud events
$registry->register(
    eventClass: \Bamise\Domain\Event\BeforeCrudEvent::class,
    listener:   static function (DomainEventInterface $event): void {
        // inspect $event->context(), $event->payload() …
    },
);
```

### Subscriber classes

[](#subscriber-classes)

```
use Bamise\Contract\Event\EventSubscriberInterface;

final class AuditSubscriber implements EventSubscriberInterface
{
    public static function subscribedEvents(): array
    {
        return [
            \Bamise\Domain\Event\AfterCrudEvent::class => [['onAfterCrud', 10]],
        ];
    }

    public function onAfterCrud(DomainEventInterface $event): void
    {
        // log to your audit trail
    }
}

// Register via SubscriberLoader
$loader = new \Bamise\Infrastructure\Event\SubscriberLoader($registry);
$loader->load(new AuditSubscriber());
```

### Async (queued) listeners

[](#async-queued-listeners)

```
// Implement QueuePortInterface and pass to AsyncEventDispatcher
$asyncDispatcher = new \Bamise\Infrastructure\Event\AsyncEventDispatcher($queue, $encoder);
```

---

Architecture
------------

[](#architecture)

Bamise follows hexagonal (ports-and-adapters) architecture. Full module documentation lives under [`docs/architecture/`](docs/architecture/).

ModulePathDescription1 — Contracts`src/Contract/`Pure interfaces and value objects only2 — Domain`src/Domain/`Models, services, policies, lifecycle events3 — Application`src/Application/`Orchestrator, middleware pipeline, strategies, response mapping4 — Infrastructure`src/Infrastructure/Persistence/`PDO connection, dialects, SQL compiler, repositories8 — Security`src/Infrastructure/Security/`CSRF, XSS, rate limiting, HMAC signing, auth adapters, audit9 — Events`src/Infrastructure/Event/`Sync dispatcher, async queue bridge, subscriber loader, plugin hooks11 — CI/CD`.github/workflows/`PHPUnit, PHPStan, PHP CS Fixer, Infection12 — Composer`composer.json`Packagist metadata, scripts, semantic versioning---

Development
-----------

[](#development)

### Available commands

[](#available-commands)

```
composer test            # PHPUnit (no coverage)
composer test-coverage   # PHPUnit + Clover report
composer analyse         # PHPStan level 6
composer cs-check        # PHP CS Fixer dry-run
composer cs-fix          # Auto-fix style violations
composer mutation        # Infection mutation testing
composer ci              # test + analyse + cs-check
```

### Running tests

[](#running-tests)

```
# All tests
composer test

# Single suite
vendor/bin/phpunit --testsuite Unit
vendor/bin/phpunit --testsuite Integration

# With coverage (requires pcov or xdebug)
composer test-coverage
```

### Static analysis

[](#static-analysis)

```
composer analyse
# Config: phpstan.neon (level 6, src/ only)
```

### Code style

[](#code-style)

```
composer cs-check   # Check without modifying
composer cs-fix     # Fix in place
# Config: .php-cs-fixer.dist.php (@PER-CS2.0 + @PHP84Migration)
```

### Mutation testing

[](#mutation-testing)

```
composer mutation
# Config: infection.json5 (minMsi=70%, minCoveredMsi=80%)
```

---

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](.github/CONTRIBUTING.md).

---

Security Policy
---------------

[](#security-policy)

See [SECURITY.md](.github/SECURITY.md).

---

License &amp; Copyright
-----------------------

[](#license--copyright)

Formerly: Sitcalm Current: Bamise Framework Support development via donations

Copyright (c) 2026 Segun Mayor

This project is licensed under the **GNU General Public License v3.0**. See the [LICENSE](LICENSE) file for the full text.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance88

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

59d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4924aef07f18f0fa155a4974ac453d5c65de8580f04bfe279eb6192d3ac04dcf?d=identicon)[flair.dev](/maintainers/flair.dev)

---

Top Contributors

[![segunmayor](https://avatars.githubusercontent.com/u/24715033?v=4)](https://github.com/segunmayor "segunmayor (22 commits)")

---

Tags

bamisecrudeventsframeworklibrarymiddlewarephpquery-builderrbacsecuritypsreventsecuritycrudenterpriserepositorydddhexagonalphp8bamise

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bamise-framework/health.svg)

```
[![Health](https://phpackages.com/badges/bamise-framework/health.svg)](https://phpackages.com/packages/bamise-framework)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[laravel/framework

The Laravel Framework.

34.8k543.8M20.5k](/packages/laravel-framework)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k54](/packages/ecotone-ecotone)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k16](/packages/tempest-framework)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k46](/packages/civicrm-civicrm-core)[wikimedia/parsoid

Parsoid, a bidirectional parser between wikitext and HTML5

187557.3k3](/packages/wikimedia-parsoid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
