Skip to content

Instantly share code, notes, and snippets.

@ThomasWeinert
Created March 13, 2021 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasWeinert/f8259506ef8503ff0c4b3a6b299d5686 to your computer and use it in GitHub Desktop.
Save ThomasWeinert/f8259506ef8503ff0c4b3a6b299d5686 to your computer and use it in GitHub Desktop.
Allow for switch between multiple PHP versions. Expects the PHP version to be in subdirectories `PHP_%VERSION%` (PHP_8.0.4).
@echo off & setlocal enabledelayedexpansion
IF "%~1"=="" GOTO Help
IF "%~1"=="list" GOTO ListVersion
IF "%~1"=="bat" GOTO CreateBatchFiles
:LINK_VERSION
set PHP_VERSION=%1
set PHP_BASE_PATH=%~dp0
set "PHP_BINARY=%~dp0PHP_%PHP_VERSION%\php"
@echo Selected %PHP_BINARY%
for /f "tokens=2" %%i in ('"%PHP_BINARY%" -v') do (
rmdir "%PHP_BASE_PATH%Current"
mklink /J %PHP_BASE_PATH%Current "%PHP_BASE_PATH%PHP_%%i"
GOTO end
)
:ListVersion
for /d %%D in (%~dp0\PHP_*) do (
SET FILE_NAME=%%~nxD
@echo !FILE_NAME:~4!
)
GOTO end
:CreateBatchFiles
@echo Create Batch Files
for /d %%D in (%~dp0\PHP_*) do (
SET PHP_PATH=%%~fD
SET PHP_FOLDER=%%~nxD
if exist !PHP_PATH!\php.exe (
SET PHP_BAT_FILE=!PHP_PATH!.bat
echo !PHP_BAT_FILE!
(
echo @echo off
echo %%~dp0!PHP_FOLDER!\php %%*
) >!PHP_BAT_FILE!
)
)
GOTO end
:Help
SET BAT_FILE=%~n0
echo Commands:
echo List: %BAT_FILE% list
echo Activate: %BAT_FILE% 8.0.3
echo Create batch files: %BAT_FILE% bat
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment