Are extensions/plugins possible and feasible? #380
Replies: 1 comment 2 replies
-
|
Hi! That's a great question. Extensibility is a long-term goal, and our approach differs between the analyzer (which needs deep, type-aware plugins) and the linter (which uses simpler, syntax-based rules). Here’s a summary of the plan: Analyzer Plugins (Future)A public plugin system is planned, which will most likely be built using wasm (WebAssembly).
Stub Support (Available Now)You can override definitions from vendor packages or even PHP's built-in symbols today. Mago loads symbols with a clear priority order:
How to Override Symbols
Note: It is best to place stubs in Linter Custom Rules (Future)For the linter, we plan to support custom rules written directly in PHP. For widely-used or performance-critical rules, we recommend opening an issue on GitHub to have them built directly into Mago. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey again.
Another question is about extensions. Currently, there are built-in integrations that are shipped with Mago, for some of the frameworks and libraries.
Some of these integrations, like Laravel's, don't provide basically any of the features that a typical Laravel codebase would need. In PHPStan world, there's a quite big extension - Larastan, which handles Laravel integration with PHPStan.
There's a lot of weird magic that Laravel does. Unfortunately, in a lot of cases Larastan must boot your application in order to get information that's not accessible statically just from looking at the code. In other cases, Larastan relies on defining stub files to overwrite incorrect types in the Laravel framework itself (common occurrence unfortunately).
The question is - is it possible to implement an extension to Mago without a fork? How feasible would it be to keep a bootstrapped PHP application running in the background, and the Mago extension to talk to it for information? Are there any hooks in the Analyser that could be used to do so? Is it possible to use PHP stub files to overwrite definitions from the original source?
Beta Was this translation helpful? Give feedback.
All reactions