Skip to content

Commit d04efb5

Browse files
committed
fix(php): ignore warnings in CLI parsing
When running PHP with extensions like imagick, sometimes the extension needs a rebuild after `brew upgrade`. Otherwise, it will throw a warning: ``` Warning: Version warning: Imagick was compiled against ImageMagick version 1809 but version 1810 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0 ``` This warning is also printed, within the shell executions in Valet. But we use the output of those PHP CLI invocations. With those warnings being printed out, the parsing on the output fails and Valet cannot be used until the pecl extension is rebuilt. With this patch, all CLI PHP invocations use ` -d error_reporting=1`. This suppresses warnings, but will still report errors. It makes valet more robust in case a system package update causes warnings.
1 parent 2c6a935 commit d04efb5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

find-usable-php.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// First, check if the system's linked "php" is 8+; if so, return that. This
66
// is the most likely, most ideal, and fastest possible case
7-
$linkedPhpVersion = shell_exec('php -r "echo phpversion();"');
7+
$linkedPhpVersion = shell_exec('php -d error_reporting=1 -r "echo phpversion();"');
88

99
if (version_compare($linkedPhpVersion, $minimumPhpVersion) >= 0) {
1010
echo exec('which php');

valet

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SOURCE="${BASH_SOURCE[0]}"
77
# do it in pure Bash. So, we'll call into PHP CLI here to resolve.
88
if [[ -L "$SOURCE" ]]
99
then
10-
DIR=$(php -r "echo dirname(realpath('$SOURCE'));")
10+
DIR=$(php -d error_reporting=1 -r "echo dirname(realpath('$SOURCE'));")
1111
else
1212
DIR="$( cd "$( dirname "$SOURCE" )" && pwd )"
1313
fi
@@ -17,15 +17,15 @@ fi
1717
# Valet CLI script which is written in PHP. Will use PHP to do it.
1818
if [ ! -f "$DIR/cli/valet.php" ]
1919
then
20-
DIR=$(php -r "echo realpath('$DIR/../laravel/valet');")
20+
DIR=$(php -d error_reporting=1 -r "echo realpath('$DIR/../laravel/valet');")
2121
fi
2222

2323
# Get a command-line executable we can use for php that's 8+; if this
2424
# is the inside loop (Valet runs itself 2x in some settings), skip
2525
# checking and pulling again by reading the exported env var
2626
if [[ "$PHP_EXECUTABLE" = "" ]]
2727
then
28-
PHP="$(php $DIR/find-usable-php.php)"
28+
PHP="$(php -d error_reporting=1 $DIR/find-usable-php.php)"
2929

3030
# Validate output before running it on the CLI
3131
if [[ ! -f "$PHP" ]]; then
@@ -45,7 +45,7 @@ fi
4545
# process to retrieve the live the share tool tunnel URL in the background.
4646
if [[ "$1" = "share" ]]
4747
then
48-
SHARETOOL="$("$PHP" "$DIR/cli/valet.php" share-tool)"
48+
SHARETOOL="$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" share-tool)"
4949

5050
# Check for parameters to pass through to share tool (these will start with '-' or '--')
5151
PARAMS=(${@:2})
@@ -72,7 +72,7 @@ then
7272

7373
# Lowercase the host to match how the rest of our domains are looked up
7474
HOST=$(echo "$HOST" | tr '[:upper:]' '[:lower:]')
75-
TLD=$("$PHP" "$DIR/cli/valet.php" tld)
75+
TLD=$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" tld)
7676
$(grep --quiet --no-messages 443 ~/.config/valet/Nginx/$HOST*)
7777
SECURED=$?
7878

@@ -140,9 +140,9 @@ elif [[ "$1" = "php" ]]
140140
then
141141
if [[ $2 == *"--site="* ]]; then
142142
SITE=${2#*=}
143-
$("$PHP" "$DIR/cli/valet.php" which-php $SITE) "${@:3}"
143+
$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" which-php $SITE) "${@:3}"
144144
else
145-
$("$PHP" "$DIR/cli/valet.php" which-php) "${@:2}"
145+
$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" which-php) "${@:2}"
146146
fi
147147

148148
exit
@@ -152,9 +152,9 @@ elif [[ "$1" = "composer" ]]
152152
then
153153
if [[ $2 == *"--site="* ]]; then
154154
SITE=${2#*=}
155-
$("$PHP" "$DIR/cli/valet.php" which-php $SITE) $(which composer) "${@:3}"
155+
$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" which-php $SITE) $(which composer) "${@:3}"
156156
else
157-
$("$PHP" "$DIR/cli/valet.php" which-php) $(which composer) "${@:2}"
157+
$("$PHP" -d error_reporting=1 "$DIR/cli/valet.php" which-php) $(which composer) "${@:2}"
158158
fi
159159

160160
exit
@@ -169,5 +169,5 @@ else
169169
exit
170170
fi
171171

172-
"$PHP" "$DIR/cli/valet.php" "$@"
172+
"$PHP" -d error_reporting=1 "$DIR/cli/valet.php" "$@"
173173
fi

0 commit comments

Comments
 (0)