- How do I install mpociot/pipeline in a Laravel project?
- Use Composer: `composer require mpociot/pipeline`. The package is framework-agnostic but mimics Laravel’s `illuminate/pipeline` API, so you can drop it into any project without Laravel dependencies. No additional configuration is needed.
- Can I use this package outside Laravel (e.g., with Slim or Symfony)?
- Yes, this package is designed to work independently of Laravel. It’s ideal for Slim, Symfony, or custom PHP applications needing middleware-style pipelines. The API (`send()`, `through()`, `then()`) is identical to Laravel’s.
- What Laravel versions does mpociot/pipeline support?
- The package is framework-agnostic, so it doesn’t tie to Laravel versions. However, it was originally based on Laravel 5.x’s `illuminate/pipeline`. For PHP 8.x compatibility, you may need polyfills or a fork, as the last update was in 2017.
- How do I create a custom middleware for this pipeline?
- Middleware must implement a `handle($data, Closure $next)` method. For example: `function handle($data, Closure $next) { return $next($data); }`. You can pass arrays of callables or objects with this method to `through()`.
- Does this package support PSR-15 middleware?
- Yes, you can wrap PSR-15 middleware using `Middleware::fromPsr15($psrMiddleware)`. This allows interoperability with frameworks like Slim or Symfony while using the pipeline’s API.
- How do I handle errors or exceptions in the pipeline?
- The package doesn’t include built-in exception handling. You must manually catch exceptions in your middleware or terminal callback. For pipeline-wide error handling, wrap the pipeline execution in a try-catch block.
- Is this package suitable for async workflows (e.g., Promises)?
- No, this package is synchronous-only. For async pipelines, integrate with libraries like `spatie/async-pipeline` or `react/promise` to handle parallel or deferred middleware execution.
- What are the alternatives to mpociot/pipeline?
- Consider `league/pipeline` (actively maintained, PSR-15 compliant) or `php-pipeline` (modern, async-capable). If you need Laravel’s full pipeline, use `illuminate/pipeline` directly. For CLI tools, `symfony/console` also offers pipeline-like features.
- How do I test middleware in this pipeline?
- Mock the pipeline’s `send()` and `through()` methods in your tests. Use PHPUnit to verify middleware behavior by passing test data through the pipeline and asserting the output. Example: `Pipeline::send($data)->through([$middleware])->then(fn($result) => $this->assertEquals(...));`
- Will this package work in production with high traffic?
- Yes, benchmarks show minimal overhead compared to manual chaining. However, for I/O-bound workflows (e.g., API calls), consider async alternatives. The package is stateless and thread-safe, making it suitable for high-throughput systems.