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\Transifex\Bridge\Symfony\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
15
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
16
|
|
|
use Translation\PlatformAdapter\Transifex\Transifex; |
17
|
|
|
use BabDev\Transifex\Transifex as TransifexClient; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Tobias Nyholm <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class TranslationAdapterTransifexExtension extends Extension |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function load(array $configs, ContainerBuilder $container) |
28
|
|
|
{ |
29
|
|
|
$configuration = new Configuration($container); |
30
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
31
|
|
|
|
32
|
|
|
$domainToProjectMap = []; |
33
|
|
|
foreach ($config['projects'] as $project => $data) { |
34
|
|
|
foreach ($data['domains'] as $d) { |
35
|
|
|
$domainToProjectMap[$d] = $project; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$apiDef = $container->register('php_translation.adapter.transifex.raw'); |
40
|
|
|
$apiDef->setClass(TransifexClient::class); |
41
|
|
|
$apiDef->addArgument([ |
42
|
|
|
'api.username' => $config['username'], |
43
|
|
|
'api.password' => $config['password'], |
44
|
|
|
]); |
45
|
|
|
|
46
|
|
|
$adapterDef = $container->register('php_translation.adapter.transifex'); |
47
|
|
|
$adapterDef |
48
|
|
|
->setClass(Transifex::class) |
49
|
|
|
->addArgument($apiDef) |
50
|
|
|
->addArgument($domainToProjectMap); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|