Skip to content
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

Add support for custom site domains to valet php and valet composer #1274

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cli/valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,19 +604,21 @@
/**
* Proxy commands through to an isolated site's version of PHP.
*/
$app->command('php [command]', function ($command) {
$app->command('php [command] [--site=]', function ($command, $site = null) {
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
})->descriptions("Proxy PHP commands with isolated site's PHP executable", [
'command' => "Command to run with isolated site's PHP executable",
'command' => "Command to run with isolated site's PHP executable. If you wish to pass a --site flag to this command then encapsulate the entire command within a string",
'--site' => 'Specify the site (e.g. if the site isn\'t linked as its directory name)',
]);

/**
* Proxy commands through to an isolated site's version of Composer.
*/
$app->command('composer [command]', function ($command) {
$app->command('composer [command] [--site=]', function ($command, $site = null) {
warning('It looks like you are running `cli/valet.php` directly; please use the `valet` script in the project root instead.');
})->descriptions("Proxy Composer commands with isolated site's PHP executable", [
'command' => "Composer command to run with isolated site's PHP executable",
'--site' => 'Specify the site (e.g. if the site isn\'t linked as its directory name)',
]);

/**
Expand Down
40 changes: 38 additions & 2 deletions valet
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,50 @@ then
# Proxy PHP commands to the "php" executable on the isolated site
elif [[ "$1" = "php" ]]
then
$(php "$DIR/cli/valet.php" which-php) "${@:2}"

# Find and extract an optional flag "--site=foo" to cater for sites that use
# a custom domain. The "=" after the flag is mandatory "--site foo" will not work.
SITE=""
PARSED_ARGS=()
for i in "$@"; do
case $i in
--site=*)
SITE="${i#*=}"
shift
;;
*) # All other input / commands / options
PARSED_ARGS+=("$i") # save it in an array for later
shift
;;
esac
done

$(php "$DIR/cli/valet.php" which-php $SITE) "${PARSED_ARGS[@]:1}"

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}"

# Find and extract an optional flag "--site=foo" to cater for sites that use
# a custom domain. The "=" after the flag is mandatory "--site foo" will not work.
SITE=""
PARSED_ARGS=()
for i in "$@"; do
case $i in
--site=*)
SITE="${i#*=}"
shift
;;
*) # All other input / commands / options
PARSED_ARGS+=("$i") # save it in an array for later
shift
;;
esac
done

$(php "$DIR/cli/valet.php" which-php $SITE) $(which composer) "${PARSED_ARGS[@]:1}"

exit

Expand Down