Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
457cd35
commit 42aac1f
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
id: php | ||
title: php | ||
sidebar_label: php | ||
--- | ||
|
||
## What | ||
|
||
Display the currently active php version. | ||
|
||
## Sample Configuration | ||
|
||
```json | ||
{ | ||
"type": "php", | ||
"style": "powerline", | ||
"powerline_symbol": "\uE0B0", | ||
"foreground": "#ffffff", | ||
"background": "#4063D8", | ||
"properties": { | ||
"prefix": " \ue73d ", | ||
"enable_hyperlink": false | ||
} | ||
} | ||
``` | ||
|
||
## Properties | ||
|
||
- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` | ||
- display_version: `boolean` - display the php version - defaults to `true` | ||
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` | ||
- missing_command_text: `string` - text to display when the command is missing - defaults to empty | ||
- display_mode: `string` - determines when the segment is displayed | ||
- `always`: the segment is always displayed | ||
- `files`: the segment is only displayed when `*.php` files are present (default) | ||
- enable_hyperlink: `bool` - display an hyperlink to the php release notes - defaults to `false` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ module.exports = { | |
"text", | ||
"time", | ||
"ytm", | ||
"php", | ||
], | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
type php struct { | ||
language *language | ||
} | ||
|
||
func (n *php) string() string { | ||
return n.language.string() | ||
} | ||
|
||
func (n *php) init(props *properties, env environmentInfo) { | ||
n.language = &language{ | ||
env: env, | ||
props: props, | ||
extensions: []string{"*.php", "composer.json", ".php-version"}, | ||
commands: []*cmd{ | ||
{ | ||
executable: "php", | ||
args: []string{"--version"}, | ||
regex: `(?:PHP (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`, | ||
}, | ||
}, | ||
versionURLTemplate: "[%[1]s](https://www.php.net/ChangeLog-%[2]s.php#PHP_%[2]s_%[3]s)", | ||
} | ||
} | ||
|
||
func (n *php) enabled() bool { | ||
return n.language.enabled() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPhp(t *testing.T) { | ||
cases := []struct { | ||
Case string | ||
ExpectedString string | ||
Version string | ||
}{ | ||
{Case: "PHP 6.1.0", ExpectedString: "6.1.0", Version: "PHP 6.1.0(cli) (built: Jul 2 2021 03:59:48) ( NTS )"}, | ||
{Case: "php 7.4.21", ExpectedString: "7.4.21", Version: "PHP 7.4.21 (cli) (built: Jul 2 2021 03:59:48) ( NTS )"}, | ||
} | ||
for _, tc := range cases { | ||
params := &mockedLanguageParams{ | ||
cmd: "php", | ||
versionParam: "--version", | ||
versionOutput: tc.Version, | ||
extension: "*.php", | ||
} | ||
env, props := getMockedLanguageEnv(params) | ||
j := &php{} | ||
j.init(props, env) | ||
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case)) | ||
assert.Equal(t, tc.ExpectedString, j.string(), fmt.Sprintf("Failed in case: %s", tc.Case)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters