Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../vendor/wordfenc.../mmdb-rea.../src/Io
File: FileHandle.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Wordfence\MmdbReader\Io;
[2] Fix | Delete
[3] Fix | Delete
use Wordfence\MmdbReader\Exception\IoException;
[4] Fix | Delete
[5] Fix | Delete
class FileHandle {
[6] Fix | Delete
[7] Fix | Delete
const POSITION_START = 0;
[8] Fix | Delete
[9] Fix | Delete
const DIRECTION_FORWARD = 1;
[10] Fix | Delete
const DIRECTION_REVERSE = -1;
[11] Fix | Delete
[12] Fix | Delete
const CHUNK_SIZE_DEFAULT = 1024;
[13] Fix | Delete
[14] Fix | Delete
private $resource;
[15] Fix | Delete
private $close;
[16] Fix | Delete
[17] Fix | Delete
public function __construct($resource, $close = true) {
[18] Fix | Delete
$this->resource = $resource;
[19] Fix | Delete
$this->close = $close;
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
public function __destruct() {
[23] Fix | Delete
if ($this->close)
[24] Fix | Delete
fclose($this->resource);
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
public function seek($offset, $whence = SEEK_SET) {
[28] Fix | Delete
if (fseek($this->resource, $offset, $whence) !== 0)
[29] Fix | Delete
throw new IoException("Seeking file to offset {$offset} failed");
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
public function getPosition() {
[33] Fix | Delete
$position = ftell($this->resource);
[34] Fix | Delete
if ($position === false)
[35] Fix | Delete
throw new IoException('Retrieving current position in file failed');
[36] Fix | Delete
return $position;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function isAtStart() {
[40] Fix | Delete
return $this->getPosition() === self::POSITION_START;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
public function isAtEnd() {
[44] Fix | Delete
return feof($this->resource);
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
public function read($length) {
[48] Fix | Delete
$read = fread($this->resource, $length);
[49] Fix | Delete
if ($read === false)
[50] Fix | Delete
throw new IoException("Reading {$length} byte(s) from file failed");
[51] Fix | Delete
return $read;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function readByte() {
[55] Fix | Delete
return ord($this->read(1));
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
public function readAll($chunkSize = self::CHUNK_SIZE_DEFAULT) {
[59] Fix | Delete
$data = '';
[60] Fix | Delete
do {
[61] Fix | Delete
$chunk = $this->read($chunkSize);
[62] Fix | Delete
if (empty($chunk))
[63] Fix | Delete
break;
[64] Fix | Delete
$data .= $chunk;
[65] Fix | Delete
} while (true);
[66] Fix | Delete
return $data;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
public function locateString($string, $direction, $limit = null, $after = false) {
[70] Fix | Delete
$searchStart = $limit === null ? null : $this->getPosition();
[71] Fix | Delete
$length = strlen($string);
[72] Fix | Delete
$position = $searchStart;
[73] Fix | Delete
if ($direction === self::DIRECTION_REVERSE)
[74] Fix | Delete
$position -= $length;
[75] Fix | Delete
do {
[76] Fix | Delete
try {
[77] Fix | Delete
$this->seek($position, SEEK_SET);
[78] Fix | Delete
}
[79] Fix | Delete
catch (IoException $e) {
[80] Fix | Delete
//This assumes that a seek failure means that the target position is out of range (and hence the search just needs to stop rather than throwing an exception)
[81] Fix | Delete
break;
[82] Fix | Delete
}
[83] Fix | Delete
$test = $this->read($length);
[84] Fix | Delete
if ($test === $string) {
[85] Fix | Delete
return $position + ($after ? $length : 0);
[86] Fix | Delete
}
[87] Fix | Delete
$position += $direction;
[88] Fix | Delete
} while ($limit === null || abs($position - $searchStart) < $limit);
[89] Fix | Delete
return null;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
}
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function