- How do I install gnugat/query-bus in a Laravel application?
- Install it with Composer using composer require gnugat/query-bus. Because the package is framework-agnostic there is no Laravel service provider auto-discovery contract to rely on, so you register the bus and your matchers yourself, typically in AppServiceProvider or a dedicated QueryBusServiceProvider. Bind the QueryBus interface to the provided implementation and inject it via constructor injection wherever you need it.
- Is gnugat/query-bus compatible with Laravel 10, 11 and PHP 8?
- The package is framework-agnostic and PSR-friendly, and the available documentation does not state a dependency on any specific Laravel major version or a hard PHP version ceiling. That means it generally works with modern Laravel releases, but you should check the composer.json constraints in the repository before committing. If you rely on current PHP 8 features, verify the package's own PHP requirement and run your test suite against your target versions.
- How do I register query matchers in a Laravel service provider?
- Create a resolver that maps each query class to the matcher that handles it, then register your matchers with it inside a service provider. The bus dispatches a query object to the matcher that claims it, so registration is the only wiring step. Keep this registration in one place so the query-to-handler map stays visible and reviewable, since resolution order becomes implicit behavior.
- What happens when multiple matchers handle the same query in gnugat/query-bus?
- The package supports explicit prioritization at registration time, which implies overlapping matchers are expected and the highest-priority one wins. The available documentation does not specify the exact tiebreak rule for equal priorities, so treat that as something to verify with a small spike before you depend on it. This is a useful escape hatch for tenant-specific overrides or test doubles, but it is also the main hazard because resolution order becomes implicit behavior encoded in registration order.
- What does gnugat/query-bus do when no matcher handles a query?
- The documented notes do not state whether an unmatched query throws, returns null, or fails later in the request. Fail-fast behavior is strongly preferable, so write a test that dispatches an unrouted query and confirm the actual result before shipping. If it fails silently, wrap the bus in a thin decorator that throws a typed exception so the error surfaces close to the cause.
- Does gnugat/query-bus support middleware for logging, timing or caching?
- Yes, the package includes middleware support for composing cross-cutting concerns around query execution. That lets you add logging, timing or caching without touching individual matchers. A practical middleware logs the query class, the resolved matcher and the resolved priority, which greatly reduces the debugging opacity that dispatch indirection normally introduces.
- How do I unit test code that uses the query bus in Laravel?
- Because the bus is a simple interface, you can bind a fake QueryBus implementation in the container for tests that only care about dispatch, or register in-memory matchers for tests that exercise real handlers. Priority registration makes it straightforward to swap a production matcher for a test double in a specific test case. Keep query objects small and immutable so assertions on the returned result stay simple.
- Is gnugat/query-bus a good fit for CQRS in Laravel, or should I stick with repositories?
- It fits a Laravel monolith or modular monolith that already leans on the container, and it is additive with no new database driver, queue backend or infrastructure. It is a poor fit if your team has no CQRS vocabulary or if read logic is already well factored into repositories and services, because it then adds a layer without removing one. Adopt it one bounded context and one read path at a time rather than converting controllers wholesale.
- What are the alternatives to gnugat/query-bus for PHP and Laravel?
- League Tactician and SimpleBus are the common general-purpose command and query bus implementations in the PHP ecosystem, and both offer broader middleware and handler-resolution features. For Laravel-only code, resolving read services directly from the container or using pipelines is often enough without a bus abstraction. Choose gnugat/query-bus when you want a very small, dependency-light query bus and are comfortable wiring it yourself.
- Is gnugat/query-bus actively maintained and safe for production?
- The repository sits under the gnugat-legacy organization at version 1.0.0 with a short changelog, which suggests limited production mileage, so check the license, open-issue count and last commit date before adopting it. Run a short spike to confirm priority tiebreaks, unmatched-query behavior and your target Laravel and PHP versions. Because the codebase is small, vendoring or forking it is a realistic fallback if maintenance stalls.