This repository was archived by the owner on Mar 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathGetPHPVersionCmdlet.cs
More file actions
58 lines (50 loc) · 2.1 KB
/
GetPHPVersionCmdlet.cs
File metadata and controls
58 lines (50 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//-----------------------------------------------------------------------
// <copyright>
// Copyright (C) Ruslan Yakushev for the PHP Manager for IIS project.
//
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//-----------------------------------------------------------------------
using System.Management.Automation;
using Microsoft.Web.Administration;
using Web.Management.PHP.Config;
namespace Web.Management.PHP.Powershell
{
[Cmdlet(VerbsCommon.Get, "PHPVersion")]
public sealed class GetPHPVersionCmdlet : BaseCmdlet
{
[Parameter(ValueFromPipelineByPropertyName = true, Position = 0)]
public string HandlerName { get; set; }
[Parameter(ValueFromPipeline = false, Position = 1)]
public string Version { get; set; }
protected override void DoProcessing()
{
using (var serverManager = new ServerManager())
{
var serverManagerWrapper = new ServerManagerWrapper(serverManager, SiteName, VirtualPath);
var configHelper = new PHPConfigHelper(serverManagerWrapper);
var phpVersions = configHelper.GetAllPHPVersions();
var nameWildcard = PrepareWildcardPattern(HandlerName);
var versionWildcard = PrepareWildcardPattern(Version);
var isActive = true;
foreach (var phpVersion in phpVersions)
{
if (!nameWildcard.IsMatch(phpVersion.HandlerName))
{
isActive = false;
continue;
}
if (!versionWildcard.IsMatch(phpVersion.Version))
{
isActive = false;
continue;
}
var versionItem = new PHPVersionItem(phpVersion, isActive);
WriteObject(versionItem);
isActive = false;
}
}
}
}
}