Skip to content

Commit 3c98fc6

Browse files
committed
Unify file reading methods.
Changelog excerpt: - Unified the methods for reading files to a singular method.
1 parent 0b71c5e commit 3c98fc6

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
133133
[2023.09.16~18; Maikuolan]: Significantly refactored all L10N data.
134134

135135
[2023.09.18; Maikuolan]: Better resource guarding.
136+
137+
[2023.09.25; Maikuolan]: Unified the methods for reading files to a singular method.

src/Loader.php

+4-26
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class Loader
174174
private $Channels = [];
175175

176176
/**
177-
* @var int The default blocksize for readFileContent and readFileContentGZ.
177+
* @var int The default blocksize for readFileGZ.
178178
*/
179179
private $Blocksize = 131072;
180180

@@ -349,7 +349,7 @@ public function __construct(
349349
$this->Request->ObjLoggerFile = $this->buildPath($this->Configuration['core']['outbound_request_log']);
350350
}
351351
$ChannelsDataArray = [];
352-
$this->YAML->process($this->readFileContent($this->AssetsPath . 'channels.yml'), $ChannelsDataArray);
352+
$this->YAML->process($this->readFile($this->AssetsPath . 'channels.yml'), $ChannelsDataArray);
353353
$this->Request->Channels = $ChannelsDataArray ?: [];
354354
unset($ChannelsDataArray);
355355
if (!isset($this->Request->Channels['Triggers'])) {
@@ -447,28 +447,6 @@ public function __destruct()
447447
restore_error_handler();
448448
}
449449

450-
/**
451-
* Returns the content of the specified file (should only use for
452-
* reasonably small files).
453-
*
454-
* @param string $File The file to read.
455-
* @return string The file's content or an empty string on failure.
456-
*/
457-
public function readFile(string $File): string
458-
{
459-
/** Guard. */
460-
if (!is_file($File) || !is_readable($File) || !$Filesize = filesize($File)) {
461-
return '';
462-
}
463-
464-
if (!is_resource($Handle = fopen($File, 'rb'))) {
465-
return '';
466-
}
467-
$Data = fread($Handle, $Filesize);
468-
fclose($Handle);
469-
return $Data;
470-
}
471-
472450
/**
473451
* Read byte value configuration directives as byte values.
474452
*
@@ -915,7 +893,7 @@ public function substrAfterLast(string $Haystack, string $Needle): string
915893
* @param string $File The path and the name of the file to read.
916894
* @return string The file's content, or an empty string on failure.
917895
*/
918-
public function readFileContent(string $File): string
896+
public function readFile(string $File): string
919897
{
920898
/** Guard. */
921899
if ($File === '' || !is_file($File) || !is_readable($File)) {
@@ -932,7 +910,7 @@ public function readFileContent(string $File): string
932910
* @param string $File The file to read.
933911
* @return string The file's content, or an empty string on failure.
934912
*/
935-
public function readFileContentGZ(string $File): string
913+
public function readFileGZ(string $File): string
936914
{
937915
/** Guard. */
938916
if ($File === '' || !is_file($File) || !is_readable($File) || !$Filesize = filesize($File)) {

src/Scanner.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ private function recursor($Files = '', int $Depth = -1): void
934934
}
935935

936936
/** Read in the file to be scanned. */
937-
$In = $this->Loader->readFileContent($Files);
937+
$In = $this->Loader->readFile($Files);
938938

939939
/** Enforce scannable threshold. */
940940
if (
@@ -1837,7 +1837,7 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
18371837
continue;
18381838
}
18391839
if (!isset($this->Loader->InstanceCache[$SigFile])) {
1840-
$this->Loader->InstanceCache[$SigFile] = $this->Loader->readFileContent($this->Loader->SignaturesPath . $SigFile);
1840+
$this->Loader->InstanceCache[$SigFile] = $this->Loader->readFile($this->Loader->SignaturesPath . $SigFile);
18411841
}
18421842

18431843
/** Fire event: "beforeSigFile". */

0 commit comments

Comments
 (0)