marcj/topsort
Fast PHP topological sort/dependency resolver. Add string nodes with dependencies and get a valid processing order; includes grouped sorting to keep same-type items together and retrieve group metadata. Useful for UoW, DI, package managers, etc.
Illuminate\Support\Collection::sort() or custom recursive algorithms) for real-world use cases?make:provider, ServiceProvider boot order) or packages like spatie/laravel-dependency-injection suffice?AppServiceProvider dependencies).Artisan::call()) with dependencies.belongsToMany or polymorphic relations).array_sort()) with topsort.topsort in a service class to handle failures (e.g., fall back to a slower algorithm or log warnings).array() syntax, type hints). May require minor patches.INSERT/UPDATE operations).bootstrap/app.php or a ServiceProvider).create_function, old array syntax).dd($sorter->getGraph())).StringSort vs. GroupedSort").| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Dependency cycle detected | App crashes or hangs | Graceful degradation (log + partial execution) |
| Invalid input (non-string keys) | Sorting fails silently | Input validation before calling sort() |
| PHP version incompatibility | Runtime errors | Polyfill or fork with PHP 8.x support |
| Large graph (memory exhaustion) | Slow performance or crashes | Batch processing or distributed sort |
How can I help you explore Laravel packages today?