Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
midnight-coding committed Nov 8, 2018
2 parents 42c1945 + 34f6ef7 commit c330ede
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 64 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [1.1.0] - 2018-08-24

### Added
- Ability to automatically detect WampServer default installation paths (both 32-bit and 64-bit).
- Ability to solely specify WampServer custom installation path.

### Changed
- Updated readme.md
- Fixed spelling mistakes in readme.md

## [1.0.0] - 2018-03-23

### Added
Expand Down
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WampServer PHP CLI Version Changer
WampServer PHP CLI version changer is a Microsoft Windows batch script that allows you to easily add and then change between available WampServer PHP CLI versions using the users environmental path.
WampServer PHP CLI Version Changer is a Microsoft Windows batch script that allows you to easily change between installed WampServer PHP CLI versions using the users environmental path.

## Minimum Requirements
The following are required for the CLI Changer script to function correctly.
Expand All @@ -11,43 +11,43 @@ No installation is required.

At just over 7kB the CLI Changer script is small enough to be saved anywhere in your file system.

**Note:** To operate seamlessly the Microsoft Windows "cmd.exe" executable must be in your system path. The standard installation path is ``C:\Windows\System32``.

**Tip:** Once you have save the CLI Changer script, create a desktop shortcut to it for quick and easy access.

## Configuration
If using a WampServer 32-bit version with default settings, then no configuration is necessary.

If using a WampServer 64-bit version **OR** a different install path was set during installation, then follow the steps below:

1. Open the CLI Changer script in your preferred text editor.
2. Change the value of the `$pathToInstall` variable to match that of your WampServer install path, taking care **not to** use quotes around the value.
3. Once you have changed the value, save and close your editor.
No configuration is necessary if your installed WampServer in its default directory.

For reference, the default WampServer install paths are:
The default installation directories are:
- `C:\wamp` - For 32-bit installations.
- `C:\wamp64` - For 64-bit installations.

If you installed WampServer in a custom directory, then follow the steps below:

1. Open the CLI Changer script in your preferred text editor.
2. Append your custom install path to the `$customInstallPath` variable.
3. Save the file and close your editor.

Example: A customised WampServer install path.
```
rem +------------------------------------------------+
rem | User Defined Variable(s) |
rem +------------------------------------------------+
rem WampServer install path.
set $pathToInstall=D:\WampServer64
rem WampServer custom install path.
set $customInstallPath=D:\WampServer 64-Bit
```

**IMPORTANT:** Do not add quotation marks around your custom installation path, even if the path contains spaces.

## How To Use
There are two ways you can use the CLI Changer script.

* Text based user interface (TUI).
* Command line interface (CLI).

### Text Based User Interface (TUI)
Upon running the CLI Changer script you will be presented with a numbered list of available PHP versions that you can select from.
Upon running the CLI Changer script you will be presented with a numbered list of installed PHP versions that you can select from.

The exact list of available PHP CLI versions is dependent on what you currently have in your WampServer PHP addon folder.
The exact list of installed PHP CLI versions is dependent on what you currently have in your WampServer PHP addon folder.

```
Available PHP CLI Versions
Expand Down Expand Up @@ -77,7 +77,7 @@ To select a PHP version:

The CLI Changer script will display the newly set PHP version number and prompt you to press any key to exit.

**Note:** The newly selected PHP version will only be available to new command line windows opened after the change. Existing windows will still reference any previously set PHP version.
**Note:** The newly selected PHP version will only be available to new command line windows. Existing windows will still reference the previously set PHP version.

To exit the CLI Changer script without making any changes just press the ENTER key.

Expand All @@ -86,11 +86,17 @@ Should you make an invalid selection or should the selection be the same as the
### Command Line Interface (CLI)
To update the PHP CLI version number directly from the command line, you can pass in the desired PHP version via the scripts first argument. This will bypass the selection screen and go straight to setting the desired version number.

From a CMD prompt:
```
C:\>: "C:\path\to\cli_changer.bat" php7.2.3
```

From a Bash or Powershell prompt:
```
cmd_prompt>: start "path\to\cli_changer.bat" php7.2.3
$ start "C:\path\to\cli_changer.bat" php7.2.3
```

**Note 1:** You will need to enclose the scripts path in double quotation marks if the path contains any spaces.
**Note 1:** You will need to enclose the CLI Changer script path in quotes if the path contains any spaces.

**Note 2:** You will need to know the available PHP CLI version(s) in advance prior to using this command.

Expand All @@ -106,7 +112,7 @@ Following execution, an exit code will be given:
As of WampServer v3.1.2 the below error message may be displayed.

```
ERROR C:/wamp or PHP in PATH"
Error C:/wamp or PHP in PATH
```

Clicking on this error will open a command window displaying the below message.
Expand All @@ -126,7 +132,7 @@ Wampserver does not use, modify or require the PATH environmental variable.
Using a PATH on Wampserver or PHP version
is detrimental to the proper functioning of Wampserver.
Press ENTER top continue...
Press ENTER to continue...
```

This error can be suppressed by right-clicking the WampServer icon in the taskbar notification area and selecting: _Wamp Settings -> Do not verify PATH_
Expand Down
166 changes: 122 additions & 44 deletions cli_changer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ rem +------------------------------------------------+
rem | User Defined Variable(s) |
rem +------------------------------------------------+

rem WampServer install path.
set $pathToInstall=C:\wamp
rem WampServer custom install path.
set $customInstallPath=



Expand All @@ -20,9 +20,12 @@ rem +------------------------------------------------+
rem ---------------------
rem Default Variables
rem ---------------------
set $scriptVersion=1.0.0
set $scriptVersion=1.1.0

set $pathToPhps=bin\php\
set $defaultInstallPath[0]=C:\wamp
set $defaultInstallPath[1]=C:\wamp64

set $pathToPhpFolders=bin\php

set $cliMode=0

Expand All @@ -31,6 +34,70 @@ set $colorSuccess=0A
set $colorWarning=0E
set $colorFailure=0C

rem Set the title.
title WampServer PHP CLI Version Changer v%$scriptVersion%


rem -----------------
rem Install Paths
rem -----------------

rem Test for a custom install path.
if defined $customInstallPath (

rem Check if the folder exists.
if not exist "%$customInstallPath%" goto invalidCustomInstallPathGiven

set $installPath=%$customInstallPath%
)

rem Test for the first default install path.
if not defined $installPath (

rem Check if the first default install path exists.
if exist %$defaultInstallPath[0]% (
set $installPath=%$defaultInstallPath[0]%
)
)

rem Test for the second default install path.
if not defined $installPath (

rem Check if the second default install path exists.
if exist %$defaultInstallPath[1]% (
set $installPath=%$defaultInstallPath[1]%
)
)

rem Exit if unable to find installation path.
if not defined $installPath goto defaultInstallPathsMissing


rem -------------------
rem PHP Folder Path
rem -------------------

rem Set the $pathToPhpFolders path.
if %$installPath:~-1% neq \ (
set $pathToPhpFolders=%$installPath%\%$pathToPhpFolders%
) else (
set $pathToPhpFolders=%$installPath%%$pathToPhpFolders%
)

rem Check the $pathToPhpFolders path exists.
if not exist "%$pathToPhpFolders%" goto invalidPathToPhpFoldersGiven

rem Iterate through folders in the the $pathToPhpFolders path adding them to the availablePhpVersionsArray.
set counter=0

for /F "delims=" %%a in ('dir %$pathToPhpFolders% /AD /B') do (
set /A counter=counter+1
set $availablePhpVersionsArray[!counter!]=%%a
)

rem Set the last available PHP versions array id.
set $lastAvailablePhpVersionsArrayId=!counter!


rem ----------------------------
rem Users Environmental Path
Expand All @@ -57,34 +124,6 @@ rem Set the last users environmental path array id.
set $lastUsersEnvironmentalPathArrayId=!counter!


rem ---------------------------------
rem Available PHP Folder Versions
rem ---------------------------------

rem Set the $pathToPhps path.
if %$pathToInstall:~-1% neq \ (
set $pathToPhps=%$pathToInstall%\%$pathToPhps%
) else (
set $pathToPhps=%$pathToInstall%%$pathToPhps%
)

rem Check the $pathToPhps path exists.
PUSHD %$pathToPhps% && POPD || (
goto invalidPathToPhpsGiven
)

rem Iterate through folders in the the $pathToPhps path adding them to the availablePhpVersionsArray.
set counter=0

for /F "delims=" %%a in ('dir %$pathToPhps% /AD /B') do (
set /A counter=counter+1
set $availablePhpVersionsArray[!counter!]=%%a
)

rem Set the last available PHP versions array id.
set $lastAvailablePhpVersionsArrayId=!counter!


rem ----------------------------
rem Match PHP Folder Version
rem ----------------------------
Expand All @@ -99,7 +138,7 @@ for /L %%a in (1,1,%$lastUsersEnvironmentalPathArrayId%) do (
rem Loop through the $availablePhpVersionsArray.
for /L %%b in (1,1,%$lastAvailablePhpVersionsArrayId%) do (
rem Check if the users environmental path string matches the path to the available PHP version string.
if "!$usersEnvironmentalPathArray[%%a]!"=="%$pathToPhps%!$availablePhpVersionsArray[%%b]!" (
if "!$usersEnvironmentalPathArray[%%a]!"=="%$pathToPhpFolders%!$availablePhpVersionsArray[%%b]!" (
rem Force the 'for' command parameters into type 'integer'.
set /A $currentPhpVersionId=currentPhpVersionId+%%b
set /A $currentUserEnvPathId=$currentUserEnvPathId+%%a
Expand Down Expand Up @@ -146,17 +185,15 @@ rem Display PHP Versions
rem ------------------------

rem Set the window.
title WampServer PHP CLI Version Changer v%$scriptVersion%
color %$colorNormal%


rem Show the title.
rem Show the header.
echo:
echo Available PHP CLI Versions
echo --------------------------
echo:

rem Display all available list of PHP folder names.
rem List all installed PHP folder names.
for /L %%a in (1,1,%$lastAvailablePhpVersionsArrayId%) do (
if %%a equ %$currentPhpVersionId% (
echo %%a - !$availablePhpVersionsArray[%%a]! - Current
Expand Down Expand Up @@ -201,15 +238,15 @@ for /L %%a in (1,1,%$lastUsersEnvironmentalPathArrayId%) do (
)

rem Add the selected PHP folder path to the end of the $usersEnvironmentalPathString.
set $result=%$result%%$pathToPhps%!$availablePhpVersionsArray[%$newSelectionId%]!
set $result=%$result%%$pathToPhpFolders%!$availablePhpVersionsArray[%$newSelectionId%]!

rem Set the $usersEnvironmentalPathString.
setx path "%$result%" >nul


rem --------------------
rem Exit Subroutines
rem --------------------
rem ------------------------------
rem Exit Subroutines - Success
rem ------------------------------

rem The update was successful.
:updateSuccessful
Expand Down Expand Up @@ -237,6 +274,11 @@ if %$cliMode% equ 0 (

exit 0


rem ------------------------------
rem Exit Subroutines - Failure
rem ------------------------------

rem An invalid selection was given.
:invalidSelectionGiven

Expand All @@ -250,13 +292,49 @@ if %$cliMode% equ 0 (

exit 1

rem An invalid $pathToPhps was given.
:invalidPathToPhpsGiven
rem ----------------------------
rem Exit Subroutines - Error
rem ----------------------------

rem An invalid $customInstallPath was given.
:invalidCustomInstallPathGiven

if %$cliMode% equ 0 (
color %$colorFailure%
echo:
echo The $customInstallPath path "%$customInstallPath%" does not exist.
echo:
echo Press any key to exit.
pause >nul
)

exit 1

rem Both of the default install paths are missing.
:defaultInstallPathsMissing
if %$cliMode% equ 0 (
color %$colorFailure%
echo:
echo Neither of the default install paths exists.
echo:
echo 1. %$defaultInstallPath[0]%
echo 2. %$defaultInstallPath[1]%
echo:
echo Wampserver does not appear to be installed.
echo:
echo Press any key to exit.
pause >nul
)

exit 1

rem An invalid $pathToPhpFolders was given.
:invalidPathToPhpFoldersGiven

if %$cliMode% equ 0 (
color %$colorFailure%
echo:
echo The $pathToPhps path "%$pathToPhps%" does not exist.
echo The $pathToPhpFolders path "%$pathToPhpFolders%" does not exist.
echo:
echo See the WampServer website for help.
echo:
Expand Down

0 comments on commit c330ede

Please sign in to comment.