Files
pathfinder/app/main/data/file/filehandler.php
Exodus4D a8edf39697 - new "logging" system for map/system/signature/connection changes, closed #271
- new map change log to Slack channel
- new "rally point" logging to Slack channel
- new "rally point" poke options (e.g. custom message), closed #295
- new log options for WebSocket installations
- added ship "mass" logging (backend only), #313
- added map logging to Slack, #326
- added "ESI error rate" limit detection
- added "Monolog" as new logging library (Composer dependency)
- added "Swiftmailer" as new eMail library (Composer dependency)
- added Support for Redis session hander (performance boost)
- improved character select panels (visible "online" status)
- improved "activity logging" (more DB columns added to check)
- improved eMail logging (HTML template support)
- improved "delete map" now become "inactive" for some days before delete
- improved character logout handling
- improved /setup page for DB bootstrap (new button for DB create if not exists)
- fixed broken ship tracking (ship name re-added)
- fixed broken ship tracking for multiple chars on different browser tabs
- fixed broken cursor coordinates, closed #518
- fixed null pointer "charactermodel.php->isActive():925" closed #529
- fixed broken "scroll offset", closed #533 closed #534
- Updated "validation" library JS v0.10.1 -> v0.11.9
- Updated ORM Mapper _Cortex_ v1.5.0-dev -> v1.5.0
- and many more....
2017-10-22 17:58:34 +02:00

90 lines
2.6 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodu
* Date: 06.08.2017
* Time: 18:47
*/
namespace data\file;
class FileHandler extends \Prefab {
const ERROR_STREAM_READABLE = 'Stream is not readable "%s"';
const LOG_FILE_OFFSET_MIN = 0;
const LOG_FILE_OFFSET = 0;
const LOG_FILE_OFFSET_MAX = 10000;
const LOG_FILE_LIMIT_MIN = 1;
const LOG_FILE_LIMIT = 100;
const Log_File_LIMIT_MAX = 100;
/**
* parse local log file from end to first line
* -> Each row is a JSON object
* @param string $sourceFile
* @param int $offset
* @param int $limit
* @param null|callable $formatter
* @return array
*/
public static function readLogFile(
string $sourceFile,
int $offset = self::LOG_FILE_OFFSET,
int $limit = self::LOG_FILE_LIMIT,
$formatter = null
): array {
$data = [];
if(is_file($sourceFile)){
if(is_readable($sourceFile)){
$file = new ReverseSplFileObject($sourceFile, $offset);
$file->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
foreach( new \LimitIterator($file, 0, $limit) as $i => $rowData){
if( !empty($rowDataObj = (array)json_decode($rowData, true)) ){
if(is_callable($formatter)){
$formatter($rowDataObj);
}
$data[] = $rowDataObj;
}
}
}else{
\Base::instance()->error(500, sprintf(self::ERROR_STREAM_READABLE, $sourceFile));
}
}
return $data;
}
/**
* validate offset
* @param int $offset
* @return int
*/
public static function validateOffset(int $offset): int{
if(
$offset < self::LOG_FILE_OFFSET_MIN ||
$offset > self::LOG_FILE_OFFSET_MAX
){
$offset = self::LOG_FILE_OFFSET;
}
return $offset;
}
/**
* validate limit
* @param int $limit
* @return int
*/
public static function validateLimit(int $limit): int{
if(
$limit < self::LOG_FILE_LIMIT_MIN ||
$limit > self::Log_File_LIMIT_MAX
){
$limit = self::LOG_FILE_LIMIT;
}
return $limit;
}
}