-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP version isolation helper for command line #1216
Merged
Merged
Conversation
This file contains 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
Co-authored-by: Shifat Hossain <[email protected]>
NasirNobin
commented
Mar 23, 2022
mattstauffer
requested changes
Mar 28, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work, as always. A few notes/requests :)
mattstauffer
requested changes
Mar 29, 2022
NasirNobin
commented
Mar 29, 2022
mattstauffer
requested changes
Mar 30, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor changes and then I think we're good to go!
Co-authored-by: Matt Stauffer <[email protected]>
NasirNobin
commented
Mar 30, 2022
1 task
Thanks so much for your work here @NasirNobin! |
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.
This PR introduces 3 new valet commands. These will help users to run PHP and Composer commands with isolated site's PHP version on the CLI.
valet php ...
will proxy PHP Commands with isolated PHP versionvalet composer ...
will proxy Composer Commands with isolated PHP versionvalet which-php
outputs the PHP executable path for a site. For isolated site it would output the isolated PHP executable path. But non-isolated site will just output the linked default PHP path. The other two commands are dependent on this one to find the PHP executable.🔽 Video demonstration
CleanShot.2022-03-23.at.03.39.09.mp4
Syntax
Though the original idea was to create a command like
valet run
that would proxy PHP calls to an isolated PHP version. But I kinda like the laravel sail style, so kept it this way.Quick note on
which-php
commandCurrently
valet which-php
uses PHP to find the correct executable path. Initially, I thought of doing this with vanilla bash. But then thought if it would bring any benefit, also would make it hard to test it. Some of the codes are still here, in case if we want to explore that route.Symlinking PHP executables to make it a bit fast (No longer using it)
It's using a combination ofbrew --cellar
andbrew info
commands to determine the correct PHP executable path, So each time user runsvalet php -v
it would go through the process of extracting the PATH, which is very slow. Ended up adding a caching mechanism that creates a symlink at/opt/homebrew/bin/valetphp81
location, that directs toward the actual path for that version.So next time a user runsvalet php -v
it would resolve the PHP path much faster from the symlink.Please do suggest if you think there's an easier way to find the PHP executable for a given PHP version. I'll be happy to refactor.Update:
Refactored it to directly look for
BREW_PREFIX/opt/[email protected]/bin/php
location to find the executable binary file. It's already fast and convenient. So we are not creating any additional symlinks now. Thanks to @nicoverbruggen for the suggestion.Alternative Solution
Before starting to work on this PR, I was working on another external solution called zsh-valet to solve the very same problem in a more automated way, still in progress. I'll try to manage that as an external zsh package.
--
Thanks to my colleague @rana01645, @MishukAdhikari & @shifat160 for helping me test this PR properly on both M1 and Intel Mac.