1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-04 16:10:08 +01:00
Files
laravel-valet/valet
Matt Stauffer 303462ffd1 Add Expose support, drop ngrok binary and move it to be managed by Brew, drop copying ngrok share URL to clipbaord
* Extract basic driver with public/ from basic driver, and simplify both

* Apply fixes from StyleCI

* Set HTTP_HOST in BaseDriverTest

* Move server helpers to their own file; add type hints

* Update drivers location and loading

- Extract much of server.php into a `Server` class
- Move all but the Laravel and Basic drivers into a subfolder
- Load all but the Laravel and Basic drivers via glob
- Add `beforeLoading` hook to simplify the `frontControllerPath` method for some drivers

* Apply fixes from StyleCI

* Add additional notes to upgrade.md

* Apply fixes from StyleCI

* Require PHP 8.0

* Add type hints and return type hints to Brew

* Apply fixes from StyleCI

* Add type hints and return type hints to CommandLine

* Add type hints and return type hints to Configuration

* Add type hints and return type hints to Diagnose

* Apply fixes from StyleCI

* Add type hints and return type hints to DnsMasq

* Add type hints and return hints to Filesystem

* Add type hints and return types to Nginx

* Add type hints and return types to ngrok

* Add type hints and return types to PhpFpm

* Apply fixes from StyleCI

* Add type hints and return types to Site and Valet

* Apply fixes from StyleCI

* Require passing a version number to isolate command

* Apply fixes from StyleCI

* Bump compat to php 8; add type hints and return types to helpers

* Apply fixes from StyleCI

* Use constructor promotion

* Apply fixes from StyleCI

* Write tests for Server.php

* Apply fixes from StyleCI

* Move upgrade calls into Upgrader class, and add upgrade to check for old custom drivers

* Apply fixes from StyleCI

* Replace some \n with PHP_EOL; move custom drivers into Custom namespace

* Apply fixes from StyleCI

* Add doc blocks

* Clean up NullWriter; drop legacy config check

* Allow null response from frontControllerPath

* Apply fixes from StyleCI

* Drop exits, fix 404 path

* Better handle new installations

* Apply fixes from StyleCI

* Drop extensions

* Clean up DX for fetch-share-url

* Apply fixes from StyleCI

* Fix site::unlink method signature and docblock

* Tweak the wording for the which command

* Support isolated sites running PHP 7.4

* Add a bunch more CLI command tests (#1332)

* Wip some cli tests

* Apply fixes from StyleCI

* Test parked command

* Test forget command

* Update Filesystem::rmDirAndContents to respect symlinks

* Wip cli commands

* Apply fixes from StyleCI

* Test link command, unlink command, and secure command

* Apply fixes from StyleCI

* Add tests for unsecure, unsecure --all, secured commands

Add placeholders for the remaining CLI commands
Add nginx::restart to unsecure --all command

Co-authored-by: StyleCI Bot <bot@styleci.io>

* Drop old config migrations

* Add status command (#1329)

* Build the foundation of a status command

* Apply fixes from StyleCI

* Wip testing status command

* Apply fixes from StyleCI

* Fix status test

* Apply fixes from StyleCI

* Fix race condition in creating test config file

* Apply fixes from StyleCI

* Reset container for each test

* Differentiate response code based on success or failure of status command

* Apply fixes from StyleCI

* Add the ability to test if a Brew service is running

* Apply fixes from StyleCI

* Check for more services running in status command

* Apply fixes from StyleCI

* Test Status

* Apply fixes from StyleCI

* Drop Yoast from base application test case

Co-authored-by: StyleCI Bot <bot@styleci.io>

* Test most of the remaining CLI commands

* Test set tld command

* Test set loopback command

* Test proxy, unproxy, and proxies commands

* Apply fixes from StyleCI

* Test which command

* Test diagnose command

* Test directory-listing and which-php commands

* Text isolate and unisolate and isolated commands

* Apply fixes from StyleCI

* Test trust command

* Apply fixes from StyleCI

* Test on-latest-version command

* Move uninstall text to a class, and tweak text and presentation

* Apply fixes from StyleCI

* Test use command

* Test stop command

* Test start command

* Test restart command

Co-authored-by: StyleCI Bot <bot@styleci.io>

* Drop unnecessary doc blocks (#1339)

* Drop unnecessary doc blocks

* Apply fixes from StyleCI

Co-authored-by: StyleCI Bot <bot@styleci.io>

* Tweak status output and install output

* Add debug instructions to valet status, expand "valet installed" status check

* Drop extensions directory

* Apply fixes from StyleCI

* Remove more docblocks

* Upgrade ngrok to 3.1.0

* Test force uninstall command

* Test log command

* Drop copying Ngrok share to clipboard; add first steps of Expose code

* Add logic paths for Expose vs. ngrok and the share-tool config

* Apply fixes from StyleCI

* Take the first steps of manually installing ngrok and expose when needed

* Apply fixes from StyleCI

* Next steps Brew-installed ngrok

* Apply fixes from StyleCI

* Add class to represent Composer; continue ngrok + expose updates

* Apply fixes from StyleCI

* Add ensureInstalled() method to Expose and installOrFail() to Composer

* Apply fixes from StyleCI

* Require global PHP 8+ to install

* Exit if invalid domain is passed to valet share

* Update Composer dependencies to use Illuminate/Container

* Drop the idea of passing a custom domain to valet share

Co-authored-by: StyleCI Bot <bot@styleci.io>
2023-01-13 21:34:37 -05:00

149 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
# If the current source is a symbolic link, we need to resolve it to an
# actual directory name. We'll use PHP to do this easier than we can
# do it in pure Bash. So, we'll call into PHP CLI here to resolve.
if [[ -L "$SOURCE" ]]
then
DIR=$(php -r "echo dirname(realpath('$SOURCE'));")
else
DIR="$( cd "$( dirname "$SOURCE" )" && pwd )"
fi
# If we are in the global Composer "bin" directory, we need to bump our
# current directory up two, so that we will correctly proxy into the
# Valet CLI script which is written in PHP. Will use PHP to do it.
if [ ! -f "$DIR/cli/valet.php" ]
then
DIR=$(php -r "echo realpath('$DIR/../laravel/valet');")
fi
# If the command is the "share" command we will need to resolve out any
# symbolic links for the site. Before starting Ngrok, we will fire a
# process to retrieve the live Ngrok tunnel URL in the background.
if [[ "$1" = "share" ]]
then
SHARETOOL="$(php "$DIR/cli/valet.php" share-tool)"
if [[ $SHARETOOL = "ngrok" ]]
then
# ngrok
# Check for parameters to pass through to ngrok (these will start with '-' or '--')
PARAMS=(${@:2})
for PARAM in ${PARAMS[@]}
do
if [[ ${PARAM:0:1} != '-' ]]; then
PARAMS=("${PARAMS[@]/$PARAM}") #Quotes when working with strings
fi
done
PARAMS=${PARAMS[@]}
HOST="${PWD##*/}"
# Find the first linked site for the current dir, if one exists
for linkname in ~/.config/valet/Sites/*; do
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
break
fi
done
TLD=$(php "$DIR/cli/valet.php" tld)
# Decide the correct PORT: uses 60 for secure, else 80
if grep --quiet --no-messages 443 ~/.config/valet/Nginx/$HOST*
then
PORT=60
else
PORT=80
fi
# Lowercase the host to match how the rest of our domains are looked up
HOST=$(echo "$HOST" | tr '[:upper:]' '[:lower:]')
BREW_PREFIX=$(brew --prefix)
sudo -u "$USER" "$BREW_PREFIX/bin/ngrok" http "$HOST.$TLD:$PORT" --host-header=rewrite $PARAMS
exit
elif [[ $SHARETOOL = "expose" ]]
then
# expose
# Check for parameters to pass through to Expose (these will start with '-' or '--')
PARAMS=(${@:2})
for PARAM in ${PARAMS[@]}
do
if [[ ${PARAM:0:1} != '-' ]]; then
PARAMS=("${PARAMS[@]/$PARAM}") #Quotes when working with strings
fi
done
PARAMS=${PARAMS[@]}
HOST="${PWD##*/}"
# Find the first linked site for the current dir, if one exists
for linkname in ~/.config/valet/Sites/*; do
if [[ "$(readlink $linkname)" = "$PWD" ]]
then
HOST="${linkname##*/}"
break
fi
done
TLD=$(php "$DIR/cli/valet.php" tld)
# Decide the correct PORT: uses 443 for secure, else 80
if grep --quiet --no-messages 443 ~/.config/valet/Nginx/$HOST*
then
PORT=443
else
PORT=80
fi
# Lowercase the host to match how the rest of our domains are looked up
HOST=$(echo "$HOST" | tr '[:upper:]' '[:lower:]')
sudo -u "$USER" expose share "$HOST.$TLD:$PORT" $PARAMS
exit
else
echo ''
echo "Please use 'valet share-tool ngrok' or 'valet share-tool expose'"
echo "to set your preferred share tool."
exit
fi
# Proxy PHP commands to the "php" executable on the isolated site
elif [[ "$1" = "php" ]]
then
$(php "$DIR/cli/valet.php" which-php) "${@:2}"
exit
# Proxy Composer commands with the "php" executable on the isolated site
elif [[ "$1" = "composer" ]]
then
$(php "$DIR/cli/valet.php" which-php) $(which composer) "${@:2}"
exit
# Finally, for every other command we will just proxy into the PHP tool
# and let it handle the request. These are commands which can be run
# without sudo and don't require taking over terminals like Ngrok.
else
if [[ "$EUID" -ne 0 ]]
then
sudo USER="$USER" --preserve-env "$SOURCE" "$@"
exit
fi
php "$DIR/cli/valet.php" "$@"
fi