Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
74.55% |
41 / 55 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CoreServiceProvider | |
74.07% |
40 / 54 |
|
50.00% |
1 / 2 |
3.16 | |
0.00% |
0 / 1 |
| getDefinitions | |
73.58% |
39 / 53 |
|
0.00% |
0 / 1 |
2.07 | |||
| getExtensions | |
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\Bootstrap\Provider; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Security\Encryption\AesGcmEncryptionService; |
| 12 | use App\Core\Security\Encryption\EncryptionServiceInterface; |
| 13 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 14 | use Psr\Http\Message\ResponseFactoryInterface; |
| 15 | use Psr\Http\Message\ServerRequestFactoryInterface; |
| 16 | use Psr\Http\Message\StreamFactoryInterface; |
| 17 | use Psr\Http\Message\UriFactoryInterface; |
| 18 | use Yiisoft\Cache\Cache; |
| 19 | use Yiisoft\Cache\CacheInterface; |
| 20 | use Yiisoft\Cache\File\FileCache; |
| 21 | use Yiisoft\Di\ServiceProviderInterface; |
| 22 | |
| 23 | /** |
| 24 | * CoreServiceProvider. |
| 25 | * |
| 26 | * Registers foundational PSR-17 factories, cache interfaces, and cryptographic services. |
| 27 | * |
| 28 | * @package App\Core\Bootstrap\Provider |
| 29 | */ |
| 30 | final class CoreServiceProvider implements ServiceProviderInterface |
| 31 | { |
| 32 | /** |
| 33 | * @return array<string, mixed> Definitions mapping for PSR-11 container. |
| 34 | */ |
| 35 | public function getDefinitions(): array |
| 36 | { |
| 37 | return [ |
| 38 | Psr17Factory::class => static fn(): Psr17Factory => new Psr17Factory(), |
| 39 | ResponseFactoryInterface::class => static fn(Psr17Factory $f): ResponseFactoryInterface => $f, |
| 40 | ServerRequestFactoryInterface::class => static fn(Psr17Factory $f): ServerRequestFactoryInterface => $f, |
| 41 | StreamFactoryInterface::class => static fn(Psr17Factory $f): StreamFactoryInterface => $f, |
| 42 | UriFactoryInterface::class => static fn(Psr17Factory $f): UriFactoryInterface => $f, |
| 43 | |
| 44 | EncryptionServiceInterface::class => static fn(): EncryptionServiceInterface => ( |
| 45 | new AesGcmEncryptionService() |
| 46 | ), |
| 47 | AesGcmEncryptionService::class => static fn(): AesGcmEncryptionService => ( |
| 48 | new AesGcmEncryptionService() |
| 49 | ), |
| 50 | |
| 51 | \Yiisoft\Hydrator\HydratorInterface::class => static fn(): \Yiisoft\Hydrator\HydratorInterface => ( |
| 52 | new \Yiisoft\Hydrator\Hydrator() |
| 53 | ), |
| 54 | \Yiisoft\Hydrator\Hydrator::class => static fn(): \Yiisoft\Hydrator\Hydrator => ( |
| 55 | new \Yiisoft\Hydrator\Hydrator() |
| 56 | ), |
| 57 | |
| 58 | \Yiisoft\Validator\ValidatorInterface::class => static fn(): \Yiisoft\Validator\ValidatorInterface => ( |
| 59 | new \Yiisoft\Validator\Validator() |
| 60 | ), |
| 61 | \Yiisoft\Validator\Validator::class => static fn(): \Yiisoft\Validator\Validator => ( |
| 62 | new \Yiisoft\Validator\Validator() |
| 63 | ), |
| 64 | |
| 65 | \Yiisoft\DataResponse\DataResponseFactoryInterface::class => static fn( |
| 66 | Psr17Factory $f |
| 67 | ): \Yiisoft\DataResponse\DataResponseFactoryInterface => ( |
| 68 | new \Yiisoft\DataResponse\DataResponseFactory($f, $f) |
| 69 | ), |
| 70 | \Yiisoft\DataResponse\DataResponseFactory::class => static fn( |
| 71 | Psr17Factory $f |
| 72 | ): \Yiisoft\DataResponse\DataResponseFactory => ( |
| 73 | new \Yiisoft\DataResponse\DataResponseFactory($f, $f) |
| 74 | ), |
| 75 | |
| 76 | \App\Core\Asset\AssetManagerInterface::class => static fn(): \App\Core\Asset\AssetManagerInterface => ( |
| 77 | new \App\Core\Asset\YiiAssetManager(dirname(__DIR__, 4) . '/public') |
| 78 | ), |
| 79 | |
| 80 | \Yiisoft\Router\UrlMatcherInterface::class => static fn(): \Yiisoft\Router\UrlMatcherInterface => ( |
| 81 | \App\Core\Router\AppRouterFactory::createMatcher() |
| 82 | ), |
| 83 | |
| 84 | \Yiisoft\Assets\AssetManager::class => static function (): \Yiisoft\Assets\AssetManager { |
| 85 | $aliases = new \Yiisoft\Aliases\Aliases(['@root' => dirname(__DIR__, 4) . '/public']); |
| 86 | $loader = new \Yiisoft\Assets\AssetLoader($aliases); |
| 87 | return new \Yiisoft\Assets\AssetManager($aliases, $loader); |
| 88 | }, |
| 89 | |
| 90 | CacheInterface::class => static function (): CacheInterface { |
| 91 | $cacheDir = dirname(__DIR__, 4) . '/storage/runtime/cache'; |
| 92 | if (!is_dir($cacheDir)) { |
| 93 | @mkdir($cacheDir, 0755, true); |
| 94 | } |
| 95 | $fileCache = (new FileCache($cacheDir))->withDirectoryLevel(0); |
| 96 | return new Cache($fileCache); |
| 97 | }, |
| 98 | ]; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return array<string, mixed> Service extensions mapping. |
| 103 | */ |
| 104 | public function getExtensions(): array |
| 105 | { |
| 106 | return []; |
| 107 | } |
| 108 | } |