Files
pathfinder/app/main/lib/logging/AbstractChannelLog.php
Mark Friedrich 1b1470c3d9 - fixed some "case-sensitive" autoloading bugs un Unix systems
- fixed a bug with backwards compability issues
- added new js/css build files for v1.3.0
2017-11-03 16:56:19 +01:00

87 lines
2.0 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodu
* Date: 04.08.2017
* Time: 22:13
*/
namespace lib\logging;
abstract class AbstractChannelLog extends AbstractLog {
/**
* @var array
*/
protected $channelData = [];
public function __construct(string $action, array $channelData){
parent::__construct($action);
$this->setChannelData($channelData);
// add log processor -> remove $channelData from log
$processorClearChannelData = function($record){
$record['context'] = array_diff_key($record['context'], $this->getChannelData());
return $record;
};
// init processorConfig. IMPORTANT: first processor gets executed at the end!
$this->processorConfig = ['clearChannelData' => $processorClearChannelData] + $this->processorConfig;
}
/**
* @param array $channelData
*/
protected function setChannelData(array $channelData){
$this->channelData = $channelData;
}
/**
* @return array
*/
public function getChannelData() : array{
return $this->channelData;
}
/**
* @return int
*/
public function getChannelId() : int{
return (int)$this->getChannelData()['channelId'];
}
/**
* @return string
*/
public function getChannelName() : string{
return (string)$this->getChannelData()['channelName'];
}
/**
* @return array
*/
public function getData() : array{
$data['main'] = parent::getData();
if(!empty($channelLogData = $this->getChannelData())){
$channelData['channel'] = $channelLogData;
$data = $channelData + $data;
}
return $data;
}
/**
* @return array
*/
public function getContext(): array{
$context = parent::getContext();
// add temp data (e.g. used for $message placeholder replacement
$context += $this->getChannelData();
return $context;
}
}