Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| FormsServiceProvider | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| register | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Minimal service provider for Forms/Repository wiring. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2025-2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2025-11-04 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Form; |
| 21 | |
| 22 | use phpMyFAQ\Forms; |
| 23 | use Symfony\Component\DependencyInjection\Alias; |
| 24 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 25 | use Symfony\Component\DependencyInjection\Definition; |
| 26 | use Symfony\Component\DependencyInjection\Reference; |
| 27 | |
| 28 | final class FormsServiceProvider |
| 29 | { |
| 30 | public static function register(ContainerBuilder $containerBuilder): void |
| 31 | { |
| 32 | // Repository Definition (concrete) |
| 33 | if (!$containerBuilder->has(FormsRepository::class)) { |
| 34 | $repoDef = new Definition(FormsRepository::class); |
| 35 | $repoDef->setArgument(0, new Reference('phpmyfaq.configuration')); |
| 36 | $repoDef->setPublic(true); |
| 37 | $containerBuilder->setDefinition(FormsRepository::class, $repoDef); |
| 38 | } |
| 39 | |
| 40 | // Interface Alias -> concrete Repository |
| 41 | if (!$containerBuilder->has(FormsRepositoryInterface::class)) { |
| 42 | $containerBuilder->setAlias(FormsRepositoryInterface::class, new Alias(FormsRepository::class, true)); |
| 43 | } |
| 44 | |
| 45 | // Forms service |
| 46 | if (!$containerBuilder->has(Forms::class)) { |
| 47 | $formsDef = new Definition(Forms::class); |
| 48 | $formsDef->setArgument(0, new Reference('phpmyfaq.configuration')); |
| 49 | $formsDef->setArgument(1, new Reference(FormsRepositoryInterface::class)); |
| 50 | $formsDef->setPublic(true); |
| 51 | $containerBuilder->setDefinition(Forms::class, $formsDef); |
| 52 | } |
| 53 | } |
| 54 | } |