1- <?php namespace App \Audit ;
1+ <?php
2+ namespace App \Audit ;
23/**
34 * Copyright 2025 OpenStack Foundation
45 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,13 +28,10 @@ class AuditLogFormatterFactory implements IAuditLogFormatterFactory
2728
2829 public function __construct ()
2930 {
30- try
31- {
32- Log::debug ("AuditLogFormatterFactory::construct loading audit_log config " );
31+ try {
3332 $ this ->config = config ('audit_log ' , []);
34- }
35- catch (\Exception $ ex ){
36- Log::error ('Failed to load audit_log configuration ' , ['exception ' => $ ex ]);
33+ } catch (\Exception $ ex ) {
34+ $ this ->config = [];
3735 }
3836 }
3937
@@ -64,8 +62,7 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
6462 $ targetEntity = $ type ;
6563 }
6664 Log::debug ("AuditLogFormatterFactory::make getTypeClass targetEntity {$ targetEntity }" );
67- }
68- elseif (method_exists ($ subject , 'getMapping ' )) {
65+ } elseif (method_exists ($ subject , 'getMapping ' )) {
6966 $ mapping = $ subject ->getMapping ();
7067 $ targetEntity = $ mapping ['targetEntity ' ] ?? null ;
7168 Log::debug ("AuditLogFormatterFactory::make getMapping targetEntity {$ targetEntity }" );
@@ -78,7 +75,8 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
7875 $ prop ->setAccessible (true );
7976 $ mapping = $ prop ->getValue ($ subject );
8077 $ targetEntity = $ mapping ['targetEntity ' ] ?? null ;
81- if ($ targetEntity ) break ;
78+ if ($ targetEntity )
79+ break ;
8280 }
8381 }
8482 }
@@ -108,26 +106,27 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
108106 break ;
109107 case IAuditStrategy::EVENT_ENTITY_CREATION :
110108 $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
111- if (is_null ($ formatter )) {
112- $ formatter = new EntityCreationAuditLogFormatter ();
109+ if (is_null ($ formatter )) {
110+ $ formatter = new EntityCreationAuditLogFormatter ($ eventType );
113111 }
114112 break ;
115113 case IAuditStrategy::EVENT_ENTITY_DELETION :
116114 $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
117- if (is_null ($ formatter )) {
115+ if (is_null ($ formatter )) {
118116 $ child_entity_formatter = ChildEntityFormatterFactory::build ($ subject );
119117 $ formatter = new EntityDeletionAuditLogFormatter ($ child_entity_formatter );
120118 }
121119 break ;
122120 case IAuditStrategy::EVENT_ENTITY_UPDATE :
123121 $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
124- if (is_null ($ formatter )) {
122+ if (is_null ($ formatter )) {
125123 $ child_entity_formatter = ChildEntityFormatterFactory::build ($ subject );
126124 $ formatter = new EntityUpdateAuditLogFormatter ($ child_entity_formatter );
127125 }
128126 break ;
129127 }
130- if ($ formatter === null ) return null ;
128+ if ($ formatter === null )
129+ return null ;
131130 $ formatter ->setContext ($ ctx );
132131 return $ formatter ;
133132 }
@@ -173,4 +172,4 @@ private function routeMatches(string $route, string $actual_route): bool
173172 {
174173 return strcmp ($ actual_route , $ route ) === 0 ;
175174 }
176- }
175+ }
0 commit comments