|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PHP Translation package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) PHP Translation team <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Translation\PlatformAdapter\Flysystem\Bridge\Symfony\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
16
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
17
|
|
|
use Symfony\Component\Translation\Writer\TranslationWriter; |
|
18
|
|
|
use Translation\PlatformAdapter\Flysystem\Dumper\FlysystemXliffDumper; |
|
19
|
|
|
use Translation\PlatformAdapter\Flysystem\Flysystem; |
|
20
|
|
|
use Translation\PlatformAdapter\Flysystem\Loader\FlysystemXliffLoader; |
|
21
|
|
|
use Translation\PlatformAdapter\Flysystem\TranslationLoader; |
|
22
|
|
|
use Translation\SymfonyStorage\FileStorage; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Tobias Nyholm <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class TranslationAdapterFlysystemExtension extends Extension |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
1 |
|
public function load(array $configs, ContainerBuilder $container) |
|
33
|
|
|
{ |
|
34
|
1 |
|
$configuration = new Configuration($container); |
|
35
|
1 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
36
|
|
|
|
|
37
|
1 |
|
foreach ($config['filesystems'] as $name => $data) { |
|
38
|
1 |
|
$baseServiceId = 'php_translation.adapter.flysystem.'.$name; |
|
39
|
1 |
|
$flysytemServiceId = $data['flysystem_service']; |
|
40
|
|
|
|
|
41
|
1 |
|
$dumperDef = $container->register($baseServiceId.'.dumper', FlysystemXliffDumper::class); |
|
42
|
1 |
|
$dumperDef->setPublic(false)->addMethodCall('setFilesystem', [new Reference($flysytemServiceId)]); |
|
43
|
1 |
|
$writerDef = $container->register($baseServiceId.'.writer', TranslationWriter::class); |
|
44
|
1 |
|
$writerDef->setPublic(false)->addMethodCall('addDumper', ['xlf', $dumperDef]); |
|
45
|
|
|
|
|
46
|
1 |
|
$xlfLoaderDef = $container->register($baseServiceId.'.xlf_loader', FlysystemXliffLoader::class); |
|
47
|
1 |
|
$xlfLoaderDef->setPublic(false)->addArgument(new Reference($flysytemServiceId)); |
|
48
|
1 |
|
$loaderDef = $container->register($baseServiceId.'.loader', TranslationLoader::class); |
|
49
|
|
|
$loaderDef |
|
50
|
1 |
|
->setPublic(false) |
|
51
|
1 |
|
->addArgument(new Reference($flysytemServiceId)) |
|
52
|
1 |
|
->addMethodCall('addLoader', ['xlf', $xlfLoaderDef]); |
|
53
|
|
|
|
|
54
|
|
|
// Register our file storage. |
|
55
|
1 |
|
$fileStorageDef = $container->register($baseServiceId, FileStorage::class); |
|
56
|
|
|
$fileStorageDef |
|
57
|
1 |
|
->addArgument($writerDef) |
|
58
|
1 |
|
->addArgument($loaderDef) |
|
59
|
1 |
|
->addArgument([$data['path']]); |
|
60
|
1 |
|
} |
|
61
|
1 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|