123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- declare(strict_types=1);
- namespace OCA\AdminAudit\Actions;
- use OCA\AdminAudit\IAuditLogger;
- class Action {
- public function __construct(
- private IAuditLogger $logger,
- ) {
- }
-
- public function log(string $text,
- array $params,
- array $elements,
- bool $obfuscateParameters = false): void {
- foreach ($elements as $element) {
- if (!isset($params[$element])) {
- if ($obfuscateParameters) {
- $this->logger->critical(
- '$params["'.$element.'"] was missing.',
- ['app' => 'admin_audit']
- );
- } else {
- $this->logger->critical(
- sprintf(
- '$params["'.$element.'"] was missing. Transferred value: %s',
- print_r($params, true)
- ),
- ['app' => 'admin_audit']
- );
- }
- return;
- }
- }
- $replaceArray = [];
- foreach ($elements as $element) {
- if ($params[$element] instanceof \DateTime) {
- $params[$element] = $params[$element]->format('Y-m-d H:i:s');
- }
- $replaceArray[] = $params[$element];
- }
- $this->logger->info(
- vsprintf(
- $text,
- $replaceArray
- ),
- [
- 'app' => 'admin_audit'
- ]
- );
- }
- }
|