feat(plugin): allow non-Laravel guest frameworks via three opt-in env vars#265
Open
alexstandiford wants to merge 1 commit into
Open
feat(plugin): allow non-Laravel guest frameworks via three opt-in env vars#265alexstandiford wants to merge 1 commit into
alexstandiford wants to merge 1 commit into
Conversation
Three opt-in env vars in resources/js/electron-plugin/src/server/php.ts:
NATIVEPHP_PHP_BOOT_BIN — replaces the hardcoded 'artisan' bin name
in command arrays. Default: 'artisan'.
NATIVEPHP_SERVER_SCRIPT — replaces the Laravel server.php router
path. Default: Laravel's bundled router.
NATIVEPHP_SKIP_LARAVEL_SETUP — skips `artisan optimize` and
`artisan migrate` in serveApp. Default: off.
Optional NATIVEPHP_SERVER_CWD override accompanies SERVER_SCRIPT.
All defaults preserve existing Laravel behavior. The runningSecureBuild
phar-bundle codepath is unaffected.
The motivation is enabling external integration packages (built and
verified end-to-end against phpnomad/db: windows open, notifications
fire, events flow Electron→PHP through real Electron) without forking
the plugin or shipping local patches. The set of overrides is the
minimum required to swap the Laravel-specific CLI commands and router
script; everything above that layer (the /api/* HTTP surface, the
state module, the wire format) is already framework-agnostic.
Acknowledges Discussion NativePHP#141: this is a smallest-possible patch that
unblocks downstream integration work without committing the project
to maintain non-Laravel frameworks first-class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three opt-in env-var overrides in
resources/js/electron-plugin/src/server/php.tsthat let a guest framework other than Laravel use the existing Electron backend without forking the plugin. All defaults preserve existing Laravel behavior in every code path — there is no impact on current users.NATIVEPHP_PHP_BOOT_BIN'artisan'bin name inretrievePhpIniSettings,retrieveNativePHPConfig, and thecallPhp/callPhpSyncsecure-build branch'artisan'NATIVEPHP_SERVER_SCRIPTvendor/laravel/framework/src/Illuminate/Foundation/resources/server.php) inserveAppNATIVEPHP_SKIP_LARAVEL_SETUPartisan optimizeandartisan migrate --forcecalls inserveApp(gated when the guest framework manages its own caching/migrations)Optional companion:
NATIVEPHP_SERVER_CWDlets a guest framework set the working directory for the spawned PHP server when it isn'tappPath/public. Honored only whenNATIVEPHP_SERVER_SCRIPTis set.Why
The plugin's PHP-side HTTP API (the
/api/*surface inresources/js/electron-plugin/src/server/api/*.ts) is already wire-format-agnostic — it doesn't care what PHP framework is on the other end. The only Laravel coupling lives in three concrete places inphp.ts:'artisan'bin name when invoking the PHP-side CLIartisan optimize/artisan migratecalls insideserveAppThis PR makes those three points overridable. The set of overrides is the minimum surface required to swap the Laravel-specific bits; everything else (the API server,
state,utils.notifyLaravel, the/_native/api/*callback convention, the env vars the plugin sets for the PHP process) is unchanged and already framework-agnostic.Real-world validation
I built a working non-Laravel integration on top of phpnomad/db (https://github.com/phpnomad/sqlite-integration). With this patch applied to
electron-pluginlocally:composer require phpnomad/nativephp-integrationstyle package can plug into the Electron backend without modifying the pluginWindowManagerand open at bootNotification,Window,Dialog,Clipboard,Shell,Settings,Screen,System,Dock,MenuBar,Menu,ContextMenu,PowerMonitor,GlobalShortcut,ProgressBar,Processall work as drop-in feature classes that post to the same/api/*endpoints Laravel apps usenotifyLaravel('events', { event, payload })mechanism — the plugin doesn't need to know about the receiving framework's event class namesWindowFocusedinto PHP, PHP fires another notification backWithout this patch, every non-Laravel integration must ship a local fork of
electron-pluginor apply runtime patches viapatch-package— both of which are friction that this small change removes.I'm aware of Discussion #141 where the maintainers noted "we're not actively working on supporting frameworks other than Laravel at this time." This PR doesn't ask the project to do that work; it just opens three doors so external maintainers can do it without depending on plugin forks. Laravel remains the only first-class supported framework; this is purely "don't actively block other people from doing the work."
Diff overview
8 net lines of new logic + a few comments. The full diff is
+37 / -14acrossphp.tsand the matching compiledphp.js(sincedist/is checked in). Touches one source file. No new dependencies, no API changes, no positional argument changes tobootstrap(), no changes to env vars the plugin sets for PHP.retrievePhpIniSettings/retrieveNativePHPConfig:['artisan', ...]→[BOOT_BIN, ...](two occurrences).callPhp/callPhpSync:if (args[0] === 'artisan' ...)→if (args[0] === BOOT_BIN ...)(two occurrences).serveApp: optimize and migrate calls gated by!SKIP_LARAVEL_SETUP; newelse if (SERVER_SCRIPT !== '')branch for the server-script selection that sits betweenrunningSecureBuild()and the Laravel default.What this does NOT change
statemodule,utils.notifyLaravel, the entireserver/api/*surfacebootstrap()signature inindex.tsgetDefaultEnvironmentVariables()env vars the plugin passes to the PHP process (NATIVEPHP_API_URL,NATIVEPHP_SECRET, etc.)runningSecureBuild()phar-bundle code pathA Laravel app with none of these env vars set behaves identically to today.
Test plan
npm run plugin:buildfromresources/js/— compiles cleanly with no new TypeScript errorsnpm run plugin:test— all 7 existing tests pass (api.test.ts × 3, mocking.test.ts × 3, utils.test.ts × 1)I deliberately did not add new tests to
tests/php.test.ts— there's no existing test coverage ofphp.tsto extend (the existing test files coverapi,mocking,utilsonly), and introducing a mocking strategy for the heavily process-spawning / fs-touching code inphp.tsis meaningfully more work than this patch itself. Happy to add tests in a follow-up if you'd prefer that to land separately, or in this PR if you want it co-located — let me know.Compatibility / risk
bootstrap()signature, exported functions, env vars passed to PHP — all unchangedHappy to iterate on naming, structure, or scope — including factoring the override config into a single object instead of three independent env vars if that's preferred. Just let me know.