@@ -45,36 +45,27 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
4545 if (count ($ subject ) > 0 ) {
4646 $ child_entity = $ subject [0 ];
4747 }
48- if (is_null ($ child_entity ) && isset ( $ subject -> getSnapshot ()[ 0 ]) && count ($ subject ->getSnapshot ()) > 0 ) {
48+ if (is_null ($ child_entity ) && count ($ subject ->getSnapshot ()) > 0 ) {
4949 $ child_entity = $ subject ->getSnapshot ()[0 ];
5050 }
5151 $ child_entity_formatter = $ child_entity != null ? ChildEntityFormatterFactory::build ($ child_entity ) : null ;
5252 $ formatter = new EntityCollectionUpdateAuditLogFormatter ($ child_entity_formatter );
5353 break ;
5454 case IAuditStrategy::EVENT_ENTITY_CREATION :
55- $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
56- if (is_null ($ formatter )) {
57- $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
58- }
55+ $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
5956 if (is_null ($ formatter )) {
6057 $ formatter = new EntityCreationAuditLogFormatter ();
6158 }
6259 break ;
6360 case IAuditStrategy::EVENT_ENTITY_DELETION :
64- $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
65- if (is_null ($ formatter )) {
66- $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
67- }
61+ $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
6862 if (is_null ($ formatter )) {
6963 $ child_entity_formatter = ChildEntityFormatterFactory::build ($ subject );
7064 $ formatter = new EntityDeletionAuditLogFormatter ($ child_entity_formatter );
7165 }
7266 break ;
7367 case IAuditStrategy::EVENT_ENTITY_UPDATE :
74- $ formatter = $ this ->getFormatterByContext ($ subject , $ eventType , $ ctx );
75- if (is_null ($ formatter )) {
76- $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
77- }
68+ $ formatter = $ this ->getStrategyClass ($ subject , $ eventType );
7869 if (is_null ($ formatter )) {
7970 $ child_entity_formatter = ChildEntityFormatterFactory::build ($ subject );
8071 $ formatter = new EntityUpdateAuditLogFormatter ($ child_entity_formatter );
@@ -84,39 +75,4 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
8475 $ formatter ->setContext ($ ctx );
8576 return $ formatter ;
8677 }
87-
88- private function getFormatterByContext (object $ subject , string $ event_type , AuditContext $ ctx ): ?IAuditLogFormatter
89- {
90- $ class = get_class ($ subject );
91- $ entity_config = $ this ->config ['entities ' ][$ class ] ?? null ;
92-
93- if (!$ entity_config || !isset ($ entity_config ['strategies ' ])) {
94- return null ;
95- }
96-
97- foreach ($ entity_config ['strategies ' ] as $ strategy ) {
98- if (!$ this ->matchesStrategy ($ strategy , $ ctx )) {
99- continue ;
100- }
101-
102- $ formatter_class = $ strategy ['formatter ' ] ?? null ;
103- return $ formatter_class ? new $ formatter_class ($ event_type ) : null ;
104- }
105-
106- return null ;
107- }
108-
109- private function matchesStrategy (array $ strategy , AuditContext $ ctx ): bool
110- {
111- if (isset ($ strategy ['route ' ]) && !$ this ->routeMatches ($ strategy ['route ' ], $ ctx ->rawRoute )) {
112- return false ;
113- }
114-
115- return true ;
116- }
117-
118- private function routeMatches (string $ route , string $ actual_route ): bool
119- {
120- return strcmp ($ actual_route , $ route ) === 0 ;
121- }
12278}
0 commit comments