52 lines
1.8 KiB
Bash
52 lines
1.8 KiB
Bash
# Hooks into 'phpenv exec' to augment command line with correct php.ini path.
|
|
# php.ini path is taken from respective .php-ini file (similar to .php-version).
|
|
|
|
# Path to .php-version file or ~/.phpenv/version
|
|
PHPENV_VERSION_FILE="$(phpenv-version-file)"
|
|
# Path to corresponding .php-ini file
|
|
PHPENV_INI_FILE="$(dirname "$PHPENV_VERSION_FILE")/.php-ini"
|
|
# Path to the php.ini file (contents of the .php-ini file), typically /var/www/vhosts/system/$domain/etc/php.ini
|
|
PHPENV_INI="$(phpenv-version-file-read "$PHPENV_INI_FILE")" || :
|
|
|
|
if [ "$PHPENV_COMMAND" = "php" -a -f "$PHPENV_INI" ]; then
|
|
# Check if php.ini should be added to the command line:
|
|
# - add if not explicitly specified
|
|
# - and do not add if composer or /usr/local/bin/wp is called
|
|
HAS_PHP_INI_ARG=
|
|
prev_arg=
|
|
for arg; do
|
|
case "$arg" in
|
|
-c|--php-ini|-n|--no-php-ini)
|
|
HAS_PHP_INI_ARG=yes
|
|
break
|
|
;;
|
|
--) break ;;
|
|
-*) : ;;
|
|
*)
|
|
# The argument could be a file path, check if it could end PHP arguments list
|
|
case "$prev_arg" in
|
|
-F|--process-file|-z|--zend-extension|-t|--docroot) : ;;
|
|
# Previous argument is not empty, i.e. this is not the php binary path (which exists)
|
|
?*)
|
|
if [ -f "$arg" ]; then
|
|
# Treat composer in a special way - don't use .php-ini with it (e.g. due to 'open_basedir')
|
|
! [ "`basename "$arg"`" = "composer.phar" ] || HAS_PHP_INI_ARG=yes
|
|
# Treat wp (wp-cli provided by WP Toolkit) in the same way, to avoid default 'open_basedir' restriction
|
|
! [ "$arg" = "/usr/local/bin/wp" ] || HAS_PHP_INI_ARG=yes
|
|
# Found a file argument to php command, which ends PHP arguments list
|
|
break
|
|
fi
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
prev_arg="$arg"
|
|
done
|
|
unset prev_arg
|
|
|
|
if [ -z "$HAS_PHP_INI_ARG" ]; then
|
|
# Inject '-c php.ini' arguments before other PHP arguments
|
|
set -- "$1" -c "$PHPENV_INI" "${@:2}"
|
|
fi
|
|
fi
|