Slim-Bridge

Integrate the PHP-DI container into the Slim 4 microframework.

Library
Composer
v3.4.1
176stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture76
Code Quality74
Innovation66
Learning Curve72

Slim-Bridge configures the Slim 4 microframework to use PHP-DI as its dependency-injection container. It replaces Slim’s default container wiring so you gain autowiring, a powerful PHP-based configuration format, and support for modular application definitions.

Beyond the container swap, the bridge enhances Slim’s controller invocation: route callables are resolved through PHP-DI and their arguments are injected by type or by route parameter name, letting you write clean, testable controllers without pulling values manually from the request.

What You Get

  • A Slim app factory pre-wired to use the PHP-DI container
  • Autowiring and PHP-DI’s configuration format for your services
  • A controller invoker that injects typed arguments and route params
  • Drop-in compatibility with the Slim 4 request/response lifecycle

Common Use Cases

  • Building Slim 4 APIs with autowired services and clean controllers
  • Migrating a Slim app to PHP-DI for modular, testable configuration
  • Injecting route parameters directly as controller method arguments

Under The Hood

Architecture - The core Bridge class exposes a static create() factory that builds a PHP-DI container and returns a configured Slim App from it. A custom CallableResolver resolves route handlers through the container, and ControllerInvoker (built on php-di/invoker) maps request/response, route arguments, and type-hinted services onto controller method parameters. Tech Stack - PHP 7.1+/8.x, requiring php-di/php-di, php-di/invoker, and slim/slim ^4.2, with PHPUnit and laminas-diactoros for tests. PSR-4 autoloading under the DI\Bridge\Slim namespace. Code Quality - A small, focused src/ directory with a dedicated tests/ suite run under PHPUnit and phpcs; the surface area is deliberately narrow and well-scoped. API Design - Ergonomic: a single Bridge::create() entry point replaces Slim’s manual container setup, and the argument-injection convention removes request-parsing boilerplate from controllers.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search