Files
pathfinder/app/Lib/Logging/AbstractChannelLog.php
Mark Friedrich 647bd7db58 - BC Break: _PHP_ namespaces changed (PSR-4 standard). The _root_ namespace for all _PF_ related scripts is Exodus4D\Pathfinder
- BC Break: Project folder structure changed. Removed `app/main` dir.
- BC Break: Core _PHP_ framework + dependencies moved into `composer.json` and are no longer part of this repo
2019-12-15 22:27:17 +01:00

91 lines
2.1 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 04.08.2017
* Time: 22:13
*/
namespace Exodus4D\Pathfinder\Lib\Logging;
abstract class AbstractChannelLog extends AbstractLog {
/**
* @var array
*/
protected $channelData = [];
/**
* AbstractChannelLog constructor.
* @param string $action
* @param array $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;
}
}