Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ActionRegistryService
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
3.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getBulkActions
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
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\Action\Application\Service;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Action\Domain\Model\ActionMetadata;
12use App\Core\Action\Domain\Repository\ActionRepositoryInterface;
13use App\Core\Engine\Domain\Repository\MetadataRepositoryInterface;
14
15/**
16 * Action Registry Application Service.
17 *
18 * Central service for querying available actions for DataGrid bulk operations,
19 * record actions, and custom toolbar extensions.
20 *
21 * @package App\Core\Action\Application\Service
22 */
23final readonly class ActionRegistryService
24{
25    /**
26     * ActionRegistryService constructor.
27     *
28     * @param ActionRepositoryInterface   $actionRepository   Action repository contract.
29     * @param MetadataRepositoryInterface $metadataRepository Module metadata repository.
30     */
31    public function __construct(
32        private ActionRepositoryInterface $actionRepository,
33        private MetadataRepositoryInterface $metadataRepository
34    ) {
35    }
36
37    /**
38     * Returns all active bulk actions configured for the given module.
39     *
40     * @param string $moduleName Module machine name.
41     * @return array<int, ActionMetadata> Ordered list of active bulk actions.
42     */
43    public function getBulkActions(string $moduleName): array
44    {
45        $moduleId = null;
46        try {
47            $module = $this->metadataRepository->findModule($moduleName);
48            $moduleId = $module->id;
49        } catch (\Throwable) {
50            // Global fallback when module lookup is not available
51        }
52
53        return $this->actionRepository->findByCategory('grid_bulk', $moduleId);
54    }
55}