Skip to content

Commit c330ede

Browse files
Merge branch 'release/v1.1.0'
2 parents 42c1945 + 34f6ef7 commit c330ede

File tree

3 files changed

+158
-64
lines changed

3 files changed

+158
-64
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
## [1.1.0] - 2018-08-24
10+
11+
### Added
12+
- Ability to automatically detect WampServer default installation paths (both 32-bit and 64-bit).
13+
- Ability to solely specify WampServer custom installation path.
14+
15+
### Changed
16+
- Updated readme.md
17+
- Fixed spelling mistakes in readme.md
18+
919
## [1.0.0] - 2018-03-23
1020

1121
### Added

README.md

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# WampServer PHP CLI Version Changer
2-
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.
2+
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.
33

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

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

14-
**Note:** To operate seamlessly the Microsoft Windows "cmd.exe" executable must be in your system path. The standard installation path is ``C:\Windows\System32``.
15-
1614
**Tip:** Once you have save the CLI Changer script, create a desktop shortcut to it for quick and easy access.
1715

1816
## Configuration
19-
If using a WampServer 32-bit version with default settings, then no configuration is necessary.
20-
21-
If using a WampServer 64-bit version **OR** a different install path was set during installation, then follow the steps below:
22-
23-
1. Open the CLI Changer script in your preferred text editor.
24-
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.
25-
3. Once you have changed the value, save and close your editor.
17+
No configuration is necessary if your installed WampServer in its default directory.
2618

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

23+
If you installed WampServer in a custom directory, then follow the steps below:
24+
25+
1. Open the CLI Changer script in your preferred text editor.
26+
2. Append your custom install path to the `$customInstallPath` variable.
27+
3. Save the file and close your editor.
28+
3129
Example: A customised WampServer install path.
3230
```
3331
rem +------------------------------------------------+
3432
rem | User Defined Variable(s) |
3533
rem +------------------------------------------------+
3634
37-
rem WampServer install path.
38-
set $pathToInstall=D:\WampServer64
35+
rem WampServer custom install path.
36+
set $customInstallPath=D:\WampServer 64-Bit
3937
```
4038

39+
**IMPORTANT:** Do not add quotation marks around your custom installation path, even if the path contains spaces.
40+
4141
## How To Use
4242
There are two ways you can use the CLI Changer script.
4343

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

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

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

5252
```
5353
Available PHP CLI Versions
@@ -77,7 +77,7 @@ To select a PHP version:
7777

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

80-
**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.
80+
**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.
8181

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

@@ -86,11 +86,17 @@ Should you make an invalid selection or should the selection be the same as the
8686
### Command Line Interface (CLI)
8787
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.
8888

89+
From a CMD prompt:
90+
```
91+
C:\>: "C:\path\to\cli_changer.bat" php7.2.3
92+
```
93+
94+
From a Bash or Powershell prompt:
8995
```
90-
cmd_prompt>: start "path\to\cli_changer.bat" php7.2.3
96+
$ start "C:\path\to\cli_changer.bat" php7.2.3
9197
```
9298

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

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

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

108114
```
109-
ERROR C:/wamp or PHP in PATH"
115+
Error C:/wamp or PHP in PATH
110116
```
111117

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

132138
This error can be suppressed by right-clicking the WampServer icon in the taskbar notification area and selecting: _Wamp Settings -> Do not verify PATH_

cli_changer.bat

+122-44
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ rem +------------------------------------------------+
88
rem | User Defined Variable(s) |
99
rem +------------------------------------------------+
1010

11-
rem WampServer install path.
12-
set $pathToInstall=C:\wamp
11+
rem WampServer custom install path.
12+
set $customInstallPath=
1313

1414

1515

@@ -20,9 +20,12 @@ rem +------------------------------------------------+
2020
rem ---------------------
2121
rem Default Variables
2222
rem ---------------------
23-
set $scriptVersion=1.0.0
23+
set $scriptVersion=1.1.0
2424

25-
set $pathToPhps=bin\php\
25+
set $defaultInstallPath[0]=C:\wamp
26+
set $defaultInstallPath[1]=C:\wamp64
27+
28+
set $pathToPhpFolders=bin\php
2629

2730
set $cliMode=0
2831

@@ -31,6 +34,70 @@ set $colorSuccess=0A
3134
set $colorWarning=0E
3235
set $colorFailure=0C
3336

37+
rem Set the title.
38+
title WampServer PHP CLI Version Changer v%$scriptVersion%
39+
40+
41+
rem -----------------
42+
rem Install Paths
43+
rem -----------------
44+
45+
rem Test for a custom install path.
46+
if defined $customInstallPath (
47+
48+
rem Check if the folder exists.
49+
if not exist "%$customInstallPath%" goto invalidCustomInstallPathGiven
50+
51+
set $installPath=%$customInstallPath%
52+
)
53+
54+
rem Test for the first default install path.
55+
if not defined $installPath (
56+
57+
rem Check if the first default install path exists.
58+
if exist %$defaultInstallPath[0]% (
59+
set $installPath=%$defaultInstallPath[0]%
60+
)
61+
)
62+
63+
rem Test for the second default install path.
64+
if not defined $installPath (
65+
66+
rem Check if the second default install path exists.
67+
if exist %$defaultInstallPath[1]% (
68+
set $installPath=%$defaultInstallPath[1]%
69+
)
70+
)
71+
72+
rem Exit if unable to find installation path.
73+
if not defined $installPath goto defaultInstallPathsMissing
74+
75+
76+
rem -------------------
77+
rem PHP Folder Path
78+
rem -------------------
79+
80+
rem Set the $pathToPhpFolders path.
81+
if %$installPath:~-1% neq \ (
82+
set $pathToPhpFolders=%$installPath%\%$pathToPhpFolders%
83+
) else (
84+
set $pathToPhpFolders=%$installPath%%$pathToPhpFolders%
85+
)
86+
87+
rem Check the $pathToPhpFolders path exists.
88+
if not exist "%$pathToPhpFolders%" goto invalidPathToPhpFoldersGiven
89+
90+
rem Iterate through folders in the the $pathToPhpFolders path adding them to the availablePhpVersionsArray.
91+
set counter=0
92+
93+
for /F "delims=" %%a in ('dir %$pathToPhpFolders% /AD /B') do (
94+
set /A counter=counter+1
95+
set $availablePhpVersionsArray[!counter!]=%%a
96+
)
97+
98+
rem Set the last available PHP versions array id.
99+
set $lastAvailablePhpVersionsArrayId=!counter!
100+
34101

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

59126

60-
rem ---------------------------------
61-
rem Available PHP Folder Versions
62-
rem ---------------------------------
63-
64-
rem Set the $pathToPhps path.
65-
if %$pathToInstall:~-1% neq \ (
66-
set $pathToPhps=%$pathToInstall%\%$pathToPhps%
67-
) else (
68-
set $pathToPhps=%$pathToInstall%%$pathToPhps%
69-
)
70-
71-
rem Check the $pathToPhps path exists.
72-
PUSHD %$pathToPhps% && POPD || (
73-
goto invalidPathToPhpsGiven
74-
)
75-
76-
rem Iterate through folders in the the $pathToPhps path adding them to the availablePhpVersionsArray.
77-
set counter=0
78-
79-
for /F "delims=" %%a in ('dir %$pathToPhps% /AD /B') do (
80-
set /A counter=counter+1
81-
set $availablePhpVersionsArray[!counter!]=%%a
82-
)
83-
84-
rem Set the last available PHP versions array id.
85-
set $lastAvailablePhpVersionsArrayId=!counter!
86-
87-
88127
rem ----------------------------
89128
rem Match PHP Folder Version
90129
rem ----------------------------
@@ -99,7 +138,7 @@ for /L %%a in (1,1,%$lastUsersEnvironmentalPathArrayId%) do (
99138
rem Loop through the $availablePhpVersionsArray.
100139
for /L %%b in (1,1,%$lastAvailablePhpVersionsArrayId%) do (
101140
rem Check if the users environmental path string matches the path to the available PHP version string.
102-
if "!$usersEnvironmentalPathArray[%%a]!"=="%$pathToPhps%!$availablePhpVersionsArray[%%b]!" (
141+
if "!$usersEnvironmentalPathArray[%%a]!"=="%$pathToPhpFolders%!$availablePhpVersionsArray[%%b]!" (
103142
rem Force the 'for' command parameters into type 'integer'.
104143
set /A $currentPhpVersionId=currentPhpVersionId+%%b
105144
set /A $currentUserEnvPathId=$currentUserEnvPathId+%%a
@@ -146,17 +185,15 @@ rem Display PHP Versions
146185
rem ------------------------
147186

148187
rem Set the window.
149-
title WampServer PHP CLI Version Changer v%$scriptVersion%
150188
color %$colorNormal%
151189

152-
153-
rem Show the title.
190+
rem Show the header.
154191
echo:
155192
echo Available PHP CLI Versions
156193
echo --------------------------
157194
echo:
158195

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

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

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

209246

210-
rem --------------------
211-
rem Exit Subroutines
212-
rem --------------------
247+
rem ------------------------------
248+
rem Exit Subroutines - Success
249+
rem ------------------------------
213250

214251
rem The update was successful.
215252
:updateSuccessful
@@ -237,6 +274,11 @@ if %$cliMode% equ 0 (
237274

238275
exit 0
239276

277+
278+
rem ------------------------------
279+
rem Exit Subroutines - Failure
280+
rem ------------------------------
281+
240282
rem An invalid selection was given.
241283
:invalidSelectionGiven
242284

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

251293
exit 1
252294

253-
rem An invalid $pathToPhps was given.
254-
:invalidPathToPhpsGiven
295+
rem ----------------------------
296+
rem Exit Subroutines - Error
297+
rem ----------------------------
298+
299+
rem An invalid $customInstallPath was given.
300+
:invalidCustomInstallPathGiven
301+
302+
if %$cliMode% equ 0 (
303+
color %$colorFailure%
304+
echo:
305+
echo The $customInstallPath path "%$customInstallPath%" does not exist.
306+
echo:
307+
echo Press any key to exit.
308+
pause >nul
309+
)
310+
311+
exit 1
312+
313+
rem Both of the default install paths are missing.
314+
:defaultInstallPathsMissing
315+
if %$cliMode% equ 0 (
316+
color %$colorFailure%
317+
echo:
318+
echo Neither of the default install paths exists.
319+
echo:
320+
echo 1. %$defaultInstallPath[0]%
321+
echo 2. %$defaultInstallPath[1]%
322+
echo:
323+
echo Wampserver does not appear to be installed.
324+
echo:
325+
echo Press any key to exit.
326+
pause >nul
327+
)
328+
329+
exit 1
330+
331+
rem An invalid $pathToPhpFolders was given.
332+
:invalidPathToPhpFoldersGiven
255333

256334
if %$cliMode% equ 0 (
257335
color %$colorFailure%
258336
echo:
259-
echo The $pathToPhps path "%$pathToPhps%" does not exist.
337+
echo The $pathToPhpFolders path "%$pathToPhpFolders%" does not exist.
260338
echo:
261339
echo See the WampServer website for help.
262340
echo:

0 commit comments

Comments
 (0)