Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.44% |
17 / 18 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
| HtmxEngineRequestHandler | |
100.00% |
17 / 17 |
|
100.00% |
14 / 14 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEngineApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPicklistValuesApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getModuleFieldsApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getModuleRelationsApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getContextFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRelationMmApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTwig | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMediaUploadApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguageTranslationsApi | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDataExchangeHtmxController | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Presentation\Web; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\DataExchange\Presentation\Htmx\DataExchangeHtmxController; |
| 12 | use App\Core\Engine\Domain\Model\PermissionContext; |
| 13 | use App\Core\Engine\Presentation\Api\CentralEngineApiController; |
| 14 | use App\Core\Engine\Presentation\Api\MediaUploadApiControllerInterface; |
| 15 | use App\Core\Engine\Presentation\Api\ModuleFieldsApiController; |
| 16 | use App\Core\Engine\Presentation\Api\ModuleRelationsApiController; |
| 17 | use App\Core\Engine\Presentation\Api\PicklistValuesApiController; |
| 18 | use App\Core\Engine\Presentation\Api\RelationMmApiController; |
| 19 | use App\Core\Engine\Application\Security\PermissionContextFactory; |
| 20 | use App\Core\Translation\Presentation\Api\LanguageTranslationsApiController; |
| 21 | use App\Modules\User\Presentation\Middleware\AuthenticatedOnlyMiddleware; |
| 22 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 23 | use Psr\Http\Message\ResponseInterface; |
| 24 | use Psr\Http\Message\ServerRequestInterface; |
| 25 | use Psr\Http\Server\RequestHandlerInterface; |
| 26 | use Twig\Environment as TwigEnvironment; |
| 27 | |
| 28 | /** |
| 29 | * HTMX Engine Request Handler. |
| 30 | * |
| 31 | * Dispatches HTMX asynchronous operations for central CRUD, picklist values, |
| 32 | * module fields reordering/deletion, and module related filters & picklists. |
| 33 | * |
| 34 | * @package App\Core\Engine\Presentation\Web |
| 35 | */ |
| 36 | final readonly class HtmxEngineRequestHandler implements RequestHandlerInterface |
| 37 | { |
| 38 | /** |
| 39 | * HtmxEngineRequestHandler constructor. |
| 40 | * |
| 41 | * @param AuthenticatedOnlyMiddleware $authMiddleware Authentication check middleware. |
| 42 | * @param string $path Requested URI path. |
| 43 | * @param CentralEngineApiController $engineApi Central CRUD engine API. |
| 44 | * @param PicklistValuesApiController $picklistValuesApi Picklist values API controller. |
| 45 | * @param ModuleFieldsApiController $moduleFieldsApi Module fields API controller. |
| 46 | * @param ModuleRelationsApiController $moduleRelationsApi Module relations (filters/picklists) API. |
| 47 | * @param PermissionContextFactory $contextFactory Factory for actor permission context. |
| 48 | * @param Psr17Factory $factory PSR-17 response factory. |
| 49 | * @param RelationMmApiController|null $relationMmApi M:M relation API controller. |
| 50 | * @param TwigEnvironment|null $twig Twig template engine. |
| 51 | * @param MediaUploadApiControllerInterface|null $mediaUploadApi Media upload controller. |
| 52 | * @param LanguageTranslationsApiController|null $languageTranslationsApi Translations controller. |
| 53 | */ |
| 54 | public function __construct( |
| 55 | private AuthenticatedOnlyMiddleware $authMiddleware, |
| 56 | private string $path, |
| 57 | private CentralEngineApiController $engineApi, |
| 58 | private PicklistValuesApiController $picklistValuesApi, |
| 59 | private ModuleFieldsApiController $moduleFieldsApi, |
| 60 | private ModuleRelationsApiController $moduleRelationsApi, |
| 61 | private PermissionContextFactory $contextFactory, |
| 62 | private Psr17Factory $factory, |
| 63 | private ?RelationMmApiController $relationMmApi = null, |
| 64 | private ?TwigEnvironment $twig = null, |
| 65 | private ?MediaUploadApiControllerInterface $mediaUploadApi = null, |
| 66 | private ?LanguageTranslationsApiController $languageTranslationsApi = null, |
| 67 | private ?DataExchangeHtmxController $dataExchangeHtmxController = null, |
| 68 | ) { |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Handles incoming request passing through authentication. |
| 73 | * |
| 74 | * @param ServerRequestInterface $request PSR-7 server request. |
| 75 | * @return ResponseInterface PSR-7 response. |
| 76 | */ |
| 77 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 78 | { |
| 79 | return $this->authMiddleware->process( |
| 80 | $request, |
| 81 | new HtmxEngineDispatchHandler($this) |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | public function getPath(): string |
| 86 | { |
| 87 | return $this->path; |
| 88 | } |
| 89 | |
| 90 | public function getEngineApi(): CentralEngineApiController |
| 91 | { |
| 92 | return $this->engineApi; |
| 93 | } |
| 94 | |
| 95 | public function getPicklistValuesApi(): PicklistValuesApiController |
| 96 | { |
| 97 | return $this->picklistValuesApi; |
| 98 | } |
| 99 | |
| 100 | public function getModuleFieldsApi(): ModuleFieldsApiController |
| 101 | { |
| 102 | return $this->moduleFieldsApi; |
| 103 | } |
| 104 | |
| 105 | public function getModuleRelationsApi(): ModuleRelationsApiController |
| 106 | { |
| 107 | return $this->moduleRelationsApi; |
| 108 | } |
| 109 | |
| 110 | public function getContextFactory(): PermissionContextFactory |
| 111 | { |
| 112 | return $this->contextFactory; |
| 113 | } |
| 114 | |
| 115 | public function getFactory(): Psr17Factory |
| 116 | { |
| 117 | return $this->factory; |
| 118 | } |
| 119 | |
| 120 | public function getRelationMmApi(): ?RelationMmApiController |
| 121 | { |
| 122 | return $this->relationMmApi; |
| 123 | } |
| 124 | |
| 125 | public function getTwig(): ?TwigEnvironment |
| 126 | { |
| 127 | return $this->twig; |
| 128 | } |
| 129 | |
| 130 | public function getMediaUploadApi(): ?MediaUploadApiControllerInterface |
| 131 | { |
| 132 | return $this->mediaUploadApi; |
| 133 | } |
| 134 | |
| 135 | public function getLanguageTranslationsApi(): ?LanguageTranslationsApiController |
| 136 | { |
| 137 | return $this->languageTranslationsApi; |
| 138 | } |
| 139 | |
| 140 | public function getDataExchangeHtmxController(): ?DataExchangeHtmxController |
| 141 | { |
| 142 | return $this->dataExchangeHtmxController; |
| 143 | } |
| 144 | } |