Skip to content

Commit cdc2ee3

Browse files
committed
CLI colours support and method migration.
Changelog excerpt: - Added colouration to phpMussel's CLI mode (some code has been added to the core to facilitate this). - The atHit method has been migrated from the Loader class to the Scanner class.
1 parent af428a9 commit cdc2ee3

File tree

3 files changed

+138
-126
lines changed

3 files changed

+138
-126
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
127127
### v3.4.1
128128

129129
[2023.09.03; Maikuolan]: Added L10N for Afrikaans and Romanian.
130+
131+
[2023.09.04; Maikuolan]: Added colouration to phpMussel's CLI mode (some code has been added to the core to facilitate this). The atHit method has been migrated from the Loader class to the Scanner class.

src/Loader.php

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2023.08.16).
11+
* This file: The loader (last modified: 2023.09.04).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -93,7 +93,7 @@ class Loader
9393
/**
9494
* @var string phpMussel version number (SemVer).
9595
*/
96-
public $ScriptVersion = '3.4.0';
96+
public $ScriptVersion = '3.4.1';
9797

9898
/**
9999
* @var string phpMussel version identifier (complete notation).
@@ -1269,85 +1269,6 @@ public function loadShorthandData(): bool
12691269
return true;
12701270
}
12711271

1272-
/**
1273-
* Writes to $HashReference, and performs any other needed hit-related actions.
1274-
*
1275-
* @param string $Hash The hash of the item which had a positive hit.
1276-
* @param int $Size The size of the item which had a positive hit.
1277-
* @param string $Name The name of the item which had a positive hit.
1278-
* @param string $Text A human-readable explanation of the hit.
1279-
* @param int $Code The integer results of the scan.
1280-
* @param int $Depth The current depth of the scan process.
1281-
* @return void
1282-
*/
1283-
public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void
1284-
{
1285-
/** Fallback for missing item hash. */
1286-
if ($Hash === '') {
1287-
$Hash = $this->L10N->getString('data_not_available');
1288-
}
1289-
1290-
/** Fallback for missing item name. */
1291-
if ($Name === '') {
1292-
$Name = $this->L10N->getString('data_not_available');
1293-
}
1294-
1295-
/** Ensure that $Text doesn't break lines and clean it up. */
1296-
$Text = preg_replace('~[\x00-\x1F]~', '', $Text);
1297-
1298-
/** Generate hash reference and key for various arrays to be populated. */
1299-
$HashReference = sprintf('%s:%d:%s', $Hash, $Size, $Name);
1300-
if (strpos($this->HashReference, $HashReference . "\n") === false) {
1301-
$this->HashReference .= $HashReference . "\n";
1302-
}
1303-
1304-
$TextLength = strlen($Text);
1305-
1306-
/** Scan results as text. */
1307-
if ($TextLength && isset($this->ScanResultsText[$HashReference]) && strlen($this->ScanResultsText[$HashReference])) {
1308-
$this->ScanResultsText[$HashReference] .= $this->L10N->getString('grammar_spacer') . $Text;
1309-
} else {
1310-
$this->ScanResultsText[$HashReference] = $Text;
1311-
}
1312-
1313-
/** Scan results as integers. */
1314-
if (empty($this->ScanResultsIntegers[$HashReference]) || $this->ScanResultsIntegers[$HashReference] !== 2) {
1315-
$this->ScanResultsIntegers[$HashReference] = $Code;
1316-
}
1317-
1318-
/** Increment detections count. */
1319-
if ($Code !== 0 && $Code !== 1) {
1320-
if (isset($this->InstanceCache['DetectionsCount'])) {
1321-
$this->InstanceCache['DetectionsCount']++;
1322-
} else {
1323-
$this->InstanceCache['DetectionsCount'] = 1;
1324-
}
1325-
}
1326-
1327-
/** Indenting to apply for the formatted scan results . */
1328-
$Indent = str_pad('', ($Depth < 1 ? 4 : ($Depth * 3) + 4), '', STR_PAD_LEFT);
1329-
1330-
/** Fallback for missing text for formatted text. */
1331-
if (!$TextLength) {
1332-
if ($Code === 0) {
1333-
$Text = sprintf(
1334-
$this->L10N->getString('grammar_exclamation_mark'),
1335-
sprintf($this->L10N->getString('x_does_not_exist'), $Name)
1336-
);
1337-
} elseif ($Code === 1) {
1338-
$Text = $this->L10N->getString('scan_no_problems_found');
1339-
} else {
1340-
$Text = $this->L10N->getString('data_not_available');
1341-
}
1342-
}
1343-
1344-
/** Scan results as formatted text. */
1345-
$this->ScanResultsFormatted .= $Indent . $Text . "\n";
1346-
1347-
/** Update flags. */
1348-
$this->InstanceCache['CheckWasLast'] = false;
1349-
}
1350-
13511272
/**
13521273
* Initialise the cache.
13531274
*

0 commit comments

Comments
 (0)