|
8 | 8 | * License: GNU/GPLv2
|
9 | 9 | * @see LICENSE.txt
|
10 | 10 | *
|
11 |
| - * This file: The loader (last modified: 2022.02.21). |
| 11 | + * This file: The loader (last modified: 2022.03.24). |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | namespace phpMussel\Core;
|
@@ -169,7 +169,7 @@ class Loader
|
169 | 169 | private $Channels = [];
|
170 | 170 |
|
171 | 171 | /**
|
172 |
| - * @var int The default blocksize for readFileBlocks and readFileBlocksGZ. |
| 172 | + * @var int The default blocksize for readFileContent and readFileContentGZ. |
173 | 173 | */
|
174 | 174 | private $Blocksize = 131072;
|
175 | 175 |
|
@@ -337,7 +337,7 @@ public function __construct(
|
337 | 337 | $this->Request = new \Maikuolan\Common\Request();
|
338 | 338 | $this->Request->DefaultTimeout = $this->Configuration['core']['default_timeout'];
|
339 | 339 | $ChannelsDataArray = [];
|
340 |
| - $this->YAML->process($this->readFileBlocks($this->AssetsPath . 'channels.yaml'), $ChannelsDataArray); |
| 340 | + $this->YAML->process($this->readFileContent($this->AssetsPath . 'channels.yaml'), $ChannelsDataArray); |
341 | 341 | $this->Request->Channels = $ChannelsDataArray ?: [];
|
342 | 342 | unset($ChannelsDataArray);
|
343 | 343 | if (!isset($this->Request->Channels['Triggers'])) {
|
@@ -850,58 +850,37 @@ public function substrAfterLast(string $h, string $n): string
|
850 | 850 | }
|
851 | 851 |
|
852 | 852 | /**
|
853 |
| - * Returns the contents of files. |
| 853 | + * Reads and returns the contents of files. |
854 | 854 | *
|
855 |
| - * @param string $File The file to read. |
856 |
| - * @param int $BlocksToRead The number of blocks to read from the file. |
857 |
| - * @return string The file's contents (an empty string on failure). |
| 855 | + * @param string $File The path and the name of the file to read. |
| 856 | + * @return string The file's content, or an empty string on failure. |
858 | 857 | */
|
859 |
| - public function readFileBlocks(string $File, int $BlocksToRead = 0): string |
| 858 | + public function readFileContent(string $File): string |
860 | 859 | {
|
861 | 860 | /** Guard. */
|
862 |
| - if (!is_file($File) || !is_readable($File) || !$Filesize = filesize($File)) { |
| 861 | + if (!strlen($File) || !is_file($File) || !is_readable($File)) { |
863 | 862 | return '';
|
864 | 863 | }
|
865 | 864 |
|
866 |
| - /** Calculate this file's blocks to read. */ |
867 |
| - if (!$BlocksToRead) { |
868 |
| - $BlocksToRead = ($Filesize && $this->Blocksize) ? ceil($Filesize / $this->Blocksize) : 0; |
869 |
| - } |
870 |
| - |
871 |
| - $Data = ''; |
872 |
| - if ($BlocksToRead > 0) { |
873 |
| - $Handle = fopen($File, 'rb'); |
874 |
| - if (!is_resource($Handle)) { |
875 |
| - return ''; |
876 |
| - } |
877 |
| - $Done = 0; |
878 |
| - while ($Done < $BlocksToRead) { |
879 |
| - $Data .= fread($Handle, $this->Blocksize); |
880 |
| - $Done++; |
881 |
| - } |
882 |
| - fclose($Handle); |
883 |
| - } |
884 |
| - return $Data; |
| 865 | + $Data = file_get_contents($File); |
| 866 | + return is_string($Data) ? $Data : ''; |
885 | 867 | }
|
886 | 868 |
|
887 | 869 | /**
|
888 |
| - * Returns the contents of GZ-compressed files. |
| 870 | + * Reads and returns the contents of GZ-compressed files. |
889 | 871 | *
|
890 | 872 | * @param string $File The file to read.
|
891 |
| - * @param int $BlocksToRead The number of blocks to read from the file. |
892 |
| - * @return string The file's contents (an empty string on failure). |
| 873 | + * @return string The file's content, or an empty string on failure. |
893 | 874 | */
|
894 |
| - public function readFileBlocksGZ(string $File, int $BlocksToRead = 0): string |
| 875 | + public function readFileContentGZ(string $File): string |
895 | 876 | {
|
896 | 877 | /** Guard. */
|
897 |
| - if (!is_file($File) || !is_readable($File) || !$Filesize = filesize($File)) { |
| 878 | + if (!strlen($File) || !is_file($File) || !is_readable($File) || !$Filesize = filesize($File)) { |
898 | 879 | return '';
|
899 | 880 | }
|
900 | 881 |
|
901 | 882 | /** Calculate this file's blocks to read. */
|
902 |
| - if (!$BlocksToRead) { |
903 |
| - $BlocksToRead = ($Filesize && $this->Blocksize) ? ceil($Filesize / $this->Blocksize) : 0; |
904 |
| - } |
| 883 | + $BlocksToRead = ($Filesize && $this->Blocksize) ? ceil($Filesize / $this->Blocksize) : 0; |
905 | 884 |
|
906 | 885 | $Data = '';
|
907 | 886 | if ($BlocksToRead > 0) {
|
@@ -982,7 +961,7 @@ public function arrayify(&$Input): void
|
982 | 961 | public function gZCompressFile(string $File): bool
|
983 | 962 | {
|
984 | 963 | /** Guard. */
|
985 |
| - if (!is_file($File) || !is_readable($File)|| !$Filesize = filesize($File)) { |
| 964 | + if (!strlen($File) || !is_file($File) || !is_readable($File)) { |
986 | 965 | return false;
|
987 | 966 | }
|
988 | 967 |
|
|
0 commit comments