1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ICanBoogie\CLDR\Generator; |
4
|
|
|
|
5
|
|
|
use ICanBoogie\CLDR\Cache\CacheCollection; |
6
|
|
|
use ICanBoogie\CLDR\Cache\FileCache; |
7
|
|
|
use ICanBoogie\CLDR\Cache\RuntimeCache; |
8
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateCurrencyData; |
9
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateHasContextTransforms; |
10
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateLocaleData; |
11
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateSequenceCompanion; |
12
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateTerritoryData; |
13
|
|
|
use ICanBoogie\CLDR\Generator\Command\GenerateUnitsCompanion; |
14
|
|
|
use ICanBoogie\CLDR\Provider; |
15
|
|
|
use ICanBoogie\CLDR\Repository; |
16
|
|
|
use Psr\Container\ContainerInterface; |
17
|
|
|
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
|
20
|
|
|
final class ContainerProvider |
21
|
|
|
{ |
22
|
|
|
private const COMMANDS = [ |
23
|
|
|
GenerateLocaleData::class, |
24
|
|
|
GenerateHasContextTransforms::class, |
25
|
|
|
GenerateCurrencyData::class, |
26
|
|
|
GenerateSequenceCompanion::class, |
27
|
|
|
GenerateTerritoryData::class, |
28
|
|
|
GenerateUnitsCompanion::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
public static function provide_container(): ContainerInterface |
32
|
|
|
{ |
33
|
|
|
$container = new ContainerBuilder(); |
34
|
|
|
$container->addCompilerPass(new AddConsoleCommandPass()); |
35
|
|
|
|
36
|
|
|
$container->register(Repository::class) |
37
|
|
|
->setFactory([ self::class, 'repository_factory' ]); |
38
|
|
|
|
39
|
|
|
foreach (self::COMMANDS as $command) { |
40
|
|
|
$container |
41
|
|
|
->register($command) |
42
|
|
|
->addTag('console.command') |
43
|
|
|
->setAutowired(true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$container->compile(); |
47
|
|
|
|
48
|
|
|
return $container; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public static function repository_factory(): Repository |
52
|
|
|
{ |
53
|
|
|
$provider = new Provider\CachedProvider( |
54
|
|
|
new Provider\WebProvider(), |
55
|
|
|
new CacheCollection([ |
56
|
|
|
new RuntimeCache(), |
57
|
|
|
new FileCache(CACHE) |
|
|
|
|
58
|
|
|
]) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
return new Repository($provider); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|