Skip to content

Commit 1a6d5d0

Browse files
committed
Implemented the usage of the system PHP interpreter
1 parent 579661c commit 1a6d5d0

File tree

9 files changed

+696
-202
lines changed

9 files changed

+696
-202
lines changed

bin/phpbrew

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
#!/usr/bin/env php
22
<?php
33

4+
if (PHP_VERSION_ID < 70200) {
5+
fwrite(
6+
STDERR,
7+
sprintf(
8+
'This version of PHPBrew is supported on PHP 7.2.0 or newer' . PHP_EOL .
9+
'You are using PHP %s (%s).' . PHP_EOL,
10+
PHP_VERSION,
11+
PHP_BINARY
12+
)
13+
);
14+
15+
die(1);
16+
}
17+
418
$includeIfExists = function($file)
519
{
620
return file_exists($file) ? include $file : false;

completion/bash/_phpbrew

+266-2
Original file line numberDiff line numberDiff line change
@@ -6660,6 +6660,270 @@ local argument_min_length=0
66606660
fi
66616661
fi
66626662
};
6663+
___phpbrew_complete_system ()
6664+
{
6665+
local comp_prefix=___phpbrew
6666+
6667+
local cur words cword prev
6668+
_get_comp_words_by_ref -n =: cur words cword prev
6669+
6670+
local command_signature=$1
6671+
local command_index=$2
6672+
6673+
((command_index++))
6674+
6675+
# Output application command alias mapping
6676+
# aliases[ alias ] = command
6677+
declare -A subcommand_alias
6678+
6679+
# Define the command names
6680+
declare -A subcommands
6681+
6682+
declare -A subcommand_signs
6683+
6684+
# option names defines the available options of this command
6685+
declare -A options
6686+
# options_require_value: defines the required completion type for each
6687+
# option that requires a value.
6688+
declare -A options_require_value
6689+
subcommands=()
6690+
subcommand_alias=()
6691+
subcommand_signs=()
6692+
options=()
6693+
options_require_value=()
6694+
local argument_min_length=1
6695+
6696+
# Get the command name chain of the current input, e.g.
6697+
#
6698+
# app asset install [arg1] [arg2] [arg3]
6699+
# app commit add
6700+
#
6701+
# The subcommand dispatch should be done in the command complete function,
6702+
# not in the root completion function.
6703+
# We should pass the argument index to the complete function.
6704+
6705+
# command_index=1 start from the first argument, not the application name
6706+
# Find the command position
6707+
local argument_index=0
6708+
local i
6709+
local command
6710+
local found_options=0
6711+
6712+
# echo "[DEBUG] command_index: [$command_signature] [$command_index]"
6713+
6714+
while [ $command_index -lt $cword ]; do
6715+
i="${words[command_index]}"
6716+
case "$i" in
6717+
# Ignore options
6718+
--=*) found_options=1 ;;
6719+
--*) found_options=1 ;;
6720+
-*) found_options=1 ;;
6721+
*)
6722+
# looks like my command, that's break the loop and dispatch to the next complete function
6723+
if [[ -n "$i" && -n "${subcommands[$i]}" ]] ; then
6724+
command="$i"
6725+
break
6726+
elif [[ -n "$i" && -n "${subcommand_alias[$i]}" ]] ; then
6727+
command="$i"
6728+
break
6729+
elif [[ $command_index -gt 1 ]] ; then
6730+
# If the command is not found, check if the previous argument is an option expecting a value
6731+
# or it is an argument
6732+
6733+
# the previous argument (might be)
6734+
p="${words[command_index-1]}"
6735+
6736+
# not an option value, push to the argument list
6737+
if [[ -z "${options_require_value[$p]}" ]] ; then
6738+
# echo "[DEBUG] argument_index++ because of [$i]"
6739+
((argument_index++))
6740+
fi
6741+
fi
6742+
;;
6743+
esac
6744+
((command_index++))
6745+
done
6746+
6747+
# If the first command name is not found, we do complete...
6748+
if [[ -z "$command" ]] ; then
6749+
case "$cur" in
6750+
# If the current argument $cur looks like an option, then we should complete
6751+
-*)
6752+
__mycomp "${!options[*]}"
6753+
return
6754+
;;
6755+
*)
6756+
# The argument here can be an option value. e.g. --output-dir /tmp
6757+
# The the previous one...
6758+
if [[ -n "$prev" && -n "${options_require_value[$prev]}" ]] ; then
6759+
# TODO: local complete_type="${options_require_value[$prev]"}
6760+
__complete_meta "$command_signature" "opt" "${prev##*(-)}" "valid-values"
6761+
return
6762+
fi
6763+
# If the command requires at least $argument_min_length to run, we check the argument
6764+
if [[ $argument_min_length > 0 ]] ; then
6765+
case $argument_index in
6766+
0)
6767+
__complete_meta "$command_signature" "arg" 0 "suggestions"
6768+
return
6769+
;;
6770+
esac
6771+
fi
6772+
6773+
# If there is no argument support, then user is supposed to give a subcommand name or an option
6774+
__mycomp "${!options[*]} ${!subcommands[*]} ${!subcommand_alias[*]}"
6775+
return
6776+
;;
6777+
esac
6778+
6779+
else
6780+
# We just found the first command, we are going to dispatch the completion handler to the next level...
6781+
# Rewrite command alias to command name to get the correct response
6782+
if [[ -n "${subcommand_alias[$command]}" ]] ; then
6783+
command="${subcommand_alias[$command]}"
6784+
fi
6785+
6786+
if [[ -n "${subcommand_signs[$command]}" ]] ; then
6787+
local suffix="${subcommand_signs[$command]}"
6788+
local completion_func="${comp_prefix}_complete_${suffix//-/_}"
6789+
6790+
# Declare the completion function name and dispatch rest arguments to the complete function
6791+
command_signature="${command_signature}.${command}"
6792+
declare -f $completion_func >/dev/null && \
6793+
$completion_func $command_signature $command_index && return
6794+
else
6795+
echo "Command '$command' not found"
6796+
fi
6797+
fi
6798+
};
6799+
___phpbrew_complete_system-off ()
6800+
{
6801+
local comp_prefix=___phpbrew
6802+
6803+
local cur words cword prev
6804+
_get_comp_words_by_ref -n =: cur words cword prev
6805+
6806+
local command_signature=$1
6807+
local command_index=$2
6808+
6809+
((command_index++))
6810+
6811+
# Output application command alias mapping
6812+
# aliases[ alias ] = command
6813+
declare -A subcommand_alias
6814+
6815+
# Define the command names
6816+
declare -A subcommands
6817+
6818+
declare -A subcommand_signs
6819+
6820+
# option names defines the available options of this command
6821+
declare -A options
6822+
# options_require_value: defines the required completion type for each
6823+
# option that requires a value.
6824+
declare -A options_require_value
6825+
subcommands=()
6826+
subcommand_alias=()
6827+
subcommand_signs=()
6828+
options=()
6829+
options_require_value=()
6830+
local argument_min_length=0
6831+
6832+
# Get the command name chain of the current input, e.g.
6833+
#
6834+
# app asset install [arg1] [arg2] [arg3]
6835+
# app commit add
6836+
#
6837+
# The subcommand dispatch should be done in the command complete function,
6838+
# not in the root completion function.
6839+
# We should pass the argument index to the complete function.
6840+
6841+
# command_index=1 start from the first argument, not the application name
6842+
# Find the command position
6843+
local argument_index=0
6844+
local i
6845+
local command
6846+
local found_options=0
6847+
6848+
# echo "[DEBUG] command_index: [$command_signature] [$command_index]"
6849+
6850+
while [ $command_index -lt $cword ]; do
6851+
i="${words[command_index]}"
6852+
case "$i" in
6853+
# Ignore options
6854+
--=*) found_options=1 ;;
6855+
--*) found_options=1 ;;
6856+
-*) found_options=1 ;;
6857+
*)
6858+
# looks like my command, that's break the loop and dispatch to the next complete function
6859+
if [[ -n "$i" && -n "${subcommands[$i]}" ]] ; then
6860+
command="$i"
6861+
break
6862+
elif [[ -n "$i" && -n "${subcommand_alias[$i]}" ]] ; then
6863+
command="$i"
6864+
break
6865+
elif [[ $command_index -gt 1 ]] ; then
6866+
# If the command is not found, check if the previous argument is an option expecting a value
6867+
# or it is an argument
6868+
6869+
# the previous argument (might be)
6870+
p="${words[command_index-1]}"
6871+
6872+
# not an option value, push to the argument list
6873+
if [[ -z "${options_require_value[$p]}" ]] ; then
6874+
# echo "[DEBUG] argument_index++ because of [$i]"
6875+
((argument_index++))
6876+
fi
6877+
fi
6878+
;;
6879+
esac
6880+
((command_index++))
6881+
done
6882+
6883+
# If the first command name is not found, we do complete...
6884+
if [[ -z "$command" ]] ; then
6885+
case "$cur" in
6886+
# If the current argument $cur looks like an option, then we should complete
6887+
-*)
6888+
__mycomp "${!options[*]}"
6889+
return
6890+
;;
6891+
*)
6892+
# The argument here can be an option value. e.g. --output-dir /tmp
6893+
# The the previous one...
6894+
if [[ -n "$prev" && -n "${options_require_value[$prev]}" ]] ; then
6895+
# TODO: local complete_type="${options_require_value[$prev]"}
6896+
__complete_meta "$command_signature" "opt" "${prev##*(-)}" "valid-values"
6897+
return
6898+
fi
6899+
# If the command requires at least $argument_min_length to run, we check the argument
6900+
6901+
# If there is no argument support, then user is supposed to give a subcommand name or an option
6902+
__mycomp "${!options[*]} ${!subcommands[*]} ${!subcommand_alias[*]}"
6903+
return
6904+
;;
6905+
esac
6906+
6907+
else
6908+
# We just found the first command, we are going to dispatch the completion handler to the next level...
6909+
# Rewrite command alias to command name to get the correct response
6910+
if [[ -n "${subcommand_alias[$command]}" ]] ; then
6911+
command="${subcommand_alias[$command]}"
6912+
fi
6913+
6914+
if [[ -n "${subcommand_signs[$command]}" ]] ; then
6915+
local suffix="${subcommand_signs[$command]}"
6916+
local completion_func="${comp_prefix}_complete_${suffix//-/_}"
6917+
6918+
# Declare the completion function name and dispatch rest arguments to the complete function
6919+
command_signature="${command_signature}.${command}"
6920+
declare -f $completion_func >/dev/null && \
6921+
$completion_func $command_signature $command_index && return
6922+
else
6923+
echo "Command '$command' not found"
6924+
fi
6925+
fi
6926+
};
66636927
___phpbrew_complete_phpbrew ()
66646928
{
66656929
local comp_prefix=___phpbrew
@@ -6686,9 +6950,9 @@ local comp_prefix=___phpbrew
66866950
# options_require_value: defines the required completion type for each
66876951
# option that requires a value.
66886952
declare -A options_require_value
6689-
subcommands=(["help"]="Show help message of a command" ["zsh"]="This function generate a zsh-completion script automatically" ["bash"]="This command generate a bash completion script automatically" ["meta"]="Return the meta data of a commands." ["compile"]="compile current source into Phar format library file." ["archive"]="Build executable phar file from composer.json" ["github:build-topics"]="Build topic classes from the wiki of a GitHub Project." ["app"]="[deprecated] php app store" ["init"]="Initialize phpbrew config file." ["known"]="List known PHP versions" ["install"]="Install php" ["list"]="List installed PHPs" ["use"]="Use php, switch version temporarily" ["switch"]="Switch default php version." ["each"]="Iterate and run a given shell command over all php versions managed by PHPBrew." ["config"]="Edit your current php.ini in your favorite $EDITOR" ["info"]="Show current php information" ["env"]="Export environment variables" ["extension"]="List extensions or execute extension subcommands" ["variants"]="List php variants" ["path"]="Show paths of the current PHP." ["cd"]="Change to directories" ["download"]="Download php" ["clean"]="Clean up the source directory of a PHP distribution" ["update"]="Update PHP release source file" ["ctags"]="Run ctags at current php source dir for extension development." ["fpm"]="fpm commands" ["list-ini"]="List loaded ini config files." ["self-update"]="Self-update, default to master version" ["remove"]="Remove installed php build." ["purge"]="Remove installed php version and config files." ["off"]="Temporarily go back to the system php" ["switch-off"]="Definitely go back to the system php" )
6953+
subcommands=(["help"]="Show help message of a command" ["zsh"]="This function generate a zsh-completion script automatically" ["bash"]="This command generate a bash completion script automatically" ["meta"]="Return the meta data of a commands." ["compile"]="compile current source into Phar format library file." ["archive"]="Build executable phar file from composer.json" ["github:build-topics"]="Build topic classes from the wiki of a GitHub Project." ["app"]="[deprecated] php app store" ["init"]="Initialize phpbrew config file." ["known"]="List known PHP versions" ["install"]="Install php" ["list"]="List installed PHPs" ["use"]="Use php, switch version temporarily" ["switch"]="Switch default php version." ["each"]="Iterate and run a given shell command over all php versions managed by PHPBrew." ["config"]="Edit your current php.ini in your favorite $EDITOR" ["info"]="Show current php information" ["env"]="Export environment variables" ["extension"]="List extensions or execute extension subcommands" ["variants"]="List php variants" ["path"]="Show paths of the current PHP." ["cd"]="Change to directories" ["download"]="Download php" ["clean"]="Clean up the source directory of a PHP distribution" ["update"]="Update PHP release source file" ["ctags"]="Run ctags at current php source dir for extension development." ["fpm"]="fpm commands" ["list-ini"]="List loaded ini config files." ["self-update"]="Self-update, default to master version" ["remove"]="Remove installed php build." ["purge"]="Remove installed php version and config files." ["off"]="Temporarily go back to the system php" ["switch-off"]="Definitely go back to the system php" ["system"]="Get or set the internally used PHP binary" ["system-off"]="Use the currently effective PHP binary internally" )
66906954
subcommand_alias=(["a"]="archive" ["ar"]="archive" ["i"]="install" ["ins"]="install" ["ext"]="extension" )
6691-
subcommand_signs=(["help"]="help" ["zsh"]="zsh" ["bash"]="bash" ["meta"]="meta" ["compile"]="compile" ["archive"]="archive" ["github:build-topics"]="github:build-topics" ["app"]="app" ["init"]="init" ["known"]="known" ["install"]="install" ["list"]="list" ["use"]="use" ["switch"]="switch" ["each"]="each" ["config"]="config" ["info"]="info" ["env"]="env" ["extension"]="extension" ["variants"]="variants" ["path"]="path" ["cd"]="cd" ["download"]="download" ["clean"]="clean" ["update"]="update" ["ctags"]="ctags" ["fpm"]="fpm" ["list-ini"]="list-ini" ["self-update"]="self-update" ["remove"]="remove" ["purge"]="purge" ["off"]="off" ["switch-off"]="switch-off" )
6955+
subcommand_signs=(["help"]="help" ["zsh"]="zsh" ["bash"]="bash" ["meta"]="meta" ["compile"]="compile" ["archive"]="archive" ["github:build-topics"]="github:build-topics" ["app"]="app" ["init"]="init" ["known"]="known" ["install"]="install" ["list"]="list" ["use"]="use" ["switch"]="switch" ["each"]="each" ["config"]="config" ["info"]="info" ["env"]="env" ["extension"]="extension" ["variants"]="variants" ["path"]="path" ["cd"]="cd" ["download"]="download" ["clean"]="clean" ["update"]="update" ["ctags"]="ctags" ["fpm"]="fpm" ["list-ini"]="list-ini" ["self-update"]="self-update" ["remove"]="remove" ["purge"]="purge" ["off"]="off" ["switch-off"]="switch-off" ["system"]="system" ["system-off"]="system-off" )
66926956
options=(["-v"]="1" ["--verbose"]="1" ["-d"]="1" ["--debug"]="1" ["-q"]="1" ["--quiet"]="1" ["-h"]="1" ["--help"]="1" ["--version"]="1" ["-p"]="1" ["--profile"]="1" ["--log-path"]="1" ["--no-interact"]="1" ["--no-progress"]="1" )
66936957
options_require_value=()
66946958
local argument_min_length=0

completion/zsh/_phpbrew

+11
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ local ret=1
9090
purge:'Remove installed php version and config files.'
9191
off:'Temporarily go back to the system php'
9292
switch-off:'Definitely go back to the system php'
93+
system:'Get or set the internally used PHP binary'
94+
system-off:'Use the currently effective PHP binary internally'
9395
)
9496
_describe -t commands 'command' commands && ret=0
9597
;;
@@ -506,6 +508,15 @@ local ret=1
506508
;;
507509
(switch-off)
508510

511+
;;
512+
(system)
513+
_arguments -w -S -s \
514+
':php version:{___phpbrewmeta "php version" system arg 0 suggestions}' \
515+
&& ret=0
516+
517+
;;
518+
(system-off)
519+
509520
;;
510521
esac
511522
;;

0 commit comments

Comments
 (0)