Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ModuleConfigApiControllerTrait
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 invalidateMetadataCache
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Engine\Presentation\Api;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Engine\Domain\Repository\MetadataRepositoryInterface;
12use Throwable;
13
14/**
15 * Trait providing shared metadata cache invalidation helpers.
16 *
17 * @package App\Core\Engine\Presentation\Api
18 */
19trait ModuleConfigApiControllerTrait
20{
21    /**
22     * Safely invalidates metadata repository cache when available.
23     *
24     * @param MetadataRepositoryInterface|null $metadataRepo Metadata repository instance.
25     * @param int|null                         $moduleId     Optional module ID.
26     */
27    protected function invalidateMetadataCache(
28        ?MetadataRepositoryInterface $metadataRepo,
29        ?int $moduleId = null
30    ): void {
31        if ($metadataRepo !== null) {
32            try {
33                $metadataRepo->clearCache($moduleId);
34            } catch (Throwable) {
35                // Best-effort cache invalidation
36            }
37        }
38    }
39}