Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Patchwork Laravel Package

antecedent/patchwork

Patchwork is a PHP monkey-patching library for runtime function and method redefinition. Useful for legacy code and hard-to-test dependencies, it enables stubbing, mocking, and behavior overrides without changing source, ideal for testing and debugging.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Legacy System Modernization: Accelerate testing and integration of legacy PHP codebases without full refactoring, reducing technical debt incrementally.
  • Rapid Prototyping: Enable quick experimentation with new features or workflows by dynamically altering function behavior without modifying production code.
  • Testing Strategy: Expand test coverage for untestable legacy systems by intercepting and stubbing dependencies, improving CI/CD reliability.
  • Debugging & Hotfixes: Deploy temporary fixes or debugging hooks in production environments without redeploying code (e.g., logging, validation overrides).
  • Build vs. Buy: Justify adopting this package over custom solutions for runtime manipulation, saving dev time and reducing risk.
  • Roadmap Prioritization: Fast-track features dependent on legacy systems by bypassing refactor blockers (e.g., third-party SDKs, static classes).

When to Consider This Package

Adopt when:

  • Your team maintains large, untested legacy PHP codebases where refactoring is costly or politically risky.
  • You need to test global/static functions or built-ins (e.g., date(), file_get_contents()) without modifying source files.
  • Prototyping requires runtime behavior changes (e.g., A/B testing, feature flags with dynamic overrides).
  • Debugging complex interactions in production is critical, and traditional logging isn’t sufficient.
  • Your stack uses Laravel/PHP and lacks native DI for certain dependencies (e.g., legacy WordPress plugins, custom libraries).

Look elsewhere if:

  • Your codebase is already modular with dependency injection (consider Laravel’s built-in mocking or containers).
  • You need long-term runtime changes (use configuration files or feature flags instead).
  • The team lacks discipline to revert patches (risk of production bugs from lingering overrides).
  • Performance is critical (monkey patching adds runtime overhead; benchmark first).
  • You’re working in a strictly typed environment where runtime manipulation conflicts with type safety.

How to Pitch It (Stakeholders)

For Executives: "Patchwork lets us test and extend legacy PHP systems without rewriting them—saving 6–12 months of dev effort. For example, we can stub out a third-party payment gateway’s static methods to test our checkout flow, or dynamically inject logging into production to debug a critical bug. This reduces risk in modernizing our stack while keeping legacy systems running. The MIT license and active maintenance make it a low-risk choice."

For Engineers: *"This is like PHP’s dd() for functions—you can override any global/static method at runtime to:

  • Mock dependencies in legacy tests (e.g., Mail::send() → return a fake response).
  • Debug live issues by intercepting calls (e.g., log every User::find() with slow queries).
  • Prototype features without touching production code (e.g., override Auth::attempt() to simulate admin sessions). It’s lightweight, works with Laravel, and avoids the pitfalls of manual hacks. Use it for tests, debugging, or temporary fixes—never for permanent changes."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope